覆盖Maven插件参数

Evg*_*pov 3 maven

我有一个Maven插件,它在POM文件中配置为

<build>
    <plugins>
        <plugin>
            <groupId>com.example</groupId>
            <artifactId>example-maven-plugin</artifactId>
            <configuration>
                <scriptsPath>scripts</scriptsPath>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

现在我想scriptsPath从命令行覆盖它,然后运行

mvn -X example-maven-plugin:goal -DscriptsPath=scripts1
Run Code Online (Sandbox Code Playgroud)

我可以看到的价值scriptsPath仍然存在,scripts而没有scripts1。可以从命令行覆盖配置参数吗?

Ste*_*vra 5

不幸的是,没有使用属性覆盖Maven插件配置的通用方法。如果插件文档未明确允许您使用属性来设置配置值,则可以使用以下模式:

<properties>
    <scripts.path>scripts</scripts.path>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>com.example</groupId>
            <artifactId>example-maven-plugin</artifactId>
            <configuration>
                <scriptsPath>${scripts.path}</scriptsPath>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

然后执行Maven作为

mvn -X example-maven-plugin:goal -Dscripts.path=scripts1
Run Code Online (Sandbox Code Playgroud)

  • 好吧,它使用相同的方法。但是,在链接的答案中,通过属性设置的是&lt;version&gt;,对于没有经验的maven用户来说,这看起来像是对另一个问题的答案。这就是为什么我回答了他的问题而没有将其标记为重复的原因。 (3认同)