Jenkins will not use Java 7 compiler

I’m working with a team on a maven project, and I set up a build job for it in Jenkins.

Recently, someone on the team added code that switches on a String. This caused the build to fail in Jenkins with the following error:

  • Commit with specific date using JGit Eclipse
  • Working with Git and Eclipse
  • How to use GitHub Repo using JitPack.io in Maven
  • git pull - changes from Java
  • how to insert a document to bitbucket using java?
  • Error - trustAnchors parameter must be non-empty
  • error: strings in switch are not supported in -source 1.5
    

    So of course I realized Jenkins needs to be using Java 7, not Java 5.

    First, I remoted into the server, opened a cmd, and did where java and java -version. I checked my environment variables and my path. Everything is pointing to the same Java 7 jdk directory: C:\Java\jdk1.7.0_21.

    Then I checked Jenkins to see if it was configured to use the correct JDK. It is:
    Jenkins JDK

    In fact, that’s the only Java that the Jenkins server is set up to use, and it’s the only Java installed in the Server.

    As a last resort, I installed the JDK parameter plugin into Jenkins. I then set the project to use the Java 7 parameter:

    Parameter JDK

    But still, I get the same error.

    Am I missing something? What could be causing this? Most importantly, how can I solve it and get Jenkins to use -source 1.7 instead of -source 1.5?

  • How to trigger a Jenkins 2.0 Pipeline job from a GitHub pull request
  • Switching branches with IntelliJ & Git
  • use git repo name as ENV variable in jenkins job
  • Updating Jira tickets from Jenkins workflow (jenkinsfile)
  • How do I automatically embed version information into my Java application?
  • CloudBees + PlayFramework + Eclipse
  • One Solution collect form web for “Jenkins will not use Java 7 compiler”

    Check your pom.xml and what java version (for the source) is specified there. That could be where the source 1.5 is coming from.

    <properties>
       <jee.level>1.4</jee.level>
       <jdk.level>1.5</jdk.level>
    </properties>
    
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <configuration>
           <source>${jdk.level}</source>
           <target>${jdk.level}</target>
       </configuration>
    </plugin>
    
    Git Baby is a git and github fan, let's start git clone.