# Java version error in jenkins pipeline

**URL:** <https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221>\
**Category:** Community\
**Tags:** java, sig-infra, version-numbers, pipeline\
**Created:** [October 19, 2022, 8:57am UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221 "2022-10-19T08:57:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![keremozben](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@keremozben](https://community.jenkins.io/u/keremozben)\
**Post date:** [October 19, 2022, 8:58am UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/1 "2022-10-19T08:58:00Z")

</div>

Hi all,

I am developing a jenkins plugin for my company and after dropping support for java 8, I updated the plugin and its dependencies to latest versions and everything is working perfectly on my local environment. But when I push latest code to github repo and trigger the jenkins pipeline, it seems that the pipeline uses Java 8 and build is failing. How am I suppose to use make/force the pipeline to use Java 11 or 18, how can I configure it ? Here is the error message. Any help would be greatly appreciated.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/5/5943ed6225841f29b6c84e87175cb5cd0e1446e3.png)

---

<div class="post-metadata">

**Author:** ![dduportal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/dduportal/32/18_2.png) [@dduportal](https://community.jenkins.io/u/dduportal)\
**Post date:** [October 19, 2022, 11:48am UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/2 "2022-10-19T11:48:30Z")

</div>

Hi @keremozben , is it a public plugin (so we can check the `Jenkinsfile` and help you) or is it a closed source plugin?

In the screenshot that you are showing, the `mvn` command reports that it is using JDK8, whcih explains the behavior.

The Maven command line (`mvn`) selects the JDK to use by looking at the environment variable `JAVA_HOME` or searching for the binary `java` in the `PATH`.

=\> These settings depends a lot on “wherwhich Jenkins controller runs this pipeline” : can you explain if it is [ci.jenkins.io](http://ci.jenkins.io) (the public controller for the CI of Jenkins public plugins) or is it a Jenkins controller in your organization?

If it is the 2nd, then you have to search for the `Jenkinsfile` of the pipeline to find what kind of agent is used (or if a “Jenkins tool” is used) to determine how is Maven installed and configured.

---

<div class="post-metadata">

**Author:** ![keremozben](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@keremozben](https://community.jenkins.io/u/keremozben)\
**Post date:** [October 19, 2022, 1:30pm UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/3 "2022-10-19T13:30:52Z")

</div>

Hi @dduportal ,

It is a public plugin, here is the repository link: [GitHub - jenkinsci/netsparker-cloud-scan-plugin: Allows users to start security scans via Netsparker Enterprise](https://github.com/jenkinsci/netsparker-cloud-scan-plugin)

This pipeline runs on [ci.jenkins.io](http://ci.jenkins.io).

---

<div class="post-metadata">

**Author:** ![uhafner](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/uhafner/32/68_2.png) [@uhafner](https://community.jenkins.io/u/uhafner)\
**Post date:** [October 19, 2022, 2:35pm UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/4 "2022-10-19T14:35:57Z")

</div>

You need to set the JDK in your Jenkinsfile. See documentation at [GitHub - jenkins-infra/pipeline-library: Collection of custom steps and variables for our Jenkins instance(s)](https://github.com/jenkins-infra/pipeline-library).

Example: [warnings-ng-plugin/Jenkinsfile at b57a36462485f64cafdec8771386bdffbae35d4e · jenkinsci/warnings-ng-plugin · GitHub](https://github.com/jenkinsci/warnings-ng-plugin/blob/b57a36462485f64cafdec8771386bdffbae35d4e/Jenkinsfile)

---

<div class="post-metadata">

**Author:** ![dduportal](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/dduportal/32/18_2.png) [@dduportal](https://community.jenkins.io/u/dduportal)\
**Post date:** [October 19, 2022, 2:37pm UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/5 "2022-10-19T14:37:03Z")

</div>

Perfect !

So:

- the `Jenkinsfile` is located at [https://github.com/jenkinsci/netsparker-cloud-scan-plugin/blob/62cf4d569d6c00ef3ba25ffd470ac7a60ce1ecfc/Jenkinsfile](https://github.com/jenkinsci/netsparker-cloud-scan-plugin/blob/62cf4d569d6c00ef3ba25ffd470ac7a60ce1ecfc/Jenkinsfile)

- As you can see, its only instruction is a call to a method `buildPlugin()` with no arguments.

- This method comes from our pipeline library and is documented here: [https://github.com/jenkins-infra/pipeline-library#buildplugin](https://github.com/jenkins-infra/pipeline-library#buildplugin)

So you might want to try `buildPlugin(jdkVersions: [11])` for instance (or look at `configurations` if you want a finer grain).

---

<div class="post-metadata">

**Author:** ![jglick](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jglick/32/77_2.png) [@jglick](https://community.jenkins.io/u/jglick)\
**Post date:** [October 19, 2022, 5:39pm UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/6 "2022-10-19T17:39:07Z")

</div>

> <https://github.com/jenkinsci/netsparker-cloud-scan-plugin/commit/4040034977fd92dd67a92d74cb85cc634110a410#r87292857>

---

<div class="post-metadata">

**Author:** ![jglick](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jglick/32/77_2.png) [@jglick](https://community.jenkins.io/u/jglick)\
**Post date:** [October 19, 2022, 5:40pm UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/7 "2022-10-19T17:40:01Z")

</div>

BTW I would recommend using pull request flow even if you are the sole committer and maintainer, just so that you can check that proposed changes pass CI.

---

<div class="post-metadata">

**Author:** ![keremozben](https://avatars.discourse-cdn.com/v4/letter/k/43a26b/32.png) [@keremozben](https://community.jenkins.io/u/keremozben)\
**Post date:** [October 20, 2022, 9:08am UTC](https://community.jenkins.io/t/java-version-error-in-jenkins-pipeline/4221/8 "2022-10-20T09:08:04Z")

</div>

Thank you so much @uhafner @dduportal I configured properly and it works.
