How to specify --main-class and --module-version in maven-jar-plugin?
A temporary workaround is to call jar --update
in the package
phase:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
...
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<exec executable="${java.home}/bin/jar" failonerror="true">
<arg value="--main-class"/>
<arg value="[main class here]"/>
<arg value="--module-version"/>
<arg value="0.1"/>
<arg value="--update"/>
<arg value="--file"/>
<arg value="${project.build.directory}/${project.artifactId}-${project.version}.jar"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
I'm open for better ideas.
This is possible with maven-jar-plugin version 3.1.2+ (not released yet, but issue is closed):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<archive>
<manifest>
<mainClass>[main class here]</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
The description says:
Starting with version 3.1.2, if the JAR file contains module-info.class, this plugin will update the modular descriptor (module-info.class) with additional attributes [...]. The most notable additional attribute added is the module main class.
Basically it takes the value which is added to the Manifest-file and also adds it to module-info.