maven build works on windows but fails on linux - maven

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

Related

Failed to execute goal org.apache.maven.plugins - package does not exist

I'm trying to use mvn install, but I keep getting this error
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project example-module-core: Compilation failure: Compilation failure:
[ERROR] /C:/terasoluna-plus/example-module-core/src/main/java/com/mycompany/project/module/util/InitServlet.java:[10,47] package org.springframework.web.context.support does not exist
[ERROR] /C:/terasoluna-plus/example-module-core/src/main/java/com/mycompany/project/module/service/impl/DatabaseServiceImpl.java:[9,50] package org.springframework.transaction.annotation does not exist
[ERROR] /C:/terasoluna-plus/example-module-core/src/main/java/com/mycompany/project/module/service/impl/DatabaseServiceImpl.java:[22,2] cannot find symbol
[ERROR] symbol: class Transactional
[ERROR] /C:/terasoluna-plus/example-module-core/src/main/java/com/mycompany/project/module/service/impl/InitializerServiceImpl.java:[11,50] package org.springframework.transaction.annotation does not exist
[ERROR] /C:/terasoluna-plus/example-module-core/src/main/java/com/mycompany/project/module/service/impl/InitializerServiceImpl.java:[28,2] cannot find symbol
[ERROR] symbol: class Transactional
[ERROR] /C:/terasoluna-plus/example-module-core/src/main/java/com/mycompany/project/example-module-core/src/main/java/com/mycompany/project/module/util/InitServlet.java:[25,11] cannot find symbol
[ERROR] symbol: variable SpringBeanAutowiringSupport
[ERROR] location: class com.mycompany.SIAR.module.util.InitServlet
[ERROR] -> [Help 1]
In my InitServlet.java I have all the imports, and it has no errors. In the pom.xml I have all dependencies needed, but this problem always persists.
All the other solutions tell me to add the dependency and use Maven Update, but it is definitely not missing code/dependencies, because this project is being shared with 2 other users, and it works fine on the other machines. It is the exact same project.
I had this working for a few hours, after countless tries of mvn clean install, one of them got the BUILD SUCCESS and I didn't change anything, and it was working fine. But later, after changing some java files, I used mvn clean install, and got again the same error.
Any ideias of what it might be?
Thanks in advance.
I fixed it. Apparently it really needed 2 more dependencies on a pom.xml that was on another folder. I needed to add to a pom.xml that was in a core folder, these 2 dependencies.
<dependency>
<groupId>org.terasoluna.plus.framework</groupId>
<artifactId>terasoluna-plus-web-conf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
After adding it, I ran mvn clean install, and it installed successfully. Thank you anyway for all your help.
At time when it is working on other systems with exact pom , and not working on mine, I look into differences....
In my local repository - Delete the problematic dependency and run mvn clean install. Whatever dependencies are needed will be downloaded again by maven.
In my maven settings.xml - at the location ${MAVEN_HOME}/conf.What is the difference , did I over-ride any settings?
Difference in JDK version or Maven version.
I hope this helps.
you need to add maven-compiler-plugin into pom.xml. you can find the plugin code below and replace the source version by your jdk version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source> // jdk version
<target>1.8</target> // jdk version
</configuration>
</plugin>

sonar.host.url not working with sonar-maven-plugin:2.7

After upgrading my POMs to sonar-maven-plugin:2.7 the configuration does not work any more. My configuration in settings.xml is like this:
<profile>
<id>sonar</id>
<properties>
<sonar.jdbc.url>jdbc:postgresql://my.server:5432/sonar</sonar.jdbc.url>
<sonar.jdbc.driverClassName>org.postgresql.Driver</sonar.jdbc.driverClassName>
<sonar.jdbc.username>xxxxx</sonar.jdbc.username>
<sonar.jdbc.password>yyyyy</sonar.jdbc.password>
<sonar.host.url>http://my.server</sonar.host.url>
</properties>
</profile>
The build is started with -Psonar of course. With version 2.6 everything is fine, with 2.7 I get
[INFO] --- sonar-maven-plugin:2.7:sonar (default-cli) # myproject ---
[INFO] User cache: C:\Users\me\.sonar\cache
[ERROR] SonarQube server 'http://localhost:9000' can not be reached
...
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar (default-cli) on project myproject: Fail to download libraries from server: java.net.ConnectException: Connection refused: connect -> [Help 1]
Starting the build with -X gives me the correct mojo configuration in both cases, especially the url is still correct in the log
[DEBUG] (f) sonarHostURL = http://my.server
Even deleting the mentioned caching directory does not help.
What can I do except of managing the plugin to version 2.6?
We are investigating the issue. Ticket was created: https://jira.sonarsource.com/browse/MSONAR-129
In the meantime you could either lock the SQ plugin to version 2.6 or pass all properties using command line.
Workaround: Adding -Dsonar.host.url=http://my.server:9000 to mvn command works for me
Better than disabling the plugin, you may fix the plugin version to 2.6, which works fine, taking into account sonar.host.url.
For instance, with Maven in my case:
<pluginManagement>
</plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.6</version>
<!-- sonar.host.url not working with version 2.7 -->
</plugin>
</plugins>
</pluginManagement>
I use the full qualified goal in the CI server to run the sonar goals:
mvn org.codehaus.mojo:sonar-maven-plugin:2.6:sonar
Since we use the templates in TeamCity this is not so much of a disaster. Still we were a bit surprised by the event.
Both
mvn -Dsonar.host.url=http://localhost:9000 org.codehaus.mojo:sonar-maven-plugin:2.6:sonar
and
mvn -Dsonar.host.url=http://localhost:9000 org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar
worked for me :
Instead of reconfiguring all jobs I disabled sonar for all jobs until this gets fixed. I added
<sonar.skip>true</sonar.skip>
to the sonar profile in settings.xml.

How to add weblogic maven dependency?

When I add dependency I get following error :
[ERROR] Plugin com.oracle.weblogic:weblogic-maven-plugin:10.3.6 or one of its dependencies could not be resolved: Failure to find com.oracle.weblogic:weblogic-maven-plugin:jar:10.3.6 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[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] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
I think that you have to define an extra repository in your ~/.m2/settings.xml file, or add an extra proxy repository to your artifact repository (e.g. Nexus).
It seems that getting access to that repository is somewhat involved, so I'll just point you to what would seem to be the right documentation:
https://blogs.oracle.com/WebLogicServer/entry/weblogic_server_and_the_oracle
The error implies that the plugin was not available in the plugin repository.
Please modify your pom to include the plugin as:
<build>
<plugins>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>weblogic-maven-plugin</artifactId>
<version>10.3.4</version>
<configuration>
<adminurl>t3://localhost:7001</adminurl>
<user>weblogic</user>
<password>weblogic123</password>
<upload>true</upload>
<action>deploy</action>
<remote>false</remote>
<verbose>true</verbose>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<name>${project.build.finalName}</name>
</configuration>
</plugin>
</plugins>
</build>
Please change adminurl, user, password accordingly.

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.

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

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)

Resources