如何修复[错误]域= plugin> org.apache.maven.plugins:maven-compiler-plugin:3.x(在Spring Boot上运行) [英] How to fix [Error] realm = plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x (Happened while working on Spring Boot)

查看:98
本文介绍了如何修复[错误]域= plugin> org.apache.maven.plugins:maven-compiler-plugin:3.x(在Spring Boot上运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定获取 spring boot hello word 示例,但存在一个令人讨厌的依赖问题.在答案部分,我解释了解决问题的方法,以及一些有关如何使计算机上的所有内容保持最新状态的提示. 我得到的错误是:

I decided to get spring boot hello word example to work with Java 1.8 but an annoying dependency issues. In the answer section I explain what solved my problem as well as some hints on how to bring everything on your machine up to date. The error I was getting was:

[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/存储库,例如


Solutions that didn't work

A lot of the threads were suggesting removing the ~/.m2/ repositories like here but it did not solve my problem.

有人说这是Java 1.8的结果,它与Java 1.7完美地兼容!但是无法相信他们,因为这没有道理.我真的很想获得这个简单的示例,以使其与Java 8兼容.

Some others said that this is due to the Java 1.8 and it works perfectly for them with Java 1.7! But couldn't believe them as it did not make sense. And I really wanted to get this simple example to work with Java 8.

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

It was a dependency conflict but had nothing to do with the Java version or the repositories under .m2 folder for me.

错误的根源是引起plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x的依赖项冲突.

The source of the error was a dependency conflict that was caused plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x.

关于stackoverflow的其他类似问题,但不能解决我的Spring Boot问题,如下:

Other questions on stackoverflow that are similar but didn't solve my problem with spring boot are as follows:

1- maven-build-error-failed -执行目标缺少类

2- 失败-execute-goal-org-apache-maven-pluginsmaven-compiler-plugin2-3-2comp

3- maven-release -plugin-issue-failed toexecute-goal-org-apache-maven-pluginsmav

4- maven-archetype-problem

推荐答案

解决方案

正如我提到的那样,错误的根源是引起plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x的依赖项冲突. 根据某些情况下通过<properties><java.version>1.8</java.version></properties>指定Java版本的注释,可以解决某些问题(根据此处的指南).

Solution

As I mentioned, the source of the error was a dependency conflict that was caused plugin>org.apache.maven.plugins:maven-compiler-plugin:3.x. Based on the comment made in some cases specifying the Java version through <properties><java.version>1.8</java.version></properties> solves their problem for some (based on the guide here).

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

However in my case (checkout the specs) only specifying the maven compiler plugin and through the following code solved my problem:

<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
  • Maven 3.3.3
  • OS X优胜美地
  • Specs

    • Java 1.8_45
    • Maven 3.3.3
    • OS X Yosemite
    • 基本上,我必须在pom.xml中指定maven-compiler-plugin(见下文).

      Basically I had to specify the maven-compiler-plugin in my pom.xml (see below).

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

      SampleContoroller.java

      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标准结构即可.

      Project folder structure

      Just follow maven standard structure.

      提示,如果这可以解决您的问题或遇到其他问题,请随时在评论中给我反馈.

      Hint Please feel free to give me feedback in the comments if this solved your problem, or if you faced other issues.

      这篇关于如何修复[错误]域= plugin&gt; org.apache.maven.plugins:maven-compiler-plugin:3.x(在Spring Boot上运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆