You could use the Checksum Maven Plugin and its artifacts goal.
I just tested the following sample POM:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>create-jar-something</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>something</classifier>
</configuration>
</execution>
<execution>
<id>create-jar-else</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>else</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.ju-n.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>artifacts</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Note: I am creating three artefacts from this project: the default one and two additional jars with classifiers.
Thanks to the simple and single execution of the artifacts
goal, I got the following content as part of the build (mvn clean verify
):
Via the additional individualFiles
configuration entry, you can also decide whether to store the checksums in separated files (default) or appended in one single file, while via the individualFilesOutputDirectory
configuration entry you can redirect their creation to another location, if required.
Hence, this approach could suit your need, since it will automatically detect any generated artifact and calculate the checksum for it.
Also note in case of multi-modules projects that as per documentation:
Is NOT inherited by default in multi-project builds.
In such a case you can place the snippet above in the pluginManagement
section of your parent/aggregator pom and just re-declare the plugin (but not its execution nor its version) in the submodules where you want to activate the behavior.
Hence, in your parent/aggregator you could have something like:
<pluginManagement>
<plugins>
<plugin>
<groupId>net.ju-n.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<goals>
<goal>artifacts</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
</plugins>
</pluginManagement>
And in the modules you want to enable this behavior you would then only specify:
<build>
<plugins>
<plugin>
<groupId>net.ju-n.maven.plugins</groupId>
<artifactId>checksum-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Last but not least: if part of a CI build on Jenkins, you could also consider a dedicated profile for this behavior and activate it on the build but not as part of the default build.