【问题标题】:Unable to compile maven project in jenkins while it is working fine in the eclipse "Source option 6 is no longer supported. Use 7 or later"无法在 jenkins 中编译 Maven 项目,而它在 Eclipse 中工作正常“不再支持源选项 6。使用 7 或更高版本”
【发布时间】:2019-10-28 22:17:15
【问题描述】:

我正在使用 maven 项目进行自动化,当我从 eclipse 执行脚本时,当我尝试从 Jenkins 运行脚本时它工作正常,然后系统显示错误

[错误] 不再支持源选项 6。使用 7 或更高版本。 [错误] 不再支持目标选项 6。使用 7 或更高版本。

JKD : 12 , 窗户:10, 詹金斯: 行家:

我正在使用以下 maven 插件

    [![<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>EventBuizz</groupId>
  <artifactId>EventBuizz</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>


  </properties>
  <dependencies>



  <dependency>
    <groupId>org.apache.maven.shared</groupId>
    <artifactId>maven-dependency-tree</artifactId>
    <version>3.0.1</version>
</dependency>
<!-- Selenium -->
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

        <!-- TestNG -->
        <dependency>                
            <groupId>org.testng</groupId>                               
            <artifactId>testng</artifactId>                             
            <version>6.14.3</version>                               
            <scope>test</scope>                                     
       </dependency>

       <!--JUnit -->

   <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.10</version>
      <scope>test</scope>
    </dependency>

     <!--Maven Plugin -->
    <dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <type>maven-plugin</type>



</dependency>  



</dependencies>



  <build>
  <plugins>

 <!--Maven Plugin -->  
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
    </configuration>
</plugin>

 <!--Maven surfire plugin -->
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <printSummary>true</printSummary>
                <suiteXmlFiles>
                <suiteXmlFile>testng.xml</suiteXmlFile>
            </suiteXmlFiles>
            </configuration>
        </plugin>
</plugins>
  </build>





</project>][1]][1]

【问题讨论】:

    标签: java maven selenium jenkins


    【解决方案1】:

    看来你是 SOL w/java12。

    根据 Oracle Java 文档, https://docs.oracle.com/en/java/javase/12/tools/javac.html

    源发布 指定接受的源代码版本。允许使用以下释放值:

    注意: 从 JDK 9 开始,javac 不再支持小于或等于 5 的 -source 版本设置。如果使用小于或等于 5 的设置,则 javac 命令的行为就像指定了 -source 6 一样

    解决方案: 您可以使用 Java 8 一路回到 Java 1.2: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html

    使用 maven 工具链/配置文件能够动态选择使用哪个: https://maven.apache.org/guides/mini/guide-using-toolchains.html

    https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

    【讨论】:

      【解决方案2】:

      您的构建服务器中的 maven 版本不支持 java 6,并且您正在通过 pom.xml 强制编译为 java 6。根据您的要求,您有两个选择,要么将 pom.xml 更正为更高的 java 版本,要么将 jinkens 指向旧的 maven 版本。

      【讨论】:

        【解决方案3】:

        这些行:

        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        

        无论您使用什么版本的 JDK,您都在强制将项目编译为 Java 6。

        Jenkins 告诉您它不再支持 Java 6。只需将该版本更新到更高版本即可。

        【讨论】:

        • 感谢您的快速回答,我如何在 jenkins 中更新我的 java 版本?
        • 我已经在 porm.xml 中更新了我的 java 版本,但仍然面临同样的问题 1.81.8 maven.compiler.target>
        • 谢谢我通过这个解决了这个问题:1.81.8
        猜你喜欢
        • 2020-09-03
        • 2020-04-28
        • 1970-01-01
        • 2019-04-01
        • 1970-01-01
        • 2021-07-03
        • 1970-01-01
        • 2018-08-08
        相关资源
        最近更新 更多