mojohaus / flatten-maven-plugin

Flatten Maven Plugin
https://www.mojohaus.org/flatten-maven-plugin/
Apache License 2.0
201 stars 85 forks source link

embedBuildProfileDependencies takes dependencies of other (not selected) profiles #73

Open karonpante opened 6 years ago

karonpante commented 6 years ago

We have a project in which different profiles define another version of a certain dependency. So the GroupID and ArtifactID of these dependencies are the same.

When we build this project with a certain profile using the flatten plugin with the 'embedBuildProfileDependencies' option enabled we don't get the expected result. Next to the selected profile dependencies also the dependencies of other profiles which have the same GroupID and ArtifactID (but another version) are added to the flattened pom file.

Following pom file was used to test this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>flatten-maven-plugin</artifactId>
        <version>1.0.1</version>
        <configuration>
          <updatePomFile>true</updatePomFile>
          <embedBuildProfileDependencies>true</embedBuildProfileDependencies>
        </configuration>
        <executions>
          <execution>
            <id>flatten</id>
            <phase>process-resources</phase>
            <goals>
              <goal>flatten</goal>
            </goals>
          </execution>
          <execution>
            <id>flatten.clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>profile1</id>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.12</version>
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>profile2</id>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.10</version>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>

When building this with the following command:

mvn clean install -Pprofile1

This gives the following flattened pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
    </dependency>
  </dependencies>
</project>
hohwille commented 5 years ago

OMG. You are right. I have testet it - even with 1.1.0 the bug is reproducable just as you described. Seems that the profile activation is somehow buggy. Shall be fixed for next release. Help is more than welcome.