Error "Source option 5 is no longer supported. Use 6 or later" on Maven compile - eclipse

I am getting the following error on $ mvn compile:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Sym360: Compilation failure: Compilation failure:
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] -> [Help 1]
Here is the code of 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.app</groupId>
<artifactId>Tset</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Test</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<!-https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-
java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
I tried to add properties in the pom.xml code, but still getting the same error.

What helped me was these lines in pom.xml file
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

I had same issue, the problem is with properties. Check your JavaSE version in your project, it will be displayed beside JRE System Library folder in your project. If it is 1.5, then it will throw an error. Most probably you will have a updated version, so check the version and update it. I have updated it below based on your code.
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>

Also in one of my IntelliJ IDEA projects, in addition to all of answers above, another try works:
Just change Language level in Modules section of Project Structure [image below]

I had same issue and i have added below configuration in pom.xml and it works.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

I think you have wrong your pom.xml:
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
change to:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
Now depending if you are using the command line use:
mvn clean compile
or either way(eclipse ide)
Right click on project Run with maven>build>Goal (compile)

In Eclipse This helped me:
Right Click on Project.
Click on Build path.
Click on Configure Build path.
It opens a Java Build path window.
Click on Java Compiler in the Left side.
It navigates to Java Compiler window in that to set the Compiler compliance level is set as according to your jre version(ex if java version is 1.8
then choose 1.8) as select.
Click on [Apply] button.
Click on [OK] button.
Right click on Project > Maven > Update the project.
Right click on Project > Run As > Maven install -- The pom.xml file is running and java jars are download and installed to project.
Right click on Project > Run As > Maven Test -- The pom.xml file is running and java jars are download and installed to project.
Then you got the Build Success message and your maven project is created successfully.

adding below code in pom will resolve the issue
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<profiles>

I was facing the same issue and resolved it with the lines of code below:
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>

I fixed this by adding this in pom.xml file:
<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>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

For the new Apache net Bean its a little bit different from the suggestion by SUPARNA SOMAN
Right Click on your Project
-Hover on "set configuration" and click customize configuration
-.A new dialogue box opens....
At the left corner where the categories are, Click on "Source"
At the select form on the page below, select your required version of JDK ----see image for this last step.the last step required to change jdk version

On MacOS I have multiple versions
user> ls /Library/Java/JavaVirtualMachines/
jdk-11.0.4.jdk jdk-12.0.2.jdk jdk1.8.0_221.jdk
and JAVA_HOME was not defined properly so Maven used jdk-12. I have jdk-11,jdk-8, and jdk-12.
user> mvn -version
Apache Maven 3.6.1
Maven home: /usr/local/Cellar/maven/3.6.1/libexec
Java version: 12.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
Default locale: XXX, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
So:
Define JAVA_HOME to use jdk-8.
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
Try again, now maven is:
user> mvn -version
Maven home: /usr/local/Cellar/maven/3.6.1/libexec
Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre
and the build is:
[INFO] BUILD SUCCESS

None of the solutions above worked for me.
For some reasons the file with the name of my project.iml had changed. Found the difference in the previous subversion repository submission...
In projectname.iml I found this line:
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_5">
And all I had to do was changing it to 11
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

After so many years, happily seeing the same error ! :P
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
pom.xml did not have any source or target declarations, so maven must have taken some archaic versions as default, rather than being clever enough to get it from the install JVM (which is currently on 18).
So, without knowing the original issue, I could also resolve it through the below snippet below. That declares a specific source and target version, which subpresses the problem.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>18</source>
<target>18</target>
</configuration>
</plugin>
</plugins>
</build>

Some people have asked:
I understand that this works, but I don't understand why maven uses a default source value that it does not support? –
The answer is:
Maven doesn't know what version of the JDK you will use.
When used with JDK 1.8 Maven compiles work successfully.
When using newer versions of the JDK, it's not clear what version of the byte code you want to use. So Maven's has punted and continues use what it has used for many years.
At this day and age, it is difficult for Maven (as a generic build tool) to select a default byte code version that everyone will like.
So it's probably best to get used to putting the version of your source code and the byte code you want to generate in your pom.xml file.
You can argue (and I would agree) that maven should (by default) use a newer version of the maven-compiler-plugin but as I stated, whatever version was picked, someone would have a problem with it.
Example
For example, if you use JDK 11, you might very well be using Java 11 syntax and need -source 11 -target 11 when compiling your code.
Even the most recent release of the plugin maven-compiler-plugin:3.10.1 defaults to JDK 1.7 syntax which would result in compilation errors for Java 11 code.
A full description of the problem
Other's have said this, but to be complete. The default pom.xml doesn't specify the maven-compiler-plugin. To find out the version used you can use
mvn help:effective-pom | more
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
You'll see that the maven-compiler-plugin:3.1 is being used.
You can see that this version generates a command with -target 1.5 -source 1.5 which generates an error when used with versions of Java newer than Java 1.8.
The following shows the error that occurs when using JDK 17.
mvn --version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: D:\p\apache-maven-3.8.6
Java version: 17.0.2, vendor: Oracle Corporation, runtime: D:\p\jdk-17.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
mvn clean install -X
. . .
[DEBUG] -d D:\Play\maven\helloworld\target\classes -classpath D:\Play\maven\helloworld\target\classes; -sourcepath D:\Play\maven\helloworld\src\main\java; -g -nowarn -target 1.5 -source 1.5
. . .
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[INFO] 2 errors
The fix
The fix was to update the maven pom.xml file to specify either a newer maven-compiler-plugin. I tested with maven-compiler-plugin:3.10.1 and it uses -target 1.7 -source 1.7
The syntax is:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
</plugins>
</build>
At the time of this writing version 3.10.1 was the latest version.
The other option is to specify the version of the byte code you want to generate, one way is to use this (as stated in another answer):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
This will work even with the old version 3.1 plugin.

Here is the solution which helped me:
I had the same issue on error source option 5 is no longer supported, Use 6 or later
So i followed these instructions and problem SOLVED
Open Project Properties (File Menu)
Change the Source / Binary Format to the latest version (JDK 7 in my case)
Project Properties
Source / Binary Format
Clean and Build, Then Run the project

This is a message from a newer javac, e.g.:
$ java -version
openjdk version "11" 2018-09-25
$ javac -source 1.5 -target 1.5 Test.java
error: Source option 5 is no longer supported. Use 6 or later.
error: Target option 1.5 is no longer supported. Use 1.6 or later.
So, apparently you're using a newer JDK version with a Maven version prior to 3.8.0 ("<source>/<target> ... NOTE: Since 3.8.0 the default value has changed from 1.5 to 1.6"). The maven-compiler-plugin:3.1 you use is from April 2013.
There are two possibilities:
Update your Maven version to the latest (I'd recommend that)
Setting the Java Version in Maven:
2.2. Java 9 and Beyond
...
<properties>
<maven.compiler.release>...</maven.compiler.release>
</properties>

If in Eclipse, Write click on project and go to properties. Search for maven and configure a jdk higher version (1.7 onwards) there and apply. Now try maven install.

In my case, running MacOS Big Sur and JDK version 15, I added the code below in pom.xml file shown below. I added the 15 for my JDK version.
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
I then re-ran $ mvn clean wildfly:deploy and it worked.

Both options work for me to resolved Source option 5 is no longer supported. Use 6 or later” on Maven compile
Open pom.xml file
Option1: add build tags
Option2: add properties tags
<project>
<groupId>com.pluralsight</groupId>
<artifactId>HelloWorld</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
OR
<project>
<groupId>com.pluralsight</groupId>
<artifactId>HelloWorld</artifactId>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
</project>

I faced the same challenge, what I did was to go to:
File
Project structure
Module
Changed compile SDK to 30 (Latest at the time)
Build tools 30.0.3 (Latest)
Source compatibility (1.8 Java 8)
Target compatibility (1.8 Java 8)

Change the
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
to
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

Set updated java version from build path as per you installed

I solve the problem by finding that my $JAVA_HOME is empty. After setting it, compilation succeeded!

Related

Eclipse - How to add Kotlin to a Tomcat Project - Compile Kotlin AND Java Files

I need help adding Kotlin compiling to an existing eclipse java tomcat project.
For the record I am on Eclipse Oxygen 4.7, and have installed the Kotlin plugin. I have successfully created and ran gradle based spring boot Kotlin rest api demo and can compile and run "Kotlin Only Projects" and use my other java libs - AWESOME.
However now that I have Kotlin I want to use it in work for my other 'legacy' Tomcat 8 projects that are Java J2EE - Dynamic WTP ... new servlets I want to write in Kotlin.
I want to be able to add a Kotlin class in the java src folder in any of my previous packages so when I build a war it all logically together.
The IDE seems ok with this - I created a Kotlin class in a package (in a tomcat project java src package folder) and it have no issues on resolving, imports, or dependency...
I was thinking WOW!, Ok now to restart the Tomcat server in WTP and I'll be able to execute my Kotlin Servlet. No - 404 404 404.
I inspected the WEB-INF/classes build folder and along all the Java class files... guess what I saw?! A file called KotlinServlet.kt ( thats the name of my test servlet, the source version not a compile class version)
So for some reason the build /package/ deployment did not bother to compile the *.kt file and just copied it over (maybe that is the default for general WTP deploy).
I wonder if this would be solved by "Add Kotlin Nature" , the strange part is that none of the eclipse Kotlin menu functions are available to me. If I right click my project I get no Kotlin menu options.
Eclipse states the plugin is installed.
So my question is:
Given an existing conventional WTP Tomcat servlet project, HOW can we get it to identify and a compile *.kt files? How and why do I not have the Kotlin menu functions? (I downloaded and tested both the Oxygen Java and J2EE version - installed the Kotlin plugin - and no menus there either to add a Kotlin Nature. I also then tried the nightly build of the plugin. No menus appeared. Obviously the puglin is installed compiling other Kotlin projects and works in the editor.
From my research - "Add Kotlin Nature" is supposed to do the trick for joint Java / Kotlin compiling but that menu function is not available anywhere???
If this is a "Kotlin Project" eclipse compiles Kotlin fine.
Any Ideas? Seems like an IntelliJ conspiracy.
Thanks,
You need add correspond dependencies. The easiest way to manage project dependencies is to use build tools (maven, gradle, Ant+Ivy...). In maven example you need:
<properties>
<!-- your properties... and define version fir kotlin -->
<kotlin.version>1.1.4</kotlin.version>
</properties>
<dependencies>
<!-- your project dependencies... and add one for kotlin -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- your project plugins... and add one for kotlin -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
</plugins>
</build>
If you use IDE you need to install kotlin language support plugin to make kotlin compile or test run more user friendly.
OK I am narrowing in on this. I found that the kotlin classes are being compiled to this location under runtime lib? Maybe this will be something I can figure to build to my normal classes folder.
OK - To get all the Kotlin menus - turns out you need to be on PACKAGE EXPLORER tab not PROJECT EXPLORER . arggh just found that by fluke.
The creation of a .kt file will automatically add the runtime and libs for Kotlin to your project.
Now on the the issue of the build / compile now. Still outstanding.
OK Update - Downloaded IntelliJ, and "IT" works out of the box, in 15 min I had a Hybrid Java/Kotlin Tomcat Project running.
Still Interested in the Eclipse solution but I am probably just going to shell out the cash for IntelliJ. Time is money.

Maven Exec plugin, ClassLoader ClassNotFoundException

I've tried many suggestions on StackOverflow, and tested with many combinations of setup and pom.xml for 3 days, none of them works. Please help.
I started with a big project with a lot of dependencies, spring-boot, hibernate, etc. Then I create another small console project which import and use some classes from the big project. They are not parent and child project. All I do is add <dependency/> to the child project pom, like this.
P.S. the big project has a <parent/> spring-boot-starter-parent and use spring-boot-maven-plugin.
<dependency>
<groupId>myGroup</groupId>
<artifactId>bigProject</artifactId>
<version>1.0.1</version>
</dependency>
This works on Eclipse with m2e, I just use "Run as" java application and the small project works.
But I need to upload and run those project on my linux VM, which does not use GUI and Eclipse, only terminal.
Then after some reading, I try to use maven exec plugin to run the small project. My steps:
1. do mvn clean install on the big project, confirmed that it appears in my /.m2, local repository.
2. run mvn compile on small project
3. run mvn exec:java on small project
It fails on step 2, those import ... in the class of small project throw package xxx does not exist. maven fail with compilation error.
Then, I try to simplify the problem. I create two test projects with only 1 class, myLib and HelloWorld console application, then I add myLib dependency (pom). HelloWorld project to print a message from the class in myLib package. run step 1 to 3. It works.
public class App
{
public static void main( String[] args )
{
//SystemLog from big project, does not work
//SystemLog log = new SystemLog();
//log.setValue("test value");
//System.out.println(log.getValue());
//CustomMessage from myLib, works fine
CustomMessage cm = new CustomMessage();
cm.setTheMessage("custom message");
System.out.println(cm.getTheMessage() );
System.out.println(CustomMessage.defaultMsg);
}
}
pom.xml of small project
<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>test</groupId>
<artifactId>dependOnOthers</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>dependOnOthers</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>myLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com</groupId>
<artifactId>bigproject</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>test.dependOnOthers.App</mainClass>
<!-- <arguments> <argument>argument1</argument> </arguments> -->
<!-- <arguments> <argument>-classpath</argument> <argument>target/lib/bigproject-1.0.1.jar</argument>
</arguments> -->
</configuration>
</plugin>
</plugins>
</build>
</project>
Then I add a reference to big project, try to print a log message using HelloWorld, it pass step 2, mvn compile, but when I do step 3, mvn exec:java, java.lang.ClassLoader.loadClass() throw ClassNotFoundException on the line where I new an SystemLog() instance, the class defined in big project.
Summarize:
Goal: try to run a console application using Maven exec plugin, which has a dependency on another project, that is installed in local repo /.m2
The SystemLog class is a model class with hibernate annotations.
1. small project depend on big project, fail on mvn compile, package does not exist.
2. HelloWorld depend on myLib, works fine.
3. HelloWorld depend on big project, fail at runtime with ClassNotFoundException.
It's a little late but i ran in the same error, migrating a project from 1.5.3 to 2.1.4
I have found a solution for this problem.
Spring Boot has changed the jar structure in version 2.0.0+, so you don't need to specify your class as <mainClass>test.dependOnOthers.App</mainClass>, you need to point JarLauncher as main entry point.
When the plugin will execute the jar, java will call the main method JarLauncher and several code of spring will be called after that he reads the manifest and call the class definied in Start-Class:. in your case test.dependOnOthers.App.
<configuration>
<!-- Since version 2 of spring, the jar is packed in
another way and has his main method here, don't worry in the MANIFEST file is described which file to boot -->
<mainClass>org.springframework.boot.loader.JarLauncher</mainClass>
The old strucutre of Spring 1.0, was the classical java way todo it, so the java classloader can load it without problems and refer to the class when it is in the classpath, with the version 2.0.0+, they copy user class files and dependency into BOOT-INF, so the java classloader cannot load it anymore, you need to use the Spring classloader to get the class instance.
I have a workaround and know what is causing the problem, but don't know all the details, hope that someone will comment on this, or elaborate the answer.
The thing that cause this problem is spring-boot-maven-plugin, which I use to run spring-boot embedded tomcat server, using mvn spring-boot:run. This plugin seems to change something on the .jar file, maybe the manifest?
The workaround is to remove this plugin, run mvn clean install, that .jar installed in local repository will work correctly. run mvn compile on the small project. Then add the plugin back to big project, run mvn spring-boot:run
I do not know what the plugin changes that result in a .jar with package not exist, does it changes package name?
My workaround is clumsy, if there is a way to choose to compile with or without spring-boot-maven-plugin by defining maven goal, so that I do not need to change the pom for different build (with/without plugin). That would be a better solution.

m2e error in MavenArchiver.getManifest()

I am seeing an error in my STS and am not sure how to debug it. Searching around I only see vague references to the error and no solutions.
The error is:
org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration) pom.xml /<maven projectName> line 1 Maven Configuration Problem
Question: Can anyone give any suggestions on how to get more information on the issue in order to debug it further or any possible solutions?
Maybe some more context on what the functionality of method is. The javadoc associated with the MavenArchiver.getManifest() method is not very detailed and there is no stack trace that I see. I've tried several refreshes and updates of the project and associated projects including clearing my local m2 repo.
STS info:
Version: 3.7.3.RELEASE
Build Id: 201602250940
Platform: Eclipse Mars.2 (4.5.2)
m2e info:
Version: 1.6.2.20150902-0002
I encountered the same issue after updating the maven-jar-plugin to its latest version (at the time of writing), 3.0.2.
Eclipse 4.5.2 started flagging the pom.xml file with the org.apache.maven.archiver.MavenArchiver.getManifest error and a Maven > Update Project.. would not fix it.
Easy solution: downgrade to 2.6 version
Indeed a possible solution is to get back to version 2.6, a further update of the project would then remove any error. However, that's not the ideal scenario and a better solution is possible: update the m2e extensions (Eclipse Maven integration).
Better solution: update Eclipse m2e extensions
From Help > Install New Software.., add a new repository (via the Add.. option), pointing to the following URL:
https://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
Then follow the update wizard as usual. Eclipse would then require a restart. Afterwards, a further Update Project.. on the concerned Maven project would remove any error and your Maven build could then enjoy the benefit of the latest maven-jar-plugin version.
Additonal notes
The reason for this issue is that from version 3.0.0 on, the concerned component, the maven-archiver and the related plexus-archiver has been upgraded to newer versions, breaking internal usages (via reflections) of the m2e integration in Eclipse. The only solution is then to properly update Eclipse, as described above.
Also note: while Eclipse would initially report errors, the Maven build (e.g. from command line) would keep on working perfectly, this issue is only related to the Eclipse-Maven integration, that is, to the IDE.
I found my answer! I looked into the pom for any plugins that have a dependency on the maven-archiver and found the maven-jar-plugin does. It was using the latest 3.0.0 version. When I downgraded to 2.6 it seems to fix the issue :-)
I had the same problem with a spring boot project. the solution was to downgrade the jar maven-jar-plugin from 3.2 to 2.6 . i had just to add this to the project pom:
<properties>
<maven-jar-plugin.version>2.6</maven-jar-plugin.version>
</properties>
I had exactly the same problem. My environment was:
Spring STS 3.7.3.RELEASE
Build Id: 201602250940
Platform: Eclipse Mars.2 (4.5.2)
The symptoms of the problems were:
There was a red error flag on my PM file. and the description of the error was as described in the original question asked here.
There were known compilation problems in the several Java files in the project, but eclipse still was not showing them flagged as error in the editor pane as well as the project explorer tree on the left side.
The solution (described above) about updating the m2e extensions worked for me.
Better solution (my recommondation):
update Eclipse m2e extensions
From Help > Install New Software.., add a new repository (via the Add.. option), pointing to the following URL: https://otto.takari.io/content/sites/m2e.extras/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
Select the m2e extensions, accept the license.
After update, you will be asked for restarting STS. The problem goes away after STS comes back up.
I had the same problem with a spring boot project. The solution was to downgrade the spring-boot-starter-parent dependency version from 2.0.0.RELEASE to 1.5.10.RELEASE(you can move to any stable version)
from:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
to
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I had also faced the same issue and it got resolved by changing the version from 3.2.0 to 2.6 as shown in below pom.xml snippet
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>Spring4MVC</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
Upgrade your m2e extensions instead downgrade.
From Help > Install New Software.., add a new repository (via the Add.. option)
Specify name for your plugin and add path http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
once you are done with installation, please restart eclipse and update your project.
I also faced the similar issues, changing the version from 2.0.0.RELEASE to 1.5.10.RELEASE worked for me, please try it before downgrading the maven version
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
I solved this error in pom.xml by adding the below code
spring-rest-demo
org.apache.maven.plugins
maven-war-plugin
2.6
I had also faced the same issue and it got resolved by commenting the version element in POM.xml as show.
org.apache.maven.archiver.[MavenArchiver](https://maven.apache.org/shared/maven-archiver/apidocs/org/apache/maven/archiver/MavenArchiver.html).getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration)
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- <version>3.5.1</version> -->
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<!-- <version>3.1.0</version> -->
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
Use the steps given in this link. It worked for me.
Step - 1 Right click on your project in Eclipse
Step - 2 Click Properties
Step - 3 Select Maven in the left hand side list.
Step - 4 You will notice "pom.xml" in the Active Maven Profiles text box on the right hand side. Clear it and click Apply.
Step - 5 Run As -> Maven clean -> Maven Install
Hope it helps!

Perforce+Sonar setup for New line code coverage

I am trying to find out code coverage on new lines only. I use jacoco report for IT coverage and run mvn sonar:sonar. Sonar does not display the new line code coverage.
I am not sure what configuration I am missing.It seems to work for svn repo. I run mvn sonar on the base version and again with the latest version.
I am using Perforce,SonarQube 4.4, SCM Activity Plugin 1.8.
Here is my POM.xml,
<scm>
<connection>scm:perforce:username#perforceserver:portnumber://depot</connection>
<developerConnection>scm:perforce:username#perforceserver:portnumber://depot</developerConnection>
<url>scm:perforce:username#perforceserver:portnumber://depot</url>
</scm>
<properties>
<skipTests>false</skipTests>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.itReportPath>C:/SonarData/ExecFiles/CSMmergeddata.exec</sonar.jacoco.itReportPath>
<sonar.scm.reloadBlame>true</sonar.scm.reloadBlame>
<sonar.language>java</sonar.language>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${acme-corporate-pom.sonarVersion}</version>
</plugin>
...
To have code coverage on new line information, SonarQube relies on information from the SCM engine. As you can see on the SCM Activity plugin matrix, Subversion is perfectly supported but not Perforce - which is only known to be tested by some users but not formally validated by SonarQube team as "supported".
So either:
your configuration of the SCM Activity plugin is not correct
See the "Additional configuration for Perforce" section of the documentation of this plugin
or you hit a bug in the implementation of the Maven SCM library (we know there are some bugs)
See all the open bugs on this lib

maven install failed"generics not supported"

I'm using embedded jetty server to build a war, I ran maven clean through eclipse, then maven install. I get a bunch of "not supported" errors
\RoleDao.java:[86,13] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
public List<Role> findAllRoles()
UserAuth.java:[44,1] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
#SuppressWarnings("deprecation")
Anyone have an idea? Thanks
The error message states that you are defining language level of 1.3. This is the default of older versions of the Maven Compiler Plugin like 2.0. Upgrade to a newer version like 2.3.2 or even the latest 2.5.1 and the default will be 1.5 and it should work just fine.
And while you are at it also upgrade to the latest version of Maven (3.0.4) so that these newer versions of the Maven Compiler Plugin are the default.
This is problem with defaults as Manfred pointed. To get rid of this nasty error you can upgrade maven version, maven-compiler-plugin version or configure version in you pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
value from source is then passed to compiler as -source argument, to ind out what values are accepted, check this page javac and search for -source release