Follow-up NXP-24952
Setting the tool is not enough in some pipelines: the JAVA_HOME or the PATH is not correct.
ftest.groovy, sonar.groovy and utest.groovy do not make Maven use the right tool:
Java version: 1.8.0_191, vendor: Oracle Corporation
tests_1 | Detected JDK Version: 1.8.0-191 is not in the allowed range [11,).
Setting the tool is not enough to get some related variables being set. In the case of Maven, it needs JAVA_HOME for instance.
Here are various working solutions:
jdk = tool name: 'java-11-openjdk' env.JAVA_HOME = "${jdk}" withEnv(['MAVEN_OPTS=...']) { sh """#!/bin/bash -ex mvn -v """ }
withEnv(["JAVA_HOME=${ tool 'java-11-openjdk' }", 'MAVEN_OPTS=...']) { sh """#!/bin/bash -ex mvn -v """ }
withMaven(jdk: 'java-11-openjdk', mavenOpts: '... <there is a bug?! prefer the following Shell export>') { sh """#!/bin/bash -ex export MAVEN_OPTS='...' mvn -v """ }