Is there a maven jigsaw jlink plugin?
Asked Answered
M

4

10

Does maven have a plugin for the new Java 9 jlink I have searched online but have not been able to find anything official from the maven team.

Melanism answered 5/6, 2017 at 1:35 Comment(1)
blog.soebes.de/blog/2017/06/06/…Medicine
A
6

Yes. There has been some progress made to create one on Github/maven-plugins for the same.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jlink-plugin</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</plugin>

The plugin in its code reads to be adaptive to JEP-282 and JEP-220 from the proposals.

And though this might look like a link too many answer. There is a working example from @khmarbaise on Github as well for this, which requires a toolchain with -

<configuration>
  <jdkHome>/Library/Java/JavaVirtualMachines/jdk1.9.0_ea+170.jdk/Contents/Home</jdkHome>
</configuration>

Plus a side note from the author quoting -

Currently not more than a Proof of Concept. Everything here is speculative!

Edit1:- As shared in the comments, additional details could be found @ How to create a Java runtime with Maven.

Edit2:- Dated 10 November, 2018 one can upgrade to using maven-jlink-plugin:3.0.0-alpha-1 and still provide some valuable feedback.

Aggrieve answered 5/6, 2017 at 6:5 Comment(4)
Also expecting the author of the shared example shall pitch in soon to correct anything misplaced in the answer. :)Aggrieve
Here I am ;-) ..Can you tell me what the configuration snippet is intended for ?Medicine
thats from the prerequisites, just to make sure the toolchain.xml configuration is appropriate in the /.m2 folder of the machine.Aggrieve
Some more informations about it: blog.soebes.de/blog/2017/06/06/…Medicine
Q
4

I'm working on ModiTect, general tooling around Java 9 modules. One of the goals of the ModiTect Maven plug-in lets you create module runtime images via jlink:

<plugin>
    <groupId>org.moditect</groupId>
    <artifactId>moditect-maven-plugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <executions>
        <execution>
            <id>create-runtime-image</id>
            <phase>package</phase>
            <goals>
                <goal>create-runtime-image</goal>
            </goals>
            <configuration>
                <modulePath>
                    <path>${project.build.directory}/modules</path>
                </modulePath>
                <modules>
                    <module>com.example.module1</module>
                    <module>com.example.module2</module>
                </modules>
                <launcher>
                    <name>helloWorld</name>
                    <module>com.example.module1</module>
                </launcher>
                <outputDirectory>
                    ${project.build.directory}/jlink-image
                </outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

The plug-in is under active development right now and must be built from source for the time being (will deploy a first version to Maven Central soon).

Quadrennium answered 12/7, 2017 at 22:32 Comment(3)
ModiTect 1.0.0.Alpha1 is available on Maven Central now.Quadrennium
Just curious to know, why should one use this over maven's own plugin? :)Aggrieve
The idea behind ModiTect is more that of an entire workflow where you first add module descriptors to the JAR you build and/or its dependencies (assuming they don't have module descriptors yet) and then take all this ad-hoc modularized JARs to build a modular runtime image.Quadrennium
L
1

there is mvn-jlink plugin which allows to call jdeps and jlink (and any tool provided by jdk), also it can download and unpack needed openjdk version from ADOPT and LIBERICA, such way allows build cross-platform images

<plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>mvn-jlink-wrapper</artifactId>
    <version>1.0.0</version>
    <executions>
        <execution>
            <id>call-jlink</id>
            <goals>
                <goal>jlink</goal>
            </goals>
            <configuration>
                <jdepsReportPath>${project.build.directory}${file.separator}jdeps.out</jdepsReportPath>
                <output>${project.build.directory}${file.separator}preparedJDK</output>
                <addModules>
                    <module>java.compiler</module>
                </addModules>
                <options>
                    <option>--compress=2</option>
                    <option>--no-header-files</option>
                    <option>--no-man-pages</option>
                </options>
            </configuration>
        </execution>
    </executions>
</plugin>
Laing answered 14/1, 2019 at 23:12 Comment(0)
F
0

Maybe check out https://github.com/ghackenberg/jigsaw-maven-plugin. The plugin also supports

  • jdeps --generate-module-info + javac + jar for patching unnamed modules,
  • jlink for creating runtime images, and
  • jpackage for creating application installers (only available since JDK 14 though).

You find the plugin documentation on the Github README page.

<plugin>
   <groupId>io.github.ghackenberg</groupId>
   <artifactId>jigsaw-maven-plugin</artifactId>
   <version>1.1.3</version>
</plugin>
Fargone answered 1/6, 2022 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.