sbt-native-packager icon indicating copy to clipboard operation
sbt-native-packager copied to clipboard

Simplifly dealing with jdeps in JlinkPlugin

Open nigredo-tori opened this issue 5 years ago • 0 comments

This was discussed in passing in a few other issues, but I'd rather have one place to track it.

  1. We feed our whole classpath to jdeps to find which platform modules we need. jdeps, however, requires the modules to form a coherent dependency graph with no missing dependencies. This was the reason for #1293. More recently, I've had a similar thing happen because HikariCP added a module descriptor that requires a lot of dependencies it doesn't bring in through its POM, which makes jdeps fail like this:
    $ jdeps -R --multi-release 11 HikariCP-3.4.5.jar
    Exception in thread "main" java.lang.module.FindException: Module micrometer.core not found, required by com.zaxxer.hikari
    	at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
    	at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
    	at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
    	at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
    	at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
    	at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration.<init>(JdepsConfiguration.java:117)
    	at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:563)
    	at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:589)
    	at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:543)
    	at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:519)
    	at jdk.jdeps/com.sun.tools.jdeps.Main.main(Main.java:49)
    
    Note that this can't be dealt with using jlinkIgnoreMissingDependencies! There are other workarounds (e.g. micromanaging jlinkBuildImage / fullClassPath), but using those is annoying, it subtly breaks jlinkModules, and it doesn't have anything to do with building an image.
  2. jlinkIgnoreMissingDependencies is annoying. It's a remnant of the first iteration of JlinkPlugin, before we restricted it to only platform modules (#1248), and I didn't find much use for it so far except for finding missing Jakarta API dependencies. I think this dependency check should be restricted to platform modules/packages only.

Here's a helper plugin I've hacked together to simplify dealing with this stuff: https://gist.github.com/nigredo-tori/3b168da8e3cdcc7766ace3f23e999ec5 . These tweaks can't be adopted into this project as they are - mostly because they use Java 11 - but it should hopefully be useful as a starting point for solving the issues above.

nigredo-tori avatar Oct 13 '20 09:10 nigredo-tori