Randa ElBehery
Randa ElBehery

Reputation: 167

how to make maven with jenkins use specific jdk?

I have jdk 7 and 8 on my machine, JAVA_HOME points to java 7, and Jenkins uses java 8. I created a maven project and i am trying to build it on jenkins using java 8 but i get the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project maven-demo: Compilation failure -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE

in pom.xml I added the following:

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>

and

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <verbose>true</verbose>
          <fork>true</fork>
           <source>1.8</source>
           <target>1.8</target>
          <executable>path/to/jdk/bin/javac</executable>
        </configuration>
      </plugin>
    </plugins>
</build>

but I still get the same error with either method of the 2 above.

How can I update it to make maven use java 8 ?

Upvotes: 3

Views: 8479

Answers (1)

DrHopfen
DrHopfen

Reputation: 837

You have to configure your Jenkins under Global Tool Configuration with Name and JAVA_HOME of your different jdks. http://path-to-your-jenkins:8080/configureTools/. Afterwards you can choose the JDK within your project configuration http://path-to-your-jenkins:8080/job/yourJob/configure. In the General tab in the field JDK.

Upvotes: 7

Related Questions