SUP*_*MAN 5 eclipse testing testng maven
我收到以下错误或$ mvn编译:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Sym360: Compilation failure: Compilation failure:
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
这是我的pom.xml的代码:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>Tset</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-
java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我试图在pom.xml代码中添加属性,但仍然遇到相同的错误。有人可以帮我解决这个问题吗?提前致谢
小智 98
帮助我的是 pom.xml 文件中的这些行
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
小智 30
我有同样的问题,问题出在属性上。检查您项目中的 JavaSE 版本,它将显示在您项目中的 JRE System Library 文件夹旁边。如果是 1.5,那么它会抛出一个错误。很可能你会有一个更新的版本,所以检查版本并更新它。我已经根据您的代码在下面更新了它。
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
小智 14
我认为你的 pom.xml 错了:
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
改成:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
现在取决于您是否使用命令行使用:
mvn 干净编译
或者任何一种方式(eclipse ide)
右键单击项目 Run with maven>build>Goal(编译)
小智 13
在pom中添加以下代码即可解决问题
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<profiles>
Run Code Online (Sandbox Code Playgroud)
小智 11
我有同样的问题,我在 pom.xml 中添加了以下配置并且它有效。
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
SUP*_*MAN 10
这帮助了我:
然后您会收到 Build Success 消息,并且您的 Maven 项目已成功创建。
有人问:
\n\n\n我明白这是可行的,但我不明白为什么 maven 使用它不支持的默认源值?\xe2\x80\x93
\n
答案是:
\nMaven 不知道您将使用哪个版本的 JDK。
\n当与 JDK 1.8 一起使用时,Maven 编译工作成功。
\n当使用较新版本的 JDK 时,不清楚要使用哪个版本的字节码。因此,Maven 已经放弃并继续使用它多年来使用的东西。
\n在当今时代,Maven(作为通用构建工具)很难选择每个人都会喜欢的默认字节码版本。
\n因此,最好习惯将源代码的版本和要生成的字节代码放在 pom.xml 文件中。
\n你可以争论(我同意)maven 应该(默认情况下)使用更新版本,maven-compiler-plugin
但正如我所说,无论选择什么版本,都会有人遇到问题。
例如,如果您使用 JDK 11,则-source 11 -target 11
在编译代码时很可能会使用 Java 11 语法和需要。
即使该插件的最新版本也maven-compiler-plugin:3.10.1
默认使用 JDK 1.7 语法,这会导致 Java 11 代码出现编译错误。
其他人也这么说过,但要完整。默认的pom.xml没有指定maven-compiler-plugin。要找出所使用的版本,您可以使用
\nmvn help:effective-pom | more\n <plugin>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.1</version>\n
Run Code Online (Sandbox Code Playgroud)\n您将看到正在maven-compiler-plugin:3.1
使用。\n您可以看到此版本生成一个命令,-target 1.5 -source 1.5
当与高于 Java 1.8 的 Java 版本一起使用时,该命令会生成错误。
下面显示了使用JDK 17时出现的错误。
\nmvn --version\nApache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)\nMaven home: D:\\p\\apache-maven-3.8.6\nJava version: 17.0.2, vendor: Oracle Corporation, runtime: D:\\p\\jdk-17.0.2\nDefault locale: en_US, platform encoding: Cp1252\nOS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"\n\nmvn clean install -X\n. . .\n[DEBUG] -d D:\\Play\\maven\\helloworld\\target\\classes -classpath D:\\Play\\maven\\helloworld\\target\\classes; -sourcepath D:\\Play\\maven\\helloworld\\src\\main\\java; -g -nowarn -target 1.5 -source 1.5\n. . .\n[ERROR] COMPILATION ERROR :\n[INFO] -------------------------------------------------------------\n[ERROR] Source option 5 is no longer supported. Use 7 or later.\n[ERROR] Target option 5 is no longer supported. Use 7 or later.\n[INFO] 2 errors\n
Run Code Online (Sandbox Code Playgroud)\n修复方法是更新 maven pom.xml 文件以指定较新的maven-compiler-plugin
. 我测试过maven-compiler-plugin:3.10.1
并且它使用-target 1.7 -source 1.7
语法是:
\n <build>\n <plugins>\n <plugin>\n <groupId>org.apache.maven.plugins</groupId>\n <artifactId>maven-compiler-plugin</artifactId>\n <version>3.10.1</version>\n </plugin>\n </plugins>\n </build>\n
Run Code Online (Sandbox Code Playgroud)\n在撰写本文时,版本3.10.1
是最新版本。
另一种选择是指定要生成的字节码的版本,一种方法是使用它(如另一个答案中所述):
\n<properties>\n <maven.compiler.source>1.8</maven.compiler.source>\n <maven.compiler.target>1.8</maven.compiler.target>\n</properties>\n
Run Code Online (Sandbox Code Playgroud)\n即使使用旧版本 3.1 插件,这也可以工作。
\npom.xml
文件中添加以下内容来修复此问题:<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,并用下面的代码行解决了它:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9372 次 |
最近记录: |