Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven-release-plugin goals ignored in submodule in multi-module project

I have a multi-module Maven project. The project is laid out as follows

project/
  pom.xml

  types/
    pom.xml

  client/
    pom.xml

  service/
    pom.xml

The types and client modules are built as JARs, service is built as a WAR. I'm using the maven-release-plugin to create new releases of this project. I would like to have the release plugin invoke extra goals when performing the release of the service module.

The release plugin is configured like so in the root pom (nothing special):

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.5.3</version>
</plugin>

... and configured like so in the service pom along with the plugin I'm trying to invoke via the <goals> parameter:

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <configuration>
    <goals>deploy dockerfile:build dockerfile:push</goals>
  </configuration>
</plugin>

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <configuration>
    <repository>12345.ecr.us-east-1.amazonaws.com/project</repository>
  </configuration>
</plugin>

The idea is that I'd like to build a Docker image for the service module but it doesn't make sense to build images for other modules in the project. However, when cutting a new release, the goals configuration in the service pom file are never invoked.

Maven version: 3.3.3

maven-release-plugin: 2.5.3

JDK: Oracle 1.8.0u144

The command being used:

mvn -Pstaging -B clean release:clean release:prepare release:perform

I'm not able to share the output from this command.

I've verified that the relevant configurations seem be be applied via

mvn -Pstaging help:effective-pom 

My question is: Is what I'm trying to accomplish possible with the release plugin? I haven't found any questions or articles that indicate it's impossible.

like image 293
Nick Pillitteri Avatar asked Jan 25 '26 23:01

Nick Pillitteri


1 Answers

With the caveat that I have never used the dockerfile-maven-plugin, try release profiles instead of goals.

Step 1. Edit the release plugin config in project/pom.xml.

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.5.3</version>   <!-- should define in pluginManagement -->
  <configuration>
    <releaseProfiles>publish-docker</releaseProfiles>
    <!-- other plugin config -->
  </configuration>
</plugin>

Choose a name for the profile that makes sense. I'll use publish-docker as the name here.

Step 2. Add a profile with that name to service/pom.xml:

<profiles>
  <profile>
    <id>publish-docker</id>
    <build>
      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>dockerfile-maven-plugin</artifactId>
        <configuration>
          <repository>12345.ecr.us-east-1.amazonaws.com/project</repository>
        </configuration>
        <executions>
          <execution>
            <id>docker-publish</id>
            <phase>deploy</phase>  <!-- important -->
            <goals>
              <goal>build</goal>
              <goal>push</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </build>
  </profile>
</profiles>

This profile includes plugin configuration that binds the dockerfile:build and dockerfile:push goals to the deploy phase. The release plugin will enable the publish-docker profile for each module. The profile will only exist in the service module, so that's where it will run.

One other thing I notice. In the release command:

mvn -Pstaging -B clean release:clean release:prepare release:perform

I suspect the -Pstaging part is not actually being applied during the release. The release plugin forks another process for each goal run. To pass the argument to the fork, the arguments parameter is required:

mvn -Pstaging -Darguments="-Pstaging" -B clean release:clean release:prepare release:perform
like image 195
user944849 Avatar answered Jan 27 '26 15:01

user944849



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!