Maven个人资料ID如何使用var?

shi*_*kui 2 maven maven-assembly-plugin

个人资料是:我使用$ {artifactId}作为个人资料ID。

 <profiles>
    <profile>
        <id>${artifactId}</id>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <descriptors>
                            <descriptor>distribution.xml</descriptor>
                        </descriptors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
Run Code Online (Sandbox Code Playgroud)

在shell中运行Maven: mvn -U -Dmaven.test.skip=true -f pom.xml -Pabc_test clean install

然后我发现一个错误:

[警告]所请求的配置文件“ abc_test”不存在,因此无法激活。完

bas*_*mes 5

您必须在pom.xml中定义所有配置文件。

    <profiles>
        <profile>
            <id>dev</id>
                    <activation>
                        <activeByDefault>true</activeByDefault>
                    </activation>
                    <properties>
                        <war.name>dev</war.name>
                    </properties>
        </profile>
        <profile>
                    <id>prod</id>
                    <properties>
                        <war.name>prod</war.name>
                    </properties>
        </profile>
    </profiles>
Run Code Online (Sandbox Code Playgroud)

此处的配置文件名称为devprod。您可以将其${war.name}用作配置文件修改的变量。