Maven Error " annotations are not supported....." - spring

This is one of the most annoying errors ? What I can understand is that I am using a lower version of Java for compiling. How can I specify java version for maven ?
Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile
(default-compile) on project
springAopMavenDemo: Compilation
failure D:\JAVA
Stuffs\projects\springAopMavenDemo\src\main\java\service\EmployeeServiceImpl.java:[13,1]
annotations are not supported in
-source 1.3 (use -source 5 or higher to enable annotations) #Service
-> [Help 1]
To see the full stack trace of the
errors, re-run Maven with the -e
switch. Re-run Maven using the -X
switch to enable full debug logging.
For more information about the errors
and possible solutions, please read
the following articles: [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I really appreciate any help......I am using NetBeans 7.0 and Maven 3

You need to tell maven which version of java the source should be compiled to
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

You are using some annotated code in your java, but compiling in your ide is using source java 1.3 by passing an additional commandline parameter most likely
I had the same thing in intellij a while back
In netbeans config (sorry I am not a netbeans person) find where jdk/compiler setup is and change the command line arg
Update: quick net serach says it may be under Properties > Build > Compiling

emeraldjava answer is correct. However, I want to add two things:
First, you can set the source and target information as Maven properties:
<build>
...
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
Second, if you use the latest version of the Maven compiler plugin (2.3.2 for example), the default version for compiler is 1.5, so you will not need any additional configuration:
The Compiler Plugin is used to compile
the sources of your project. The
default compiler is javac and is used
to compile Java sources. Also note
that at present the default source
setting is 1.5 and the default target
setting is 1.5, independently of the
JDK you run Maven with.
(source)

Related

maven build works on windows but fails on linux

I use the azure pipeline to build the java spring boot app using maven.
when I run the pipeline on a windows machine works fine but when I use a Linux machine gives me error.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project java-app: 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]
[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
how can i slove this problem ?
You have different java versions on Windows, Linux. More recent versions can only downgrade up to 1.6 but not 1.5. so I assume on your Linux is a JDK 11 while on your Windows a JDK 8 or less.
However maven standard is still java 1.5, if you do not override it. Look into the other answer from #khmarbaise.
maven takes Java 1.5 default even if JAVA_HOME is set to JDK11
You have to define a more up-to-date maven-compiler-plugin like this:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
I would suggest to use <release>8</release> depending on your used JDK..Also I would suggest to use the most recent version of Maven

Java 11 Eclipse finds automatic module, Maven does not

I'm attempting to upgrade a 15 year old Maven multimodule project to Java 11, and the module system that was introduced in Java 9. Since the project is built using Maven, all dependencies are pretty clear. First I want to do this using the automatic module names, in order not to also introduce upgraded artifacts (if not absolutely required).
Eclipse is pretty helpful in this process, autocompleting the automatic module names in the module-info.java. For example:
requires dom4j;
But if I compile with Maven, I get errors about that it cannot find the modules Eclipse just autocompleted in there.
module-info.java:[29,18] module not found: dom4j
I am using Maven's compiler plugin 3.7.0 (3.8.0 gives a NullPointerException as per https://jira.apache.org/jira/browse/MCOMPILER-355) I suspect Maven is setting the jars up on the classpath instead of on the modulepath, but the compiler's plugin debug output does not log that.
How can I make Maven correctly handle those modules?
I was running into the same issue. Adding
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
to my pom solved the problem for me...
Maven version 3.9.0 seems to be buggy and will not find the module although the dependency is using an Automatic-Module-Name. Downgrading to version 3.8.1 helps.

Please update sonar-maven-plugin to at least version 2.3

I'm building a project in Jenkins with Sonar Integration.
Everything goes smoothly until the sonar analysis part. I get the following error:
[ERROR] Failed to execute goal
org.codehaus.mojo:sonar-maven-plugin:2.2:sonar (default-cli) on
project project-whatever: Can not execute SonarQube analysis:
Please update sonar-maven-plugin to at least version 2.3 -> [Help 1]
and then the build fails.
I must explain that I have no references to sonar in my project pom.xml. This has been done exclusively with Jenkins configuration.
I'm using the latest available versions both on Jenkins (1.599) and Sonar (5.0). All Jenkins plugins are updated.
Already looked for a way to update the sonar-maven-plugin version, but I canĀ“t find it: either it doesn't exist or I'm not looking at the right places...
Does anyone have any ideia how to work around this?
I was able to fix this issue by going into Manage Jenkins -> Configure System -> Scroll to the SonarQube section -> Click advanced -> fill in "Version of sonar-maven-plugin" with the verison you would like to use.....I used 2.5.
If you can change the root pom.xml, then following should work as well:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
More info in SonarQube docs

Maven - use -source 5 or higher to enable... while building the project

I downloaded one project from our svn and now I am trying to build this using Maven (mvn clean install... my maven is Apache Maven 3.0.4). Unfortunately, when I try to build, the following error occurs. It is strange that it reports something (I think) about Java version 1.3, which of course I dont have installed in my laptop. I have JAVA_HOME setted to JDK 1.7, my javac is also in version 1.7 ...
Please do you know where is the problem?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project irapi: Compilation failure: Compilation failure:
[ERROR] /home/jan/nutch/src/plugin/irapi/src/main/java/cz/cvut/fit/linkedtv/irapi/rest/MediaServer.java:[21,1] error: **annotations are not supported in -source 1.3**
[ERROR]
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/jan/nutch/src/plugin/irapi/src/main/java/cz/cvut/fit/linkedtv/irapi/solr/SolrQueryResponseConvertor.java:[35,26] error: **for-each loops are not supported in -source 1.3**
You must specify the source configuration parameter to the maven-compiler-plugin like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
</configuration>
</plugin>
See also Setting the -source and -target of the Java Compiler in the maven documentation for further details.

Wro4j maven plugin - required class is missing

I'm trying to run wro4j maven plugin according to the documentation
I add the plugin to my pom.xml:
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
and run the goal:
mvn wro4j:run -Dminimize=true -DtargetGroups=all
However the build fails with error:
org.apache.maven.lifecycle.LifecycleExecutionException: Internal error in the pl
ugin manager executing goal 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run': Unable
to load the mojo 'ro.isdc.wro4j:wro4j-maven-plugin:1.5.0:run' in the plugin 'ro
.isdc.wro4j:wro4j-maven-plugin'. A required class is missing: org/codehaus/plexu
s/util/Scanner
Do you know how to avoid this error?
Since wro4j-1.5.0, the maven 3.0 is required to run the plugin. The reason is a feature called incremental build support which depends on a library which is not available on older version of maven by default.
The issue is on your local environment.
Go to this folder on my windows machine:${user.home}/.m2/repository, then delete everything in this folder. (Well you can keep a copy.)
After deleting, run the Maven command:mvn clean install -U.
See: https://groups.google.com/forum/#!topic/wro4j/ZPSFBQ_5lI8

Resources