每个配置文件相同的财产

Paw*_*ęba 5 maven

我面临着每个配置文件的maven属性问题.我有两个配置文件,每个配置文件具有相同的属性'prop.key',具有不同的值.当我打电话mvn clean package -PA -PB或mvn clean package -PB -PA两者都使用相同的值' B-1.0-SNAPSHOT '时.我正在使用maven 3.0.4.

在我的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>
Run Code Online (Sandbox Code Playgroud)

我找到了'类似的话题'但结果相反!它是maven的bug还是功能?

感谢您的任何建议和帮助.

Mar*_*eln 4

你可以写 mvn package -PA,B 简短的。

结果是相同的: [echo] RUN A = B-1.0-SNAPSHOT和 [echo] RUN B = B-1.0-SNAPSHOT

这是maven的正确行为。

一个属性每次运行只能有一个特定值。您可以使用配置文件中的版本覆盖“默认值”。但是,如果您在两个配置文件中重新定义它并激活这两个配置文件,则其中一个配置文件“获胜”。

对于同一个属性,每个配置文件不可能有一个值。配置文件没有自己的变量范围。属性始终是全局的。