简体   繁体   中英

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

I know this is a duplicate question but the answers on other topics didn't help me.

I'm using Eclipse Photon, Java Version:10, I've set jdk/jre versions on 10 in eclipse and pom.xml file. I've changed eclipse.ini file:

-Dosgi.requiredJavaVersion=10 (it was set to 1.8)

and also I've added plugin in my pom.xml:

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

Nothing helped. This is my 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>com.luv2code</groupId>
<artifactId>spring-security-demo-06-user-roles</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>spring-security-demo</name>

<properties>

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

<dependencies>

    <!-- Spring Security -->
    <!-- Spring Security WEB -->
    <!-- Spring Security taglibs -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>5.1.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>5.1.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-taglibs</artifactId>
        <version>5.1.1.RELEASE</version>
    </dependency>


    <!-- Spring MVC support -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.1.2.RELEASE</version>
    </dependency>


    <!-- Servlet, JSP and JSTL support -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>javax.servlet.jsp-api</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

</dependencies>


<!-- TO DO: Add support for Maven WAR Plugin -->
<build>
    <finalName>spring-security-demo</finalName>

    <pluginManagement>
        <plugins>
            <plugin>
                <!--  Add Maven coordinates forL maven-war-plugin -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>10</source>
                    <target>10</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

The dependencies aren't being read in class files and also I've tried deleting.m2 repository and starting Eclipse and doing the: Maven->Clean, Maven->install, and than Maven->update project. Nothing helped. I'm really stuck here for about 2-3 hours now.

Note: in Windows->Preferences->installed JRE's the jre10 was marked with the tick. I changed it to mark the jdk10. but still error:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project spring-security-demo-06-user-roles: Compilation failure

Everything was working fine until I added the dependency of: spring-security-taglibs.

Deleting the dependency doesn't do anything aswell.

Check properly settings with version of your project in eclipse and version of your runner for maven.


I have reproduced the same issue with maven-compiler plugin , but using version 3.8.1:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project testName: Fatal error compiling

My POM was:

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

To clarify:

in project I'm using Java 11 and IntelijIDEA (but logic I think the same for eclipse). So I'm using maven lifecycle phases fine only if my version of project (check properly Project Structure -> Project Settings) corresponds to version of maven runner.

在此处输入图片说明

Eg if version of runner is for java 8, but project settings are for Java 11 then I'm getting this error. If I have the same for both then I don't have any problems.


And I highly recommend to check all settings for maven and the whole project. It helps to avoid the issues in the future. Deleting folder for maven is as alternative solution, but it must be last thing that you need to do.

It started working Automagically . FIX : delete .m2 repository.

I did that yesterday but it didn't help, today somehow, deleting the .m2 repository and updating the project helped !

确认,删除 .m2/settings.xml 指向的整个本地存储库,通常是 .m2/repository

I updated my Java SDK to 11.9 and reloaded the project. With this I solved my problem.

I had the same issue, it was because the Spring Boot project was using Java 11 but my %JAVA_HOME% variable was pointing to Java 8 home directory. I resolved the issue by changing the path to %JAVA_HOME% variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM