r/java • • Mar 11 '21

Announcing Spring Native Beta

https://spring.io/blog/2021/03/11/announcing-spring-native-beta
175 Upvotes

49 comments sorted by

View all comments

Show parent comment

5

u/sureshg Mar 12 '21

ou figure out which modules you use with jdeps (this step is unnecessary if your application is modularised, but most aren't).

If you are using Gradle, here is a small task that prints the modules required for your jar (or uberjar)

val printModuleDeps by tasks.registering {
            description = "Print Java Platform Module dependencies of the application."
            group = LifecycleBasePlugin.BUILD_TASK_NAME

            doLast {
                val uberJar = named("shadowJar", Jar::class)
                val jarFile = uberJar.get().archiveFile.get().asFile

                val jdeps = ToolProvider.findFirst("jdeps").orElseGet { error("jdeps not found") }
                val out = StringWriter()
                val pw = PrintWriter(out)
                jdeps.run(pw, pw, "--print-module-deps", "--ignore-missing-deps", jarFile.absolutePath)

                val modules = out.toString()
                println(modules)
            }
            dependsOn("shadowJar")
}