我有一個類似的問題。
解決方案是在Jenkins的Job-Configuration中設置JDK8,並將JDK7設置爲用於編譯源代碼,測試源代碼和surefire插件。
事情是這樣的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<testSource>1.7</testSource>
<testTarget>1.7</testTarget>
<verbose>true</verbose>
<fork>true</fork>
<executable>C:\java\jdk1.7.0_25\bin\javac</executable>
<compilerVersion>1.7</compilerVersion>
</configuration>
<executions>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<fork>true</fork>
<executable>C:\java\jdk1.7.0_25\bin\javac</executable>
<source>1.5</source>
<target>1.5</target>
<compilerVersion>1.7</compilerVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>C:\java\jdk1.7.0_25\bin\java</jvm>
<forkMode>once</forkMode>
</configuration>
</plugin>
它是否適合你,你可以在路徑的settings.xml中設置爲JDK和你的pom.xml所以每個環境/開發人員可以使用自己的使用環境自己的JDK。
<profile>
<id>jdk7</id>
<properties>
<JDK_1_7_HOME>C:\java\jdk1.7.0_25</JDK_1_7_HOME>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
而且你的pom.xml
...
<executable>${JDK_1_7_HOME}/bin/javac</executable>
...