beryx / badass-jlink-plugin

Create a custom runtime image of your modular application
https://badass-jlink-plugin.beryx.org
Apache License 2.0
379 stars 25 forks source link

Gradle Java ToolChain support in Gradle 6.7 and later #170

Closed msgilligan closed 3 years ago

msgilligan commented 3 years ago

Gradle 6.7 added support for Java Toolchains which allows a build to be configured to use a specific version of the JDK, to auto-detect JDKs, and to download a specific JDK automatically.

It would be nice if the BA JLink Plugin was able to make use of this capability as described in Toolchains for plugin authors.

For now it is possible to do something like the following):

String findDefaultToolchainJavaHome() {
    // Use the Gradle default Java Toolchain to find the JDK Home for the JLink Plugin
    def defaultToolchain = project.getExtensions().getByType(JavaPluginExtension.class).toolchain
    JavaToolchainService service = project.getExtensions().getByType(JavaToolchainService.class)
    return service.launcherFor(defaultToolchain).get().metadata.installationPath.asFile.absolutePath
}

jlink {
    javaHome = findDefaultToolchainJavaHome()
    ...
    jpackage {
        jpackageHome = findDefaultToolchainJavaHome()
    }
    ...
}
msgilligan commented 3 years ago

See https://github.com/gradle/gradle/issues/15027 for more relevant info.

siordache commented 3 years ago

Implemented in 2.23.3. The default value of the properties javaHome and jpackageHome takes now into account the Java toolchain.

msgilligan commented 3 years ago

I just upgraded SupernautFX to BA JLink 2.23.3: https://github.com/SupernautApp/SupernautFX/commit/621a4d1d934a95695410173ec05cf064cedbdf46

Thanks @siordache !

One thing to note when upgrading to 2.23.3 is that if have the BADASS_JLINK_JPACKAGE_HOME environment set in your global shell startup, you'll need to remove it to make your current project build and this may break your other projects.

(My intention is to upgrade all my projects to Gradle 6.8+ and BA JLink plugin to 2.23.3+, so I'm just noting this a potential gotcha for others.)