1

I need to ensure one thing before doing it, so I have not yet tested the solution I'll propose.

I have a Jenkins on which one project compiles with a JDK 7 with target Java 7. I have a new project written in Java 8, and I'd like to add it to my Jenkinsfor it to build it too.

As a consequence, I need to install a JDK 8 on the machine. I know we can specify the java compiler version in the pom of each project, but I'm fearing this: once I have installed JDK 8, will my Java 7 project still be able to compile with that JDK 8? Should I have the two JDK installed on the machine, and have a configuration for each project to be able to locate its own JDK? Or will my Java 7 project be able to compile in Java 7 using the JDK 8 ?

Thanks for any help.

Rémi Doolaeghe
  • 2,262
  • 3
  • 31
  • 50
  • 2
    JDK should be fully backwards compatible – Dragondraikk Jan 30 '15 at 09:06
  • Is it only compile with JDK8, or beeing able to execute on a Java 7 JVM? In the 1st case this is automatic, in the second, you have some options to set. – pdem Jan 30 '15 at 09:08
  • @pdem This is an integration server, so it just compiles, run tests and deploy on our entreprise repository (nexus) – Rémi Doolaeghe Jan 30 '15 at 09:10
  • 3
    In Jenkins you can set up multiple JDKs and for each project select the decent one – cy3er Jan 30 '15 at 09:10
  • As stated before JDK is backward compatible, but if you want to run with a JRE 7 and not set options you should avoid compiling with a different JDK. You may want to have a lookt to this answer that might help you to set the convenient JDK : http://stackoverflow.com/questions/747878/how-can-i-configure-a-hudson-job-to-use-a-specific-jdk – Christophe Jan 30 '15 at 09:11
  • You can install as many versions as your disk space allows. – Peter Lawrey Jan 30 '15 at 09:52

2 Answers2

3

As stated in comments, it is possible to install multiple JDKs on Jenkins machine (see this answer as an example) and to configure each job to use a specific one.

Besides, you could perfectly compile your Java7 project using Java8 JDK. However, I advise you not to do that. indeed, if backwards compatibility is enforced at language level, you may find some APIs in which bugs you were unaware of, but the libs you use already knew, have been fixed, creating some weird behaviours. As a consequence, your Java7 application would compile using Java8 JDK, but expose bugs at runtime. And it would be the hell of a nightmare to solve those bugs (believe me, my friend, I've met that kind of horrors in a previous common company).

Community
  • 1
  • 1
Riduidel
  • 22,052
  • 14
  • 85
  • 185
0

You can use multiple jdk on your machine, but remember to use specific jdk for specific project. Configure POM file of your project carefully if you have installed multiple jdk. Compiling Source Using Maven

Or you can change JAVA_HOME in the Build Environment section of the job configuration you can set environment variables for the job. Although, you can use multiple JDKs but its not a good practice to in CI/CD. Use specific machines with specific configurations.