当前位置: 首页 > 知识库问答 >
问题:

如何修复[Error]realm=plugin>org。阿帕奇。专家插件:maven编译器插件:3。x(在处理Spring靴时发生)

毛越
2023-03-14

我决定让spring boot hello word示例与Java 1.8一起使用,但存在一个恼人的依赖性问题。在回答部分,我将解释是什么解决了我的问题,以及如何使您的机器上的所有内容更新的一些提示。我得到的错误是:

[ERROR] realm =    plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/xxx/.m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.jar
[ERROR] urls[1] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
[ERROR] urls[2] = file:/Users/xxx/repository/org/apache/maven/shared/maven-shared-utils/0.1/maven-shared-utils-0.1.jar
[ERROR] urls[3] = file:/Users/xxx/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
[ERROR] urls[4] = file:/Users/xxx/.m2/repository/org/apache/maven/shared/maven-shared-incremental/1.1/maven-shared-incremental-1.1.jar
[ERROR] urls[5] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar
[ERROR] urls[6] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-compiler-api/2.2/plexus-compiler-api-2.2.jar
[ERROR] urls[7] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-compiler-manager/2.2/plexus-compiler-manager-2.2.jar
[ERROR] urls[8] = file:/Users/xxx/.m2/repository/org/codehaus/plexus/plexus-compiler-javac/2.2/plexus-compiler-javac-2.2.jar
[ERROR] urls[9] = file:/Users/xxx/.m2/repository/org/apache/xbean/xbean-reflect/3.4/xbean-reflect-3.4.jar
[ERROR] urls[10] = file:/Users/xxx/.m2/repository/log4j/log4j/1.2.12/log4j-1.2.12.jar
[ERROR] urls[11] = file:/Users/xxx/.m2/repository/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar
[ERROR] urls[12] = file:/Users/xxx/.m2/repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar
[ERROR] urls[13] = file:/Users/xxx/.m2/repository/junit/junit/3.8.2/junit-3.8.2.jar

许多线程建议删除像这里这样的~/. m2/存储库,但这并没有解决我的问题。

还有一些人说这是因为Java1.8,它在Java1.7中非常适合他们!但我无法相信他们,因为这毫无意义。我真的很想让这个简单的例子使用Java8。

这是一个依赖冲突,但与Java版本或下的存储库无关。m2文件夹给我。

错误源是由插件引起的依赖冲突

关于stackoverflow的其他问题类似,但没有解决我在spring boot上的问题,如下所示:

1-maven-build-error-failed-to-execute-goal-missing-a-class

2-failed-to-execute-goal-org-apache-maven-pluginsmaven-compiler-plugin2-3-2comp

3-maven发布插件问题无法执行目标组织apache maven pluginsmav

4-maven-原型-问题


共有1个答案

宰父玄天
2023-03-14

正如我提到的,错误的来源是由插件引起的依赖冲突

然而,在我的情况下(检查规格),仅指定maven编译器插件,并通过以下代码解决了我的问题:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
  • Java 1.8_45

基本上,我必须在pom中指定maven编译器插件。xml(见下文)。

<?xml version="1.0" encoding="UTF-8"?>
<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>com.mycompany</groupId>
    <artifactId>helloworld</artifactId>
    <version>0.1.0</version>
    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>
    <build>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
    </build>
</project>
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class SampleController {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SampleController.class, args);
    }
}

只需遵循maven的标准结构。

提示如果这解决了您的问题,或者您面临其他问题,请随时在评论中给我反馈。

 类似资料: