Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven

前端 未结 19 1534
说谎
说谎 2020-12-01 01:17

I have a maven project forked and cloned from a git repo onto my eclipse. It is build on Java 8. The first thing i do is perform a

mvn clean install


        
相关标签:
19条回答
  • 2020-12-01 01:42

    I don't think that IDE is relevant here. After all you're running a Maven and Maven doesn't have a source that will allow to compile the diamond operators. So, I think you should configure maven-compiler-plugin itself.

    You can read about this here. But in general try to add the following properties:

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

    and see whether it compiles now in Maven only.

    0 讨论(0)
  • 2020-12-01 01:43

    In case if you are able to compile mvn compile the project successful from terminal but not from Eclipse check out Window > Preferences >Installed JREs, make sure you have selected JRE that is under JDK (check out the paths of 2 different JRE's in pic), as Maven needs JDK to compile you need to add it.

    0 讨论(0)
  • 2020-12-01 01:45

    I am not able to run my own build on the other suggestions here. I even tried different versions of maven-compiler-plugin: 3.1, 3.7.0, etc.

    I made it work adding this:

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

    I tried this approach because it seems like the /src/test/java directory is considered a java class that is why it is compiled the same time as /src/test/java. So my hunch were right in my case.

    Maybe it is to others too, so just try this one.

    0 讨论(0)
  • 2020-12-01 01:45

    Jdk 9 and 10 solution

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

    and make sure your maven is pointing to JDK 10 or 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"
    
    0 讨论(0)
  • 2020-12-01 01:47

    This is an irritating error that pops up once in a while , jotting down some steps which help:

    Writing answer from eclipse perspective as base logic will remain the same whether done by Intellij or command line

    1. Rt click your project -> Maven -> Update project -> Select Force update -> Click OK
    2. Under properties tag , add :
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target>
    
    1. In some instances, you will start seeing error as we tried force update saying , failure to transfer X dependency from Y path , resolutions will not be reattempted , bla bla bla

      In such case quickly fix it by cd to .m2/repository folder and run following command :

    for /r %i in (*.lastUpdated) do del %i
    
    0 讨论(0)
  • 2020-12-01 01:49

    My issues was that I was running mvn compile from a child project directory instead of the parent project.

    0 讨论(0)
提交回复
热议问题