简体   繁体   中英

Jenkins Build Maven Project with Java 8 and Java 7

I have 2 applications, Apps A uses Java 8 and Apps B uses Java 7. Furthermore, my company using Jenkins and Java 7.

I need to build Apps A without change the original environment.

Is there any method that I can choose between Java 7 and Java 8 to build an application with Jenkins? or Can I choose java version when maven build?

Thank you

Jenkins can manage multiple versions of the Java JDK which can be selected when creating each build job:

With maven you can specify different build profiles, the profiles can be automatically selected depending on wich JDK you are executing maven targets with. This is an example for that, here activated using jdk 1.4:

<profiles>
    <profile>
        <activation>
            <jdk>1.4</jdk>
        </activation>
        ...
    </profile>
</profiles>

Read more about profiles here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

You can also specify witch buildversion to use with a build plugin like this:

[...]
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.4</source>
      <target>1.4</target>
    </configuration>
  </plugin>
</plugins>
[...]

Read more about source and target versions here: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

By combining these two possible configurations in you pom I think you should be able to set maven to automatically creating the target java version for your liking.

Profiles can use many activation methods to determine what to do so further options are available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM