question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ModiTect not finding module dependencies

See original GitHub issue

I’ve configured ModiTect to generate module-info.javas 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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
garzycommented, Aug 23, 2019

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>
0reactions
garzycommented, Dec 17, 2019

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ModiTect and Jlink not finding module dependencies
The workaround is to use the maven-dependency plugin to copy them to a known directory which can be added to the module path....
Read more >
Unable to import the Maven multi module successfully in ...
Unable to import the Maven multi module successfully in WSL2 if root Maven pom.xml use the module as a dependency ; Project, IntelliJ...
Read more >
Containerizing Apps with jlink - Oracle Blogs
Adding Nonmodule Dependencies ... Unfortunately, jlink works only with modules and it will fail if not all dependencies are modules. The only way ......
Read more >
Maintaining a medium-sized Java library in 2022 and beyond
Use properties and dependency management for versions; 2.2.2. ... actually and without joking, the module system.
Read more >
Migrating to Java 9 Modules with ModiTect by Gunnar Morling
Find out how to generate descriptors based on your application's dependencies, add them to existing JARs and create a fully self-contained ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found