flatten-maven-plugin icon indicating copy to clipboard operation
flatten-maven-plugin copied to clipboard

flatten error when profiles are activated by property

Open farfouille64 opened this issue 6 years ago • 7 comments
trafficstars

Given the following pom.xml :

<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>org.test</groupId>
  <artifactId>A</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.${revision}</version>
    </dependency>     
  </dependencies>

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

  <profiles>
     <profile>
        <id>ProfDef</id>
        <activation>
           <property>
              <name>!prof</name>
           </property>
        </activation>
        <properties>
           <revision>10</revision>
        </properties>
     </profile>
     <profile>
        <id>ProfA</id>
        <activation>
           <property>
              <name>prof</name>
           </property>
        </activation>
        <properties>
           <revision>12</revision>
        </properties>
     </profile>
  </profiles>
</project>

flatten succeeds if profiles are activated explicitly (-P option) but fails when they are activated by properties : mvn process-resources => failure mvn -Dprof process-resources => failure mvn -PProfA process-resources => success mvn -PProfDef process-resources => success failure message : [ERROR] 'dependencies.dependency.version' for junit:junit:jar must be a valid version but is '4.${revision}'.

farfouille64 avatar Mar 22 '19 10:03 farfouille64

activeByDefault=true property in profile configuration doesn't work either.

<profiles> <profile> <id>TEST</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <revision>1.0.1-SNAPSHOT</revision> </properties> </profile> <profile> <id>PRE</id> <properties> <revision>1.0.1-PRE-SNAPSHOT</revision> </properties> </profile> </profiles>

hunalme avatar Dec 24 '19 10:12 hunalme

I have the same problem.

ashulin avatar Sep 29 '21 02:09 ashulin

boy oh boy i sure do love debugging

menneske2 avatar Oct 22 '21 12:10 menneske2

Nothing new since pratically 3 years?

dymont avatar Jan 26 '22 07:01 dymont

maybe this is intentional?

from docu:

profiles resolved specially only the Activation and the Dependency dependencies of a Profile are copied to the flattened POM. If you set the parameter embedBuildProfileDependencies to true then only profiles Activation activated by JDK or OS will be added to the flattened POM while the other profiles are triggered by the current build setup and if activated their impact on dependencies is embedded into the resulting flattened POM.

enabledByDefault is not part of that activation list: JDK/OS

jcunliffe1 avatar Feb 10 '22 08:02 jcunliffe1