我正在学习 Selenium,我想尝试将 maven-compiler-plugin 添加到 pom.xml 并重新导入 maven 设置。所以我找到了这个例子来做到这一点http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html并尝试将代码添加到pom中.xml。但示例 3.8.1 中的 vrsion 是红色的,如屏幕截图所示。这是什么意思?它是示例的副本。
这是整个 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>camaj.vladimir</groupId>
<artifactId>selenium-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.tempus-fugit</groupId>
<artifactId>tempus-fugit</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
就我而言,我已将标签从插件更改为依赖项,就像在 Maven 存储库中一样。
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
在我的例子中,插件的 groupId 丢失了:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
...
就我而言,Spring Boot 代码无需更改任何内容即可正常工作,但是,当我尝试在 Git 中提交时,它会给出相同的错误。
为了解决这个问题,我添加了如下版本信息并且成功了。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
...
我在我的旧项目(在我的旧 ItelliJ IDEA 上 100% 工作)和新安装的 ItelliJ IDEA 中遇到过这个问题: 在 pom.xml 中我有这个:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
IDEA 抛出错误 maven-compiler-plugin not find 。我已经添加了
<groupId>org.apache.maven.plugins</groupId>
IDEA 找到了该插件,之后我可以自由地删除 org.apache.maven.plugins 而不会破坏 IDEA
我在使用 IntelliJ 时遇到此错误。尝试了很多方法,以下对我有用:
在 IntelliJ 中,您可以右键单击 3.8.1,向下滚动到 Maven,然后选择“重新导入”。这为我解决了这个问题。
就我而言,使缓存无效并重新启动解决了问题。
我去了
.m2\repository\org\apache\maven\plugins\maven-compiler-plugin
并删除了旧版本。成功了
在您的 pom 中添加以下代码即可解决问题
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
<forkCount>1</forkCount>
<useFile>false</useFile>
<skipTests>false</skipTests>
<testFailureIgnore>true</testFailureIgnore>
<forkMode>once</forkMode>
<suiteXmlFiles>
<suiteXmlFile>testing.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
确保添加插件后重新导入依赖项
您需要更新您的项目,以便从 Maven 端更新依赖项。
更新:
它将下载所有必需的依赖项。
一个原因可能是由于 Maven 设置中系统上的
proxy
设置造成的。
您可以删除/备份以前的 Maven
settings.xml
文件,这应该可以工作。
mv ~/.m2/settings.xml ~/.m2/settings.xml.bak
对我来说,我也突然面临这个问题,我刚刚做了maven clean install。这对我有用!!!