Maven : error: generics are not supported in -source 1.3 , I am using 1.6 - maven

I have imported an existing Maven project into Eclipse IDE .
I have modified some code in it , it compiled successfully ,
I am using Java 1.6 as compiler
and when i am trying to run maven clean install -X
Its giving the following error
could not parse error message: (use -source 5 or higher to enable generics)
D:\bayer\util\src\main\java\com\tata\bayer\util\BrokerageCalendar.java:179: error: generics are not supported in -source 1.3
private static Hashtable<String, Boolean> nyseHolidays = new Hashtable<String, Boolean>();
^
could not parse error message: (use -source 5 or higher to enable generics)
D:\bayer\util\src\main\java\com\tata\bayer\util\APIHttpXmlClient.java:27: error: generics are not supported in -source 1.3
Class<? extends APIResponse> responseClass) {
^
Please suggest any ideas as how to resolve this ??

Did you declare that you want to use java 1.6 in your project pom.xml?:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument></compilerArgument>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Configuring the Maven Compiler Plugin will fix the problem. It turns out the problem was caused by the Maven3 package in the Ubuntu repository. An alternate fix is to download Maven 3 from the Apache website which uses a more up to date Compiler plugin.
I wanted to know why this was happening when the documentation states the default Java source is 1.5. To see what mvn is using for your compiler plugin use:
mvn help:effective-pom
My Maven Compiler Plugin was 2.0.2 even though I was using Maven 3.0.4 from the Ubuntu packages.
When I run the same command using Maven 3.0.4 from Apache I have a plugin version 2.3.2, which defaults to Java 1.5 as expected.

You have to configure the Maven Compiler Plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

Another way that doesn't involve modifying the pom is to specify the source and target in the command line:
mvn clean install -Dmaven.compiler.source=1.6 -Dmaven.compiler.target=1.6
Note that this should be avoided generally as the build cannot be guaranteed to be repeatable this way.

I'd prefer this:
<properties>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
...

Related

Old version of checkstyle detected. Consider updating to >= v8.30

Small question regarding a SonarQube + Checkstyle warning please.
Currently, in my app, in my pom, I use the following Checkstyle plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<outputFile>.out/reports/checkstyle/checkstyle-result.xml</outputFile>
<outputDirectory>target/reports/checkstyle</outputDirectory>
<outputFileFormat>xml</outputFileFormat>
</configuration>
</plugin>
This plugin is doing its job, no worries there.
When I run SonarQube though, I get this warning
Old version of checkstyle detected. Consider updating to >= v8.30
For more information see: https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
I obviously went to read the website, but I am still having hard time understanding.
The Checkstyle plugin I have is the latest known, version 3.1.2, checked on Maven central etc.
In SonarQube, I am running on the latest version, 8.9 LTS, with the latest version of Checkstyle plugin as well.
What am I missing please? Am I using some kind of wrong plugin?
It is a SonarQube plugin named sonar-checkstyle which needs to be installed or upgraded at the SonarQube server instance. The current version is 8.40.
Note: Refer to
https://docs.sonarqube.org/latest/setup/install-plugin/
https://docs.sonarqube.org/latest/instance-administration/plugin-version-matrix/
https://github.com/checkstyle/sonar-checkstyle
https://github.com/checkstyle/sonar-checkstyle/releases
Edit 1
Step 1
Firstly, there is a cache directory at <user_home>/.sonar/cache (for me on the Windows 10 is C:\Users\<myuser>\.sonar\cache), please delete all sub directories under this cache directory with purpose to let the org.sonarsource.scanner.maven:sonar-maven-plugin latest version download it from our SonarQube server instance and ensure that all related plugins are new and fresh after upgrading/installing at the SonarQube server instance. (Do not forget to restart it after finishing upgrading/installing to ensure all new are re-loaded)
Step 2
Secondly, make sure that we do not specify the org.sonarsource.scanner.maven:sonar-maven-plugin in our project pom.xml neither at the parent nor anywhere else with purpose to ensure that during executing, it will be a latest version which matches to our SonarQube server instance version.
Anyhow the formal document (https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/) also mentions about How to Fix Version of Maven Plugin as the following: -
How to Fix Version of Maven Plugin
It is recommended to lock down versions of Maven plugins:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>
<!--Version that matched with our Sonar server instance version -->
</version>
</plugin>
</plugins>
</pluginManagement>
</build>
The latest version is able to be browsed at https://search.maven.org/artifact/org.codehaus.mojo/sonar-maven-plugin or https://search.maven.org/artifact/org.sonarsource.scanner.maven/sonar-maven-plugin The latest is version 3.9.0.2155 (Note: the version ?.y.z is matched with our Sonar server instance version)
Step 3
Last but not least, if our project is a multi-module projects there is a mentioned at the formal document (https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/) as the following: -
In some situations you may want to run the sonar:sonar goal as a
dedicated step. Be sure to use install as first step for multi-module
projects
mvn clean install
mvn sonar:sonar ...
Then there will be 2 steps here, mvn clean install first so that it is completed and then mvn sonar:sonar ... later on.
Edit 2
The maven-checkstyle-plugin is also able to specify the checkstyle version as mentioned at https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html with the significant sentence as
Maven Checkstyle plugin comes with a default Checkstyle version: for
maven-checkstyle-plugin 3.1.2, Checkstyle 8.29 is used by default.
Then the configuration for the maven-checkstyle-plugin will be like the following: -
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>...choose your version...</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
<build>
...
</project>
The latest version is able to be browsed at https://search.maven.org/artifact/com.puppycrawl.tools/checkstyle The latest is version 8.42.

pull apache beam from github compile error

I am new to Apache beam, I download latest source code from github and compile runner module under path :
../beam/runners
with command : mvn package and it prints the exception like this :
enter image description here
Apache Beam :: Runners :: Core Construction Java ... FAILURE
Does anyone have some ideas with this ? thanks!
#Balajee Venkatesh
Here are my compile steps:
cd beam-master
mvn compile
wait compile finish
The first time I execute mvn compile command and met the exception shown above was under path beam-master/runners. After I changing compiling path to beam-master everything goes well .
And may I ask are you trying to compile the whole project to load it to your IDE ?
If so , I suggest using IDEA with 'File'->'import from existing source' instead of executing 'mvn compile' command .
If you try to use IDEA import beam , you can just remove/comment error messages in ${project_loc:beam-parent/pom.xml} like :
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.3</version>
<reportSets>
<reportSet>
<reports>
<report>dependency-updates-report</report>
<report>plugin-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>-->
and, replace this maven plugins version the same as your mvn -version .
<!-- Rename the artifact produced by the Apache parent's
source release. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>**3.3.3**</version>
<executions>
<execution>
<id>source-release-assembly</id>
<configuration>
<finalName>apache-beam-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
By the way , my maven version is 3.3.3 . You can also check out if the pom.xml's maven version incompatible with your local mvn -version .
Here is my mvn compile path :
enter image description here
After I changing my compiling path to main path every module compiled success.

Sonarqube-Analysis on Jenkins fails due to PMD Plugin throwing UnsupportedClassVersionError: Unsupported major.minor version 52.0

Java-Version Configuration
Java-Version used for compiling classes with ant: 1.8
pom.xml für Sonarqube-Analysis defines:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
and
<!-- Set the sonar.java.source property to tell PMD which version of Java your source code complies to. The default value is 1.5. -->
<sonar.java.source>1.8</sonar.java.source>
Sonarqube-Version: 4.5.4
Sonarqube-PMD-Plugin-Version: 2.4.1
JDK configured in Jenkins-Job: 1.8
Sonarqube-Server runs using Java 8
There is only Java8 installed on both Jenkins- and Sonarqube-Server.
Jenkins executes the following maven-comand to start the analysis:
mvn.bat -f "D:\Jenkins\workspace\DVLP MW2.0 Coverage und Codeanalyse\sonar-pom.xml" -e -B sonar:sonar -Dsonar.jdbc.driver=com.mysql.jdbc.Driver "-Dsonar.jdbc.url=jdbc:mysql://192.168.58.121:3306/sonar?autoReconnect=true&useUnicode=true&characterEncoding=utf8" -Dsonar.host.url=http://192.168.58.121/sonar
What are we missing?
You should remove property sonar.java.source. SonarQube gets Java Class Version from maven-compiler-plugin configuration. It is not a problem if you compile with JDK7 and run analysis with JDK8 (or do both actions with JDK7/JDK8).

Maven/Jenkins java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0

I have a Jenkins server having JDK & JRE 6 and 7 installed together.
All of the projects are built on 1.6 except one which is 1.7 dependent.
I've configured the maven pom file to use the Java compiler from the JAVA_HOME_7 environment PATH.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
**<executable>${env.JAVA_HOME_7}/bin/javac</executable>**
<fork>true</fork>
<verbose>false</verbose>
</configuration>
</plugin>
During mvn install I'm getting the following error:
java.lang.RuntimeException: There was an error in the forked process
java.lang.UnsupportedClassVersionError: : Unsupported major.minor version 51.0
which I think means that the server is using JRE 1.6.
How to keep the JRE 1.6 together with 1.7 in order to keep the compatibility with the old 1.6 projects and the new 1.7 one?
Many Thanks,
Atanas
You will need to run surefire tests with java 7 too. By default surefire will use same jvm as that running maven - Java6 in your case.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
...
<jvm>${env.JAVA_HOME_7}/bin/java</jvm>
</configuration>
</plugin>
</plugins>
I remember I also struggled to this problem. Follow below steps to resolve the problem
Cause: when multiple JRE is installed then multiple java.exe is also installed to many location of system.
Solution: Modify your environment PATH variable and change the order of java.exe. put location of java.exe on first position like below code
PATH = C:\Program Files\Java\jdk1.6.0\; other;other;other
Change above location according to your use and installation location.
I have encountered this problem more than once, it is because you have more than one versions of jdk(jre) on your system, so just set the JAVA_HOME to the proper jdk you compile your project with and the running would be fine.
Have a look at your target/lib directory, you might have two versions of same jar. For me it was creating the pro

Maven Compiler Plugin Fork Option Not Working

I have a maven pom file with the following compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<executable>${path_to_JDK6}</executable>
<fork>true</fork>
<compilerVerison>1.6</compilerVerison>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
My system's JAVA_HOME is set to a 1.5 JDK. When I run mvn package, maven throws the following error message:
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6
Usage: javac <options> <source files>
Does anyone have any ideas about why Maven is using the 1.5 JDK instead of forking to the 1.6 executable? Is there any debugging option that I could use? Are the fork and executable options broken in Maven 2?
Note: My system admin would not allow me to change the value of JAVA_HOME and some of my new libraries are written for java 6. So I would like to find a workaround to make maven compile with JDK 1.6.
My ${path_to_JDK6} variable only included the path to the folder containing the JDK. It did not include the /bin/javac. When I added /bin/javac, the 1.6 compiler was invoked.

Resources