How to build java dependencies on maven dependencies

Java9 introduced strong modularity similar to OSGI and Maven Dependecies.

Is there a maven plugin for building java 9 dependencies checking maven dependencies?

For example, from

<groupId>com.mycompany.app</groupId> <artifactId>my-module</artifactId> .... <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>23.3-jre</version> </dependency> 

before

 module my-module{ requires com.google.guava; exports com.mycompany.app; } 

I read this article, but it is not so useful - How to express maven dependency on java ee functions to migrate to Java 9?

+2
java maven java-9 modularity module-info
source share
2 answers

To answer the question exactly, the module names in module-info , as indicated in a question like com.google.guava per say, are called the automatic module name. Generally, if you already have a jar of Java 8 for your application, say yourApp.jar with the above maven configuration. You can use jdeps tool like: -

 jdeps --generate-module-info <output-dir> /path/to/yourApp.jar 

which will generate module-info.java for your jar, which you can use when migrating the same project to Java 9.

The current matching plugin called maven-jdeps-plugin does not seem to support this task. Although its still โ€œWork in progressโ€ , and this can happen if it is seen by the owners who will be represented in the Maven workflow.

Edit :: Just in case, if you find a useful task, a function can be requested on the MJDEPS Tracker.

+6
source share

In this gythub repo is https://github.com/moditect/moditect which allows you to do this.

In your example, add the following to the maven assembly:

 <plugin> <groupId>org.moditect</groupId> <artifactId>moditect-maven-plugin</artifactId> <version>1.0.0.Alpha2</version> <executions> <execution> <id>add-module-infos</id> <phase>package</phase> <goals> <goal>add-module-info</goal> </goals> <configuration> <module> <moduleInfo> <name>com.mycompany.app.my.module</name> </moduleInfo> </module> </configuration> </execution> </executions> </plugin> 

and under target/moditect you can find the generated module-info.java

+3
source share

All Articles