繁体   English   中英

找不到 maven 编译器插件

[英]maven-compiler-plugin not found

我正在学习 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 Repository中一样。

<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>
    ...

在 IntelliJ 中,您可以右键单击 3.8.1 向下滚动到 Maven 并选择“重新导入”。 这为我解决了这个问题。

我的旧项目(100% 在我的旧 ItelliJ IDEA 上工作)和新安装的 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 found。 我已经添加

<groupId>org.apache.maven.plugins</groupId>

并且 IDEA 找到了插件,之后我可以在不破坏 IDEA 的情况下自由删除 o​​rg.apache.maven.plugins

就我而言,使缓存无效并重新启动解决了这个问题。

在您的 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>

确保在添加插件后重新导入依赖项

我在 IntelliJ 中遇到了这个错误。 尝试了很多方法,以下对我有用:

  1. 关闭你的 IDE。
  2. 删除“*.iml”和“.idea”-目录(存在于项目的根文件夹中)
  3. 从命令行运行“mvn clean install”
  4. 将您的项目重新导入 IDEA

您需要更新您的项目,以便从 Maven 端更新依赖项。

更新:

  1. 将文件结构更改为项目视图。
  2. 右键单击项目名称 -> Maven -> 重新加载项目

它将下载所有必要的依赖项。

我去了

.m2\repository\org\apache\maven\plugins\maven-compiler-plugin

并删除了旧版本。 有效

原因之一可能是您系统上 Maven 设置中的proxy设置。

您可以删除/备份以前的 maven settings.xml文件,这应该可以。

mv ~/.m2/settings.xml ~/.m2/settings.xml.bak

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM