wttech/gradle-aem-plugin

Use Gradle Java toolchain to run Maven in hybrid build

pun-ky opened this issue · 3 comments

Same as for launching AEM instance:

https://stackoverflow.com/a/19654699/3360007

here JAVA_PATH need to be overridden with that path from common.javaSupport: https://github.com/wttech/gradle-aem-plugin/blob/master/src/main/kotlin/com/cognifide/gradle/aem/common/mvn/MvnModule.kt#L174

spec {
  environment("JAVA_PATH", common.javaSupport.homePath)
}

as a consequence, GAP will launch Maven build with the version set in gradle.properties which will allow to have any version of Java installed as GAP will use Gradle toolchain to download appropriate version on the fly if missing

javaSupport.version=11

implemented in Gradle Common Plugin

then

    register("foo") {
        doLast {
            common.mvn {
                args("--version")
            }
        }
    }

with

gw foo -S -PjavaSupport.version=11
gw foo -S -PjavaSupport.version=16
gw foo -S -PjavaSupport.version=8

will print different versions

e.g

Starting process 'command 'mvn''. Working directory: /Users/krystian.panek/Projects/other/straumann Command: mvn -B --version
Successfully started process 'command 'mvn''
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3/libexec
Java version: 16.0.2, vendor: Eclipse Foundation, runtime: /Users/krystian.panek/.gradle/jdks/jdk-16.0.2+7/Contents/Home
Default locale: en_PL, platform encoding: UTF-8
OS name: "mac os x", version: "11.5", arch: "x86_64", family: "mac"
:foo (Thread[Execution worker for ':',5,main]) completed. Took 0.241 secs.


note that this feature is not working with JEnv when jenv enable-plugin maven was run;
to make it working run jenv disable-plugin maven

released in 15.3.0