Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In maven, how to override plugin configuration in settings.xml

I want to override a particular plugin configuration that's defined in the pom.xml. I don't want to modify the pom.xml for various reasons. Is there a way to define a config attribute for that plugin in settings.xml that override corresponding pom.xml plugin config?

In the below example, you'll notice that the plugin xx-plugin is defined in profile1 in pom.xml. In my settings.xml I've already defined profile2 to override property prop1 from pom.xml. But how to override config3. I apologize if this is a silly question. I am a little new to maven.

This is what my pom.xml looks like:

<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>

This is what my settings.xml looks like:

<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>
like image 751
IdleCashew Avatar asked Feb 09 '17 20:02

IdleCashew


1 Answers

AFAIK you can only override properties with settings.xml profiles. You'd have to change your plugin's configuration to use a property instead of a fixed value:

<!-- 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>

Remember that profiles with activeByDefault set to true will get deactivated if any other profile gets activated in your build invocation. See http://maven.apache.org/guides/introduction/introduction-to-profiles.html

like image 163
szczepanpp Avatar answered Sep 30 '22 11:09

szczepanpp