# How to specify jdk version, Jenkins keeps using default Java

**URL:** <https://community.jenkins.io/t/how-to-specify-jdk-version-jenkins-keeps-using-default-java/4335>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [October 28, 2022, 12:21am UTC](https://community.jenkins.io/t/how-to-specify-jdk-version-jenkins-keeps-using-default-java/4335 "2022-10-28T00:21:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![echujonut](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/echujonut/32/2561_2.png) [@echujonut](https://community.jenkins.io/u/echujonut)\
**Post date:** [October 28, 2022, 12:21am UTC](https://community.jenkins.io/t/how-to-specify-jdk-version-jenkins-keeps-using-default-java/4335/1 "2022-10-28T00:21:33Z")

</div>

I been using Jenkins 2.346.1 which by default the controller uses java 8. I have added a java 7 jdk via Global Tools Configuration. I’m trying to use Grails to build a WAR file, that needs java 7, I’ve created both a freestyle project and a pipeline project, that should explicitly be using Java 7. But every time the freestyle project builds it use the java 8, and so does the pipeline.

 ![Screen Shot 2022-10-27 at 6.14.29 PM](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/2/284901b6e155e7bdbd3236d5a0e36b174c13b4e4.jpeg)

Here is my pipeline-line code:

> pipeline {  
> agent any  
> stages {  
> stage (‘checkout svn’) {  
> steps {  
> script{  
> def svnVar = checkout([$class: ‘SubversionSCM’,  
> additionalCredentials: ,  
> excludedCommitMessages: ‘’,  
> excludedRegions: ‘’,  
> excludedRevprop: ‘’,  
> excludedUsers: ‘’,  
> filterChangelog: false,  
> ignoreDirPropChanges: false,  
> includedRegions: ‘’,  
> locations: [[cancelProcessOnExternalsFail: true,  
> credentialsId: ‘e6c2f984-a684-4401-93af-69c39ad4aa74’,  
> depthOption: ‘infinity’,  
> ignoreExternalsOption: true,  
> local: ‘.’,  
> remote: ‘[https://svn.chpc.utah.edu/repo/mhp/medhomexml/trunk](https://svn.chpc.utah.edu/repo/mhp/medhomexml/trunk)’]],  
> quietOperation: true,  
> workspaceUpdater: [$class: ‘UpdateUpdater’]])  
> svnRevision = svnVar.SVN\_REVISION  
> }
> 
> ```
> }
> }
> stage ('change name') {
> steps {
> script {
> currentBuild.displayName = "v${svnRevision}"
> }
> }
> }
> stage('inject GWT_HOME') {
> steps {
> sh "export GWT_HOME=/opt/gwt-2.6.1/"
> echo "$GWT_HOME"
> }
> }
> stage ('run ant') {
> tools {
> jdk 'java-8.0.292'
> }
> steps {
> sh "ant -Dsvn.revision=${svnRevision} deploydev" 
> sh 'ant -version'
> }
> }
> stage('grails war') {
> tools {
> jdk 'java-7-sdk'
>             
> }
> steps {
> sh "echo workspace: ${WORKSPACE}"
> sh "echo svnRevision: ${svnRevision}"
> sh 'java -version'
> sh 'javac -version'
> sh """echo $JAVA_HOME
>             
> cd grails 
> java -version
> export JAVA_HOME=/usr/local/sdkman/candidates/java/7.0.352-zulu/
> /opt/grails-2.3.11/bin/grails -Dgrails.work.dir=${WORKSPACE}/target/ -Dgrails.env=prod -Dgrails.project.war.file=/var/lib/jenkins/workspace/pipeline-test/target/medhome-prod.${svnRevision}.war war --non-interactive --plain-output --refresh-dependencies
> """
> }
> }
> }
> 
> ```
> 
> }

This is causing issues when the war application runs. Any idea on how to fix this?

Any idea how I could fix this issue?

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [October 31, 2022, 8:11am UTC](https://community.jenkins.io/t/how-to-specify-jdk-version-jenkins-keeps-using-default-java/4335/2 "2022-10-31T08:11:19Z")

</div>

Hello @echujonut and welcome to this community 👋 .

Could you try with moving

```auto
tools {
            jdk 'jdk 'java-7-sdk''
        }

```

to the agent definition?

---

<div class="post-metadata">

**Author:** ![echujonut](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/echujonut/32/2561_2.png) [@echujonut](https://community.jenkins.io/u/echujonut)\
**Post date:** [November 1, 2022, 6:59pm UTC](https://community.jenkins.io/t/how-to-specify-jdk-version-jenkins-keeps-using-default-java/4335/3 "2022-11-01T18:59:03Z")

</div>

Thanks for the help.

I’m not using any agents besides the controller, is that going to be an issue?  
I have this:

> pipeline {  
> agent any {  
> tools {  
> jdk ‘java-8.0.292’  
> }  
> }  
> stages {  
> stage (‘checkout svn’) {  
> …

After running the build, it stills seem that is building the WAR with java-8, any other things I should be looking for?

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [November 2, 2022, 8:22am UTC](https://community.jenkins.io/t/how-to-specify-jdk-version-jenkins-keeps-using-default-java/4335/4 "2022-11-02T08:22:15Z")

</div>

As far as I know, It’s not a good idea to keep an agent on the controller, security-wise.

> **[Managing Nodes](https://www.jenkins.io/doc/book/managing/nodes/)**
>
> Jenkins – an open source automation server which enables developers around the world to reliably build, test, and deploy their software
