簡體   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