Search code examples
mavenmaven-assembly-pluginmaven-release-plugin

Maven release to perform assembly single in a sub module


I would like to run Maven release so that it should perform an assembly:single for a sub module. I've included the assembly:single as part of the install of the sub module i.e. when you run install on the top level it builds the jar-with-dependencies. But when the release:perform is run, even though it is configured to call install (as a a goal) it does not build the jar-with-dependencies.

How do I run a release at the top level and have this release perform an assembly:single on a sub-level using the release version?

<modules>
    <module>parent</module>
    <module>api</module>
    <module>testing</module>
    <module>main</module>
</modules>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <goals>install</goals>
                <completionGoals>install</completionGoals>
            </configuration>
        </plugin>
    </plugins>
</build>

This is the sub module in main

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.example.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                    <execution>
                        <phase>install</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Solution

  • Use below configuration for release plugin:

    <configuration>
      <preparationGoals>install</preparationGoals>
    </configuration>
    

    and start release preparation from scratch:

    mvn release:prepare -Dresume=false
    

    More detailed explanation of maven-release-plugin parameters:

    <goals>install</goals> Called by release:perform. Release:perform clones your repo to target/checkout directory and calls install in it.

    <preparationGoals>install</preparationGoals> Called by release:prepare. Install is executed before committing, default is clean verify.

    <completionGoals>install</completionGoals> Called by release:prepare. Install is executed after committing. In this case whole build cycle is reiterated.