How to appoint specific jdk version for maven to build my project?

前端 未结 3 516
说谎
说谎 2020-12-12 04:33

My problem is: Test cases are green on local, but some are failed on hudson server because of non-supported jdk version. Local is ibm jdk1.6 sr4 windows, but hudson server i

相关标签:
3条回答
  • 2020-12-12 05:01

    You can configure this in your maven-compiler-plugin

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
    

    You can also use profiles -P to set versions based on environments.

    0 讨论(0)
  • 2020-12-12 05:09

    Maven should start with the java specified in JAVA_HOME if you need to use a different version I would use the toolchain plugin to run your build with a specified jdk version. It will require the version be already installed on the server though.

    http://maven.apache.org/guides/mini/guide-using-toolchains.html

    You will need to add the plugin to your pom and add a toolchains.xml file.

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-toolchains-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>toolchain</goal>
                </goals>
          </execution>
        </executions>
        <configuration>
          <toolchains>
            <jdk>
              <version>1.5</version>
              <vendor>sun</vendor>
            </jdk>
          </toolchains>
        </configuration>
      </plugin>
    

    toolchains.xml file added to .m2 folder which specifies the install location for the jdk

    <?xml version="1.0" encoding="UTF8"?>
    <toolchains>
      <toolchain>
         <type>jdk</type>
         <provides>
             <version>1.5</version>
             <vendor>sun</vendor>
             <id>default</id>
         </provides>
         <configuration>
            <jdkHome>/path/to/jdk/1.5</jdkHome>
         </configuration>
      </toolchain>
    
    0 讨论(0)
  • 2020-12-12 05:18

    Are you sure? The Hudson should support switching JDKs, I've done it in Jenkins. In worst case you could specify JAVA_HOME env variable in the Hudson build. It is impossible to change in maven, because maven itself needs JDK to start.

    0 讨论(0)
提交回复
热议问题