Java – Maven has the same properties for each profile
I am faced with the Maven attribute of each configuration file I have two profiles, each with the same attribute 'prop Key 'has different values When I call MVN clean package - pa - Pb or MVN clean package - Pb - PA, both use the same value 'b-1.0-snapshot' I'm using Maven 3.0 four
Under my POM:
<?xml version="1.0" encoding="UTF-8"?> <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.test.module</groupId> <artifactId>test-module</artifactId> <version>1.0-SNAPSHOT</version> <packaging>pom</packaging> <properties> <prop.key>UNKNowN</prop.key> </properties> <profiles> <profile> <id>A</id> <properties> <prop.key>A-${project.version}</prop.key> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.2</version> <executions> <execution> <id>A</id> <phase>package</phase> <configuration> <tasks name="a" description="a-desc"> <echo message="RUN A = ${prop.key}" level="info"/> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> <profile> <id>B</id> <properties> <prop.key>B-${project.version}</prop.key> </properties> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.2</version> <executions> <execution> <id>B</id> <phase>package</phase> <configuration> <tasks name="b" description="b-desc"> <echo message="RUN B = ${prop.key}" level="info"/> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> </project>
I found 'similar topic', but the result was the opposite! Is it a maven bug or a feature?
Thank you for any advice and help
Solution
You can write
The result is the same: [echo] run a = b-1.0-snapshot and [echo] run B = b-1.0-snapshot
This is Maven's correct behavior
A property can have only one specific value at a time You can override the default with the version in the configuration file But if you redefine and activate two profiles in two profiles, one of them "wins"
Each profile cannot have a value for the same attribute The configuration file does not have its own variable range Properties are always global