Override Maven plugin configuration defined in the pom pluginManagement from the command line

淺唱寂寞╮ 提交于 2020-01-01 07:40:32

问题


The POM that my project inherits contains some <pluginManagement> for the release plugin that specifies some additional arguments.

My question is: Is there a way to override the arguments parameter from the command line in this case?

The parent POM has this:

<pluginManagement>
    <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
            <arguments>-Prelease</arguments>
        </configuration>
    </plugin>
</pluginManagement>

Due to that the command line argument doesn't work:

mvn release:prepare -Darguments="-Pmock -Prelease"

The -Darguments="-Pmock -Prelease" part has no effect. When arguments is not already specified, it works.

It is not possible for me to modify the parent POM or not to use it.


回答1:


Found the solution. In my POM I add this which overrides the settings in the parent POM and allows to specify additional arguments on command line, e.g. -Darguments=-Pmock

<pluginManagement>
    <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
            <arguments>${arguments} -Prelease</arguments>
        </configuration>
    </plugin>
</pluginManagement>



回答2:


You cannot override a configuration, which is already set in the POM (see Maven Bug MNG-4979). You may use variables in order to avoid this behaviour. The snippet of your answer makes use of it.



来源:https://stackoverflow.com/questions/4660047/override-maven-plugin-configuration-defined-in-the-pom-pluginmanagement-from-the

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