source

Maven 빌드 컴파일 오류 : goal org.apache.maven을 실행하지 못했습니다.플러그인: maven-compiler-plugin: 3.1: 프로젝트 Maven의 컴파일(기본 컴파일)

goodcode 2022. 9. 5. 22:56
반응형

Maven 빌드 컴파일 오류 : goal org.apache.maven을 실행하지 못했습니다.플러그인: maven-compiler-plugin: 3.1: 프로젝트 Maven의 컴파일(기본 컴파일)

나는 git repo에서 maven 프로젝트를 분기하여 복제했다.Java 8을 기반으로 합니다.제가 제일 먼저 하는 일은

mvn clean install

그러나 다음과 같은 실패 메시지가 나타납니다.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven ---
[INFO] Deleting /Users/vshukla/git/Prism/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 66 source files to /Users/vshukla/git/Prism/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/scanUtility.java:[54,52] diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/AppUtility.java:[87,86] diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/ComparisionUtility.java:[58,52] diamond operator is not supported in -source 1.5
  (use -source 7 or higher to enable diamond operator)
[INFO] 3 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.266 s
[INFO] Finished at: 2017-03-01T12:11:27+05:30
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure:
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/scanUtility.java:[54,52] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/AppUtility.java:[87,86] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] /Users/vshukla/git/Prism/src/main/java/PrenPost/ComparisionUtility.java:[58,52] diamond operator is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable diamond operator)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]   http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

단, JRE - 8이 명확하게 설정된 프로젝트의 빌드 경로 세부 사항은 다음과 같습니다.

컴파일 설정:

컴플라이언스 수준

프로젝트를 몇 번을 만들어도 같은 오류가 발생합니다.프로젝트를 청소하고 일식으로부터 새로 고친 후에도 도움이 되지 않습니다.안내 부탁드립니다.

갱신:

maven 컴파일러 플러그인을 설정하는 속성을 추가한 후

<properties>
 <maven.compiler.source>1.8</maven.compiler.source>
 <maven.compiler.target>1.8</maven.compiler.target>
</properties>

,

다음 오류가 발생하였습니다.

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven ---
[INFO] Deleting /Users/vshukla/git/Prism/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 66 source files to /Users/vshukla/git/Prism/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING : 
[INFO] -------------------------------------------------------------
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java uses or overrides a deprecated API.
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Recompile with -Xlint:deprecation for details.
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Some input files use unchecked or unsafe operations.
[WARNING] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java: Recompile with -Xlint:unchecked for details.
[INFO] 4 warnings 
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[26,22] package com.apple.eawt does not exist
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,41] cannot find symbol
  symbol: class Application
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,67] cannot find symbol
  symbol: variable Application
[INFO] 3 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.591 s
[INFO] Finished at: 2017-03-01T13:09:47+05:30
[INFO] Final Memory: 21M/347M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven: Compilation failure: Compilation failure:
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[26,22] package com.apple.eawt does not exist
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,41] cannot find symbol
[ERROR] symbol: class Application
[ERROR] /Users/vshukla/git/Prism/src/main/java/main/MainUITabbed.java:[93,67] cannot find symbol
[ERROR] symbol: variable Application
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

다음은 Main UITabed 클래스의 컴파일 오류를 나타내는 코드 스니펫입니다.

import com.apple.eawt.Application;
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {


                Application application = Application.getApplication(); // line 93

                ImageIcon imgicon = new ImageIcon(getClass().getResource(
                        "ICON.jpg"));
                Image img = imgicon.getImage();


                application.setDockIconImage(img);

                MainUITabbed frame = new MainUITabbed();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();

            }
        }
    });
}

여기서 사용되는 기본 컴파일러용 코드가 아니기 때문에 오류가 발생했습니다.종속성을 선언한 후 루트 요소가 종료되기 전에 이 코드를 유효한 POM에 붙여넣어 사용하는 컴파일러를 변경합니다.필요에 따라 버전을 조정합니다.

<dependencies>
...
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

IDE는 여기서 관련이 없는 것 같아요.결국 당신은 메이븐을 운영하고 있고 메이븐은 다이아몬드 연산자를 컴파일할 수 있는 소스를 가지고 있지 않습니다.따라서 maven-compiler-plugin 자체를 설정해야 합니다.

여기서 읽어보실 수 있습니다.그러나 일반적으로 다음 속성을 추가하려고 합니다.

<properties>
 <maven.compiler.source>1.8</maven.compiler.source>
 <maven.compiler.target>1.8</maven.compiler.target>
</properties>

이제 메이븐에서만 컴파일되는지 알아보겠습니다.

9,Java 이며, "jdk" "11" "9" "10" "Java "/" "1.8 " 를 사용하고 org.projectlombok:lombok패키지의 버전을 1.16.22 또는 1.18.12로 갱신할 수 있습니다.

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.22</version>
        </dependency>

이제 겨우 문제가 해결됐어

다음과 같이 pom.xml에 코드를 추가해야 합니다.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

이것은 가끔 나타나는 짜증나는 오류이며, 다음과 같은 도움이 되는 몇 가지 단계를 적어 둡니다.

이클립스 관점에서 답을 기본 로직으로 기술하는 것은 Intelij에 의한 것이든 명령줄에 의한 것이든 동일합니다.

  1. 프로젝트를 클릭합니다.-> 메이븐 -> 프로젝트 갱신 -> 강제 갱신 선택 -> [확인]을 클릭합니다.
  2. [ Properties tag ]아래에서 다음을 추가합니다.
<maven.compiler.source>1.8</maven.compiler.source> 
<maven.compiler.target>1.8</maven.compiler.target>
  1. 경우에 따라서는 강제 갱신을 시도했을 때, 「Y 패스에서 X 의존관계를 전송하지 못했습니다」, 「해결은 재시도되지 않습니다」, 「bla bla bla」라고 하는 에러가 표시됩니다.

    이 경우 CD를 사용하여 .m2/repository 폴더에 빠르게 수정하고 다음 명령을 실행합니다.

for /r %i in (*.lastUpdated) do del %i

제 경우 OpenJDK 9와의 비호환성이 원인입니다(조사하지 않았습니다).

JDK 9 가 필요 없는 경우는, 일시적으로 머신으로부터 삭제해 주세요.

sudo apt-get remove --purge openjdk-9-jdk openjdk-9-jre 
sudo apt-get remove --purge openjdk-9-jdk-headless openjdk-9-jre-headless

Java 홈 경로가 올바른지 확인합니다.내 경우 java home path가 pom 파일에 잘못되어 있습니다.

  <properties>
        <java.home>/usr/java/jdk1.8.0_45/bin/javac</java.home>
  </properties>




              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.5.1</version>
                <configuration>
                      <verbose>true</verbose>
                      <fork>true</fork>
                      <executable>${java.home}</executable>
                   <compilerVersion>1.8</compilerVersion>
                   <source>1.8</source>
                   <target>1.8</target>
                 </configuration>
             </plugin>

★★★★★★★★★★★★★★★★.
할 수 .
이 명령어를 이클립스에서 실행하는 대신 단말기에서 직접 실행해 보십시오.
$ mvn clean install

다음 사항을 확인합니다.

  • maven이 시스템 경로에 있습니다.
  • 모든 maven 의존관계는 .m2/저장소에서 이용할 수 있다
  • java는 시스템 경로에 있습니다.


할 수 mvn compile터미널에서 프로젝트가 성공했지만 Eclipse에서는 성공하지 못했습니다.Windows > [ Preferences ]> [ Installed JREs ]를 선택합니다.Maven은 JDK를 컴파일하기 위해 JDK를 필요로 하기 때문에 JDK 아래에 있는 JRE를 선택했는지 확인합니다(그림에서 다른2개의 JRE 경로를 체크).

설치된 JRE

나도 같은 문제가 있어서 이걸 바꿨어

<configuration>
    <source>1.7</source>
    <target>1.7</target>
 </configuration>

여기 1.7은 JDK version.it이 해결되었습니다.

java version match로 인해 coming이 되었기 때문에 수정하여 war 파일을 작성할 수 있습니다.그것이 도움이 되기를 바란다

    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>

이것을 pom.xml 파일로 하고 프로젝트를 업데이트하면 문제가 사라집니다.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
</configuration>
</plugin>
  1. "pom.xml" 아래의 pom합니다.<plugin></plugin>.

  2. 프로젝트를 갱신합니다.

  3. 그런 다음 메이븐을 청소하고 메이븐을 설치합니다.

POM이 저장되어 있는 파일 위치로 이동하여 cmd를 엽니다.그런 다음 "mvn --v"를 입력하여 제공된 maven 버전과 Java 런타임을 확인합니다.런타임 속성을 확인하고 "C:\Program Files\Java\jre1.8.0_191" 또는 JRE에 가까운 경우 환경변수로 이동하여 "JAVA_HOME"이라는 새로운 "시스템 변수"를 값 "C:"로 추가합니다.\Program Files\Java\jdk1.8.0_191".

cmd를 다시 열고 프로젝트를 "클린 설치"하십시오.

여기에서는 다른 제안으로는 제 자신의 빌드를 실행할 수 없습니다.다른 버전의 maven-compiler-plugin 3.1, 3.7.0 등을 사용해 보았습니다.

나는 이것을 추가해 일을 해냈다.

<testSourceDirectory>/src/test/java</testSourceDirectory>

이 접근방식은 /src/test/java 디렉토리가 Java 클래스로 간주되기 때문에 /src/test/java와 같은 시간에 컴파일됩니다.그래서 내 예감이 맞았다.

다른 사람들도 그럴 수 있으니까, 그냥 이걸로 해봐.

저도 같은 문제가 있었습니다.솔루션은 JAVA_로 설정되었습니다.환경변수의 HOME.

pom.xml에 다음을 추가함으로써 동작:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
</properties>

SDK 13이나 14도 가지고 있습니다.

<maven.compiler.release>(없음)source&target)

기타 몇 가지 답변이 표시됩니다.<maven.compiler.source>&<maven.compiler.target>두 가지 요소가 모두 단순한 단일 요소로 대체되었습니다.<maven.compiler.release>.

<maven.compiler.release>15</maven.compiler.release>

그래서 다음과 같이 됩니다.

  <!--old-school-->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
  </properties>

…개요:

  <!--modern-->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>15</maven.compiler.release>
  </properties>

소스 타깃 대체품으로 질문 "maven.compiler.release"를 참조하십시오.

파일 -> 프로젝트 구조 -> 프로젝트 -> 프로젝트 SDK 및 프로젝트 언어 수준을 Java 버전 1.8로 전환합니다.

다음은 예를 제시하겠습니다.

여기에 이미지 설명 입력

다음 pom.xml 설정은 빌드를 성공시키고 있으며 프로젝트 빌드 경로 JRE 시스템 라이브러리가 Java8을 가리키고 있는지 확인합니다.

org.maven.maven 입니다.pluginsmaven-displays-displays3.7.0 1.81.8

Jdk 9 및 10 솔루션

<plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <debug>true</debug>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.ow2.asm</groupId>
                    <artifactId>asm</artifactId>
                    <version>6.2</version>
                </dependency>
            </dependencies>
        </plugin>

maven이 JDK 10 또는 9를 가리키고 있는지 확인합니다.mvn - v

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T14:49:05-05:00)
Maven home: C:\devplay\apache-maven-3.5.3\bin\..
Java version: 10.0.1, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-10.0.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

pom.xml에 다음을 추가하고 CTRL+S를 실행하면 자동으로 프로젝트가 구축됩니다.

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.5.1</version> 
    <configuration>
        <source>1.8</source> 
        <target>1.8</target> 
    </configuration> 
</plugin>

[ Run as ]> [ Maven Test ]을 클릭합니다.

이 오류는 반드시 해결될 것입니다.

내 문제는 내가 달리기를 하고 있다는 것이었다.mvn compile상위 프로젝트 대신 하위 프로젝트 디렉토리에서 사용할 수 있습니다.

이 페이지의 모든 답변과 올바른 JDK가 그것인 것 같았습니다.속성을 추가했습니다.

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

JDK 1.8 플러그인은 Redhat의 오픈 JDK를 가리키고 있습니다.

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <fork>true</fork>
            <executable>C:\java\java-1.8.0-openjdk\bin\javac.exe</executable>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>

그리고 달렸다

mvn clean verify

빌드 성공을 거두었습니다.아싸!

편집: 이것이 실제로 차이를 만든 것이라고 생각합니다.https://mkyong.com/eclipse/eclipse-ide-no-compiler-is-provided-in-this-environment-perhaps-you-are-running-on-a-jre-rather-than-a-jdk/

내 경우 JAVA_를 설정합니다.홈은 맞지만 몇 시간 동안 문제가 있었습니다!마지막으로 settings.xml이 .m2 디렉토리에 있고 Java 홈이 설정되어 다른 경로를 가리키고 있다는 것을 알게 되었습니다.다음 명령을 실행하여 maven이 사용하는 Java 경로를 확인했습니다.

mvn clean install -X | grep -i "executable"

그리고 .m2 디렉토리의 settings.xml의 Java 홈 경로를 수정하여 문제를 해결했습니다!

주의: 특정 버전의 Java에 대해 File-> Project Structure setup으로 프로젝트를 설정하고 다른 버전의 Java에 대해 Pom.xml을 설정한 경우 이 오류가 발생합니다.예를 들어 Project Structure에서 Java 8을 실행하고 pom.xml에서 Java 11을 실행합니다.

수작업으로 해결하려고 여러 번 시도했지만 매번 오류가 발생합니다.

마지막으로 이 문제를 해결하도록 메이븐에게 맡겼지만

먼저 메이븐을 깨끗하게 사용하세요.

Right-click on project -> Run as -> Maven Clean

두 번째 사용 Maven 설치,

Right-click on project -> Run as -> Maven Install

세 번째 사용 Maven Update,

Right-click on project -> Maven -> Update Project

Java 11에서는 이 플러그인이 동작합니다.

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>

제, 유, 유, 유를 했기 때문에<packaging>로로 합니다.warjarsnavafx를 합니다.

<packaging>jar</packaging>

언급URL : https://stackoverflow.com/questions/42525139/maven-build-compilation-error-failed-to-execute-goal-org-apache-maven-plugins

반응형