开发者

How to override maven-release-plugin config in one child module

开发者 https://www.devze.com 2023-03-12 04:37 出处:网络
I have a multi-module maven build where one of the child modules requires an extra goal to be executed as part of a release. But it lo开发者_运维技巧oks as though any configuration of the maven-releas

I have a multi-module maven build where one of the child modules requires an extra goal to be executed as part of a release. But it lo开发者_运维技巧oks as though any configuration of the maven-release-plugin in the child module is ignored in favour of the default configuration in the parent module.

This is the snippet from the child module. The plugin configuration is the same in the pluginManagement section of the parent pom, but without the custom element.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>    
    <version>2.1</version>
    <configuration>
        <tagBase>http://mycompany.com/svn/repos/myproject/tags</tagBase>
        <goals>deploy myCustomPlugin:myCustomGoal</goals>
    </configuration>
</plugin>

So is it possible for a child module to override the parent's configuration and add extra goals?

Maven version 2.2.1


Use combine.children="append" combine.self="override"

Parent POM

<configuration>
  <items>
    <item>parent-1</item>
    <item>parent-2</item>
  </items>
  <properties>
    <parentKey>parent</parentKey>
  </properties>
</configuration>

Child pom

<configuration>
  <items combine.children="append">
    <!-- combine.children="merge" is the default -->
    <item>child-1</item>
  </items>
  <properties combine.self="override">
    <!-- combine.self="merge" is the default -->
    <childKey>child</childKey>
  </properties>
</configuration>

Result

<configuration>
  <items combine.children="append">
    <item>parent-1</item>
    <item>parent-2</item>
    <item>child-1</item>
  </items>
  <properties combine.self="override">
    <childKey>child</childKey>
  </properties>
</configuration>

See this blog for further details


Yes and no. Certainly a child pom can override the configuration of a plugin specified by its parent, and I have to assume you've done so correctly because there's nothing really hard about it. If you check the output of mvn help:effective-pom, you should be able to see plainly that this module has different settings for the release plugin.

The problem you're having is with the behavior of the release plugin. Typically, if you run a goal or phase--mvn compile, for example--from the root module of your project, it first runs that goal/phase on the root module, then on all the modules in reactor order, almost as if you'd run it in each module yourself. Any customizations you've added to child modules take effect as expected. When you run the release plugin, it runs only at the root module. It doesn't run in any of the child modules. Instead, running it at the root module forks a new build using the same settings as the root module, which runs for all the other modules in nearly the same way, except that it uses the root module's configuration for all the modules. I don't know the exact semantics, but I believe this is analogous to you manually running the release goals in each child and specifying the configuration options as system properties at the command line: regardless of how a child module configures the release plugin, the command line args win.

I've never dealt with this problem myself, and it's hard to say without knowing exactly what you're trying to accomplish. Perhaps if you can express what you want to do in this special module as a profile, then you could add a profile to your goals and or preparationGoals. Alternately, there's an arguments option to both the prepare and perform goals that you might be able to pull some tricks with.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号