Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify JAVA_HOME in Jenkins for Java 11

I have several projects running in Java 1.8 and Jenkins groovy script + Ansible acting as a pipleine to do deploys. Some of the projects are now migrated to Java 11 (OpenJDK). How do I configure Jenkins to build these projects in migrated to Java 11?

like image 474
nanospeck Avatar asked Jul 20 '26 14:07

nanospeck


1 Answers

In Jenkins 2.x, under Jenkins | Manage Jenkins | Global Tool Configuration,
you should find a section "JDK Installations".

Configure multiple your jdk there. I'd not recommend "Install automatically" for Oracle JDK given their licensing changes since April 2019.

JDK Installations

This question describes handling multiple jdk in a pipeline.

Corresponding the names in the image example the tools values would be:

  tools {
    jdk 'jdk1.8'
    jdk 'jdk1.6'
  }

For maven,

Use a maven toolchain / profiles to be able to dynamically choose which to use: https://maven.apache.org/guides/mini/guide-using-toolchains.html

https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

ps: for freestyle jobs, the choice in in the General tab: enter image description here

Note: if only one JDK is available, the option is hidden.

like image 95
Ian W Avatar answered Jul 23 '26 03:07

Ian W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!