Activation in my maven profile is ignored (profile always executed) using file exist

我的梦境 提交于 2019-12-02 07:51:10

问题


I am using activation based on file exists in my pom.xml.

However, my profile is ALWAYS executed, no matter what.

Here is the profile description:

<profile>
    <id>copy</id>
    <activation>
        <file>
            <exists>file.xml</exists>
        </file>
    </activation>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <configuration>
                            <target name="copy and rename file">
                                <copy           file="${basedir}/src/main/resources/application.${env}.properties"  tofile="${basedir}/src/main/fabric8/io.fabric8.system.properties" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

I call my profile like this: mvn package -Pcopy

But the profile is always called, no matter if the file is present or not. What am I doing wrong?

Thanks Romain.


回答1:


You don't need to pass the profile name when running the mvn command if the file exists in the project. Passing -Pcopy explicitly to the command will override the activation in the POM, and will always activate this profile.

See the section How can a profile be triggered in this link.



来源:https://stackoverflow.com/questions/26126828/activation-in-my-maven-profile-is-ignored-profile-always-executed-using-file-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!