Maven build Compilation error: failed to fulfill the goal org.apache.maven.plugins: maven-compiler-plugin: 3.1: compile (by default compilation) in the Maven project

I have a maven project forked and cloned from a git repository to my eclipse. It is built on Java 8. The first thing I do is execute

mvn clean install 

But I get the following error message:

 [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, ie 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, ie 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 

However, the following is detailed information on the project construction path in which JRE-8 is clearly installed: build path

and compilation setup:

Compliance Level

No matter how many times I create a project, I get the same error. Even after cleaning the project and updating it from an eclipse does not help. Please guide.

UPDATE:

After adding properties to install the maven compiler plugin

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

we get the following error:

 [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, ie 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, ie 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 

And here is a piece of code that gives a compilation error from the MainUITabbed class:

 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(); } } }); } 
+19
source share
15 answers

Adding this to POM fixed it for me. Adjust version as needed

 ... </dependencies> <build> <plugins> <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> </plugins> </build> 
+37
source

I do not think the IDE is appropriate here. After all, you are working with Maven, and Maven does not have a source that allows you to compile diamond operators. So, I think you should configure the maven-compiler-plugin itself.

You can read about it here . But in general, try adding the following properties:

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

and see if it compiles now only in Maven.

+12
source

In my case, it was caused by incompatibility with OpenJDK 9 (which I have not investigated yet).

If you do not need JDK 9, the temporary work should be to clean it from your computer:

 sudo apt-get remove --purge openjdk-9-jdk openjdk-9-jre sudo apt-get remove --purge openjdk-9-jdk-headless openjdk-9-jre-headless 
+3
source

I had the same problem and I changed this

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

here 1.7 my version of JDK.it has been resolved.

+2
source

Buddy
If all this is relevant, even then you have this problem, then
try running this command from the terminal directly rather than running from eclipse.
$ mvn clean install

and make sure of this:

  • maven is in the system path
  • all maven avaialble dependencies in `.m2 / repository`
  • java is in the system path


+2
source

because it started due to a mismatch in the Java version, so I fixed it and I can create a war.hope file, it will help someone

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

By doing this in the pom.xml file and after updating the project, the problem disappeared.

 <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. Update the pom.xml file in the <plugin></plugin> section.

  2. Update your project.

  3. Then clean Maven and install Maven.

+1
source

The pom.xml configuration below makes the build successful, and make sure the JRE project system library must point to Java8.

org.apache.maven.pluginsmaven-compiler-plugin3.7.0 1.81.8

+1
source

JDK solution 9 and 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> 

and make sure your maven points 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" 
+1
source

In case you can compile the mvn compile project successfully from the terminal, but not from Eclipse, go to "Window"> "Preferences"> "Installed JREs", make sure you select the JRE under the JDK (check the paths of 2 different JREs on fig.), since Maven needs the JDK to compile, you need to add it.

Installed JREs

+1
source

Go to the location of the file where the POM is stored and open cmd. Then enter "mvn --v" to check the provided version of maven and the Java runtime. Check the runtime attribute and if it is "C: \ Program Files \ Java \ jre1.8.0_191" or even close to the JRE, go to the environment variables and add a new "system variable" named "JAVA_HOME" with the value "C: \ Program Files \ Java \ jdk1.8.0_191 ".

Open cmd again and then "clean install" the project.

+1
source

Make sure the Java home path is correct. in my case, the Java home path is incorrect in the pom file.

  <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> 
+1
source

You should add the code in pom.xml, for example:

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

You should follow this link, this is a video from YouTube, step by step explaining how to change the path to the installed jre (in my case it’s just an example ->) "C: \ Program Files \ Java \ jdk1.8.0_151"; watch the video: video language: deutsh ^^, but you have nothing to worry about. Click here

0
source

I cannot run my own build on other offers here. I even tried different versions of maven-compiler-plugin: 3.1, 3.7.0, etc.

I made it work by adding this:

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

I tried this approach because it seems that the / src / test / java directory is considered a java class, so it compiles at the same time as / src / test / java. So my guesses were true in my case.

Maybe this is also for others, so just try this.

0
source

Source: https://habr.com/ru/post/1015360/


All Articles