在maven中,如何覆盖settings.xml中的插件配置

Idl*_*hew 7 maven-plugin maven-3 maven

我想覆盖在 pom.xml 中定义的特定插件配置。出于各种原因,我不想修改 pom.xml。有没有办法在 settings.xml 中为该插件定义一个配置属性来覆盖相应的 pom.xml 插件配置?

在下面的例子中,你会注意到插件xx-pluginprofile1在 pom.xml 中定义的。在我的 settings.xml 中,我已经定义profile2为覆盖prop1pom.xml 中的属性。但是如何覆盖config3. 如果这是一个愚蠢的问题,我深表歉意。我对 maven 有点陌生。

这是我的 pom.xml 的样子:

<profile>
  <id>profile1</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>com.xx.yyy</groupId>
        <artifactId>xx-plugin</artifactId>
        <executions>
          <execution>
            <id>xx-install</id>
            <phase>install</phase>
            <goals>
              <goal>xx-install</goal>
            </goals>
            <configuration>
              <config1>AAA</config1>
              <config2>BBB</config2>
              <config3>CCC</config3> <!-- I want to override this with value DDD -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

这是我的 settings.xml 的样子:

<profile>
    <id>profile2</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <prop1>overriden-value</prop1> <!-- This works -->
    </properties>
    <!-- Somehow override config3 here -->
    <!-- <config3>DDD</config3> -->
</profile>
Run Code Online (Sandbox Code Playgroud)

szc*_*npp 4

AFAIK 你只能用settings.xml配置文件覆盖属性。您必须更改插件的配置才能使用属性而不是固定值:

<!-- define your property -->
<properties>
      <prop1>CCC</prop1>
</properties>

<profile>
  <id>profile1</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>com.xx.yyy</groupId>
        <artifactId>xx-plugin</artifactId>
        <executions>
          <execution>
            <id>xx-install</id>
            <phase>install</phase>
            <goals>
              <goal>xx-install</goal>
            </goals>
            <configuration>
              <config1>AAA</config1>
              <config2>BBB</config2>
              <config3>${prop1}</config3> <!-- I want to override this with value DDD -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

请记住,如果在构建调用中激活任何其他配置文件,activeByDefaulttrue设置为 的配置文件将被停用。请参阅http://maven.apache.org/guides/introduction/introduction-to-profiles.html