James Dunn
James Dunn

Reputation: 8274

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:

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?

Upvotes: 2

Views: 5263

Answers (1)

jedison
jedison

Reputation: 976

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>

Upvotes: 5

Related Questions