moditect
moditect copied to clipboard
ModiTect not finding module dependencies
I've configured ModiTect to generate module-info.java
s for all my dependencies (that don't have them) and that seems to be working; but when it comes to dependencies that do have them, it's not finding them.
When I run mvn package
in my app it's failing with:
[INFO] --- moditect-maven-plugin:1.0.0.Beta1:create-runtime-image (create-runtime-image) @ dashman ---
[ERROR] Error: Module tech.dashman.dashmancommon not found, required by tech.dashman.dashman`
Now, I know tech.dashman.dashmancommon
is a module and has a module-info.java
because I built it myself. How do I make ModiTect/Jlink find all the dependent modules in their original jars?
My under-construction ModiTect config looks like this:
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.Beta1</version>
<executions>
<execution>
<id>add-module-info-to-dependencies</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
<overwriteExistingFiles>true</overwriteExistingFiles>
<modules>
<module>
<artifact>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.59</version>
</artifact>
<moduleInfoSource>
module bcprov.jdk15on {
exports org.bouncycastle.jce.provider;
exports org.bouncycastle.jce.spec;
exports org.bouncycastle.util.encoders;
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.5.RELEASE</version>
</artifact>
<moduleInfoSource>
module spring.core {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.5.RELEASE</version>
</artifact>
<moduleInfoSource>
module spring.context {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>1.2.2.RELEASE</version>
</artifact>
<moduleInfoSource>
module spring.retry {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.0.5.RELEASE</version>
</artifact>
<moduleInfoSource>
module spring.web {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>com.pubnub</groupId>
<artifactId>pubnub-gson</artifactId>
<version>4.19.0</version>
</artifact>
<moduleInfoSource>
module pubnub.gson {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</artifact>
<moduleInfoSource>
module com.fasterxml.jackson.core {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<version>2.1.1</version>
</artifact>
<moduleInfoSource>
module org.kordamp.ikonli.javafx {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>io.sentry</groupId>
<artifactId>sentry</artifactId>
<version>1.7.2</version>
</artifact>
<moduleInfoSource>
module io.sentry {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.22.0-CR2</version>
</artifact>
<moduleInfoSource>
module javassist {
}
</moduleInfoSource>
</module>
<module>
<artifact>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</artifact>
<moduleInfoSource>
module java.validation {
}
</moduleInfoSource>
</module>
</modules>
</configuration>
</execution>
<execution>
<id>create-runtime-image</id>
<phase>package</phase>
<goals>
<goal>create-runtime-image</goal>
</goals>
<configuration>
<modulePath>
<path>${project.build.directory}/modules</path>
<path>${project.build.directory}/classes</path>
</modulePath>
<modules>
<module>tech.dashman.dashman</module>
</modules>
<outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
BTW, I posted this as a question in Stack Overflow: https://stackoverflow.com/questions/49716711/moditect-and-jlink-not-finding-module-dependencies
@pupeno Any chance you share the sources of the tech.dashman.dashmancommon module?
I'm sorry, but that's proprietary code. I ended up not moving to Java 9, so, I'm not using Moditect anymore.
I'm back moving to Java 10 and experiencing this problem again.. @gunnarmorling what do you need to see of tech.flexpoint.dashmancommon
(formerly tech.dashman.dashmancommon
)? It's module-info.java
looks like this:
// Copyright (c) 2018 Flexpoint Tech Ltd. All rights reserved.
module tech.flexpoint.dashmancommon {
exports tech.flexpoint.dashmancommon;
exports tech.flexpoint.dashmancommon.models;
exports tech.flexpoint.dashmancommon.dto;
exports tech.flexpoint.dashmancommon.crypto;
exports tech.flexpoint.dashmancommon.serializers;
exports tech.flexpoint.dashmancommon.constraints;
opens tech.flexpoint.dashmancommon.crypto to com.fasterxml.jackson.databind;
requires spring.context;
requires com.fasterxml.jackson.core;
requires com.fasterxml.jackson.databind;
requires java.validation;
requires java.desktop;
requires bcprov.jdk15on;
requires jackson.annotations;
}
This is the command line:
Running jlink: C:\Program Files\Java\jdk-10.0.1\bin\jlink --add-modules tech.flexpoint.dashmanserver --module-path C:\Users\pupeno\Documents\Dashman\code\dashmanserver\target\modules;C:\Program Files\Java\jdk-10.0.1\jmods;C:\Users\pupeno\Documents\Dashman\code\dashmanserver\target\classes --output C:\Users\pupeno\Documents\Dashman\code\dashmanserver\target\jlink-image --launcher dashmanserver=tech.flexpoint.dashmanserver
I don't see in there anything that would cause jlink to find the installed dashmancommon jar, if I add this:
<path>c:\Users\pupeno\.m2\repository\tech\flexpoint\dashmancommon\1.0.0-beta.11</path>
to the config, it starts finding. So, I'm guessing the module for dashmancommon works, it's just that ModiTect is not automatically adding the paths for dependencies.
I have the same problem. I have a lot of dependencies I have moditect create module-infos for, and some (I created myself) that already are modules, but the create-runtime-image goal does only take the modules from the configured path, but not those configured as dependencies.
Hello guys, I just fixed the problem with the next trick that exports dependency libs to target/lib
and uses these libs as another path in modulePath
declaration.
At this moment, this code WORKS! 🥇
...
<execution>
<id>create-runtime-image</id>
<phase>package</phase>
<goals>
<goal>create-runtime-image</goal>
</goals>
<configuration>
<!--requires toolchains.xml file in .m2/ user folder -->
<baseJdk>version=12,vendor=openjdk</baseJdk>
<modulePath>
<path>${project.build.directory}/modules</path>
<path>${project.build.directory}/lib</path>
</modulePath>
<modules>
<module>my.app.module</module>
</modules>
<launcher>
<name>my.app</name>
<module>my.app.module</module>
</launcher>
<outputDirectory>
${project.build.directory}/jlink-image
</outputDirectory>
<compression>2</compression>
<stripDebug>true</stripDebug>
</configuration>
</execution>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<!-- <excludeArtifactIds>junit,hamcrest-core</excludeArtifactIds> -->
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
@garzy That's a great solution. Exactly what I needed. Thank you!
Thanks, also, sometimes runtime image generation fails due to "duplicated" modules because the maven dependency plugin will also export the jars of the libs that we are "mocking" with moditect.
In this case the solution is include these conflictive artifact ids in the "excludeArtifactIds" commented section of the maven-dependency-plugin (only artifact ids, comma separated)