Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile)

廉价感情. 提交于 2019-11-26 23:46:30
Prateek Batla

Deleting full .m2/repository local repository solved my problem.

Or else you need to know what plugins are you using exactly with their dependencies as one of the plugin suffered a problem while downloading.

Lucas Gomes

Deleting full .m2 local repository solved my problem, too.

If you don't know where it is, the locations are:

Unix/Mac OS X – ~/.m2/repository
Windows – C:\Documents and Settings\{your-username}\.m2\repository
Sree Rama

I am adding more points to the solution by @Rushi Shah

mvn clean install -X helps to identify the root cause.

Some of the important phases of Maven build lifecycle are:

clean – the project is clean of all artifacts that came from previous compilations compile – the project is compiled into /target directory of project root install – packaged archive is copied into local maven repository (could in your user's home directory under /.m2) test – unit tests are run package – compiled sources are packaged into archive (JAR by default)

The 1.6 under tag refers to JDK version. We need to ensure that proper jdk version in our dev environment or change the value to 1.7 or 1.5 or whatever if the application can be supported in that JDK version.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

We can find the complete details on Maven build lifecycle in Maven site.

I had the same problem, check the installed jre used by Maven in your Run Configuration...

In your case, I think that the maven-compiler-plugin:jar:2.3.2 needs a jdk1.6

To do this : Run Configuration > YOUR_MAVEN_BUILD > JRE > Alternate JRE

Hope this helps.

Sometimes it is caused due to the project points to JRE rather than JDK.So try this,

1.Right Click on project -->Build Path --> Configure Build Path -->Add Library -->JRE System Library -->Environments--> Installed JREs-->Point to java folder in c: drive (Windows) and select JDK folder and ok.

2.Remove the already present JRE from build path.

Usually, define maven-compiler-plugin is sufficient enough. add the following to your compiler plugin definition.

<plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>              
</plugin>

I had this problem once, and this is how i resolved it:

  • Step-1 Clean your
    .m2/repository

  • Step-2 execute the maven command(for example mvn clean verify) from the terminal at the current project location(where your project's pom.xml file exist) instead of running maven from eclipse.
  • Sometimes this issue comes because the java.version which you have mentioned in POM.xml is not the one installed in your machine.

    <properties>
        <java.version>1.7</java.version>
    </properties>
    

    Ensure you exactly mention the same version in your pom.xml as the jdk and jre version present in your machine.

    Actually, if you do not want to delete your local .m2/repository/... and you are have a downloaded copy of Maven from Apache, you can have Eclipse /STS use that external Maven and you can edit the {maven}\conf\settings.xml to point your localRepository to a new empty location.

    <localRepository>C:\java\repository</localRepository>
    

    Of course, you will have a new repository with all of the maven source downloads in addition to your previous .m2 location.

    venkad

    check the property endorsed.dir tag in your pom.xml.
    I also had this problem and I fixed by modifying the property.

    Example:

    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>  
    
    • Download maven compiler plugin jar from your central repositoy n try
    • If it is still failing check your jdk version, it is because of your application is built on diff jdk version

    For me, restarting Eclipse got rid of this error!

    I think you have Two ways to solve this problem

    01. Set Properties

    • Set Java Build Path as jdk

    Right click project ->Java Build Path ->Select Libraries tab ->Select JRE System Library ->Click Edit button ->Click Installed JREs-> add tick to box ->click Edit ->Click Directory->Select jdk

    • Specifi which kind of jdk version you installed

    Right click project ->Project Facets ->tick java and select java version->Apply ->Ok

    • Update project

    Right-click on "project"->Go to Maven->Update

    02.Delete .m2 file

    If you can't solve your problem using above two topic get this action Close your project. Delete your full .m2 folder

    How to fined .m2 file(windows)

    Go to Local Disk(C) ->Users ->Select your PC name ->.m2 file

    Java 9 incompatible

    I got this error when trying to calling mvn install on a project.

    I had installed Java 9 on macOS as well as Java 8 Update 144. My Maven project was apparently invoking Java 9 and failing. Removed Java 9 from my Mac, leaving just Java 8 in place. Maven is now happily building my project to successful completion.

    Using Apache Maven 3.5.0 on macOS Sierra.

    FreeWong

    Maybe you can add this dependency to your pom.xml. I use this method and solve the problem!

    <dependency> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.3.2</version> 
    </dependency>
    

    for the new users on Mac os , find out .m2 folder and delete it, its on your /Users/.m2 directory.

    you wont get to see .m2 folder in finder(File Explorer), for this user this command to Show Mac hidden files

    $ defaults write com.apple.finder AppleShowAllFiles TRUE

    after this press alt and click on finder-> relaunch, you can see /Users/.m2

    to hide files again, simply use this $ defaults write com.apple.finder AppleShowAllFiles false

    I renamed the .m2 directory, this didn't help yet, so I installed the newest sdk/jdk and restarted eclipse. This worked.

    It seems an SDK was needed and I only had installed a JRE.

    Which is weird, because eclipse worked on the same machine for a different older project.

    I imported a second maven project, and Run/maven install did only complete after restarting eclipse. So maybe just a restart of eclipse was necessary.

    Importing yet another project, and had to do maven install twice before it worked even though I had restarted eclipse.

    It's really incredible to be oblige to erase whole .m2/repository content. I suggest to type this command (On Windows) :

    mvn clean

    mvn -X package > my_log_file.log

    The last command enable Debug option et redirect output to a file. Open the file and search ERROR or WARNING key words. You can find this kind of expression :

    DEBUG] =======================================================================
    [WARNING] The POM for javax.servlet:javax.servlet-api:jar:4.0.0 is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model for javax.servlet:javax.servlet-api:4.0.0
    [FATAL] Non-parseable POM C:\Users\vifie\.m2\repository\net\java\jvnet-parent\3\jvnet-parent-3.pom: processing instruction can not have PITarget with reserved xml name (position: END_TAG seen ...</profiles>\n\n</project>\n\n<?xml ... @160:7)  @ C:\Users\vifie\.m2\repository\net\java\jvnet-parent\3\jvnet-parent-3.pom, line 160, column 7
    
    [WARNING] The POM for org.glassfish:javax.json:jar:1.0.4 is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model for org.glassfish:javax.json:[unknown-version]
    [FATAL] Non-parseable POM C:\Users\vifie\.m2\repository\net\java\jvnet-parent\3\jvnet-parent-3.pom: processing instruction can not have PITarget with reserved xml name (position: END_TAG seen ...</profiles>\n\n</project>\n\n<?xml ... @160:7)  @ C:\Users\vifie\.m2\repository\net\java\jvnet-parent\3\jvnet-parent-3.pom, line 160, column 7
    

    It's esay in this case to understand you have just to delete directory C:\Users\vifie.m2\repository\net\java\jvnet-parent\3

    Relaunch compilation, packaging and so on :

    mvn package

    WARNING disappear just because you delete POM file corrupted at the good location and maven re download it. Normally the new POM file is better.

    Often debug mode give you messages with more comprehensive details.

    Why I redirect log to a file : Simply because on Windows console don't have enough buffer to store all lines and often you cannot see all lines.

    We tried everything listed so far and it still failed. The error also mentioned

    (default-war) on project utilsJava: Error assembling WAR: webxml attribute is required

    The solution that finally fixed it was adding this to POM:

    <failOnMissingWebXml>false</failOnMissingWebXml>
    

    As mentioned here Error assembling WAR - webxml attribute is required

    Our POM now contains this:

    <plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven-war-plugin.version}</version>
    <configuration>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <warName>${project.artifactId}</warName>
    <attachClasses>true</attachClasses>
    </configuration>
    </plugin>  
    

    i had the same problem and besides the above posts' configurations putting

                <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>1.9.32</version>
                <configuration>
                    <enableJarClasses>false</enableJarClasses>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>endpoints_get_discovery_doc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    in the plugins element in pom.xml. i think the problem was absence of execution -> goal "endpoints_get_discovery_doc" in some cases like mine, so this worked for me.

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!