Jenkins maven release plugin with different jdk - java

I want to perform a maven release that compile java 1.8 code on a Jenkins install that runs on jdk 1.7
I have a project that I compile with java 1.8 using the JDK Parameter Plugin . It works when doing a regular build.
When I do a maven release using the maven release plugin, it forks a JVM with java 1.7 instead of the version specified on the plugin. I guess that it takes the java version in the environment.
If I set JAVA_HOME for that job to 1.8 it works.
I am trying to find a solution where I don't have to override the JAVA_HOME in all my jobs.
I tried to use the solution from a similar post which fixed OP problem by forcing a compiler version:
<properties>
<jee.level>1.8</jee.level>
<jdk.level>1.8</jdk.level>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jee.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
but I end up with:
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.3:compile (default-compile) on project redeem-commons-test: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
any help would be appreciated.

The best solution I found so far is to upgrage the JDK of the container in which jenkins runs and add a JAVA_OPTS to the latter to support the previous JDK version. e.g. -Djava.version=1.7
This way I can build and maven release projects that are java 7 or java 8.

Related

When try to mvn clean install -> an error package does not exist appear

I have been trying to do: mvn clean install on a project which depends on external jar, but got:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile (default-testCompile) on project automation-service: Compilation failure: Compilation failure:
[ERROR] /C:/Checkouts/Release-4.0/test-service-intelligence/service-automation-service/src/test/java/com/company/automation/steps/BasicsSteps.java:[16,53] package com.company.service.automation.databaseaccess does not exist
/C:/Checkouts/Release-4.0/test-service-intelligence/service-automation-service/src/test/java/com/company/automation/steps/BasicsSteps.java:[43,13] cannot find symbol
[ERROR] symbol: class IdentifierIndexRepository
and weirdly this was successfully executed on my colleagues MAC (although he is using completely different IDE, tools and stuff. For example he is using X-Code IDE, ZULU 8 JDK, Maven 3.5). Firstly I though it is a JDK problem and switch the JDK as the same as his: ZULU 8, then I tried his version of Apache Maven and downgraded from 3.6 to 3.5. And finally I switched from Intelij Idea to Eclipse out of desperation -> nothing helps me.
It seems that the missing package is from an external dependency jar which is supplied successfully - I can see it in the External libraries, also there is no signs for unresolved dependencies before trying to mvn clean install (mvn clean compile pass successfully)
the dependency in the POM is declared like that:
<dependency>
<groupId>com.company.da.fid.resolve</groupId>
<artifactId>automation-database-access</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
and maven-compiler-plugin like that:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
The dependency .jar file consists his owns dependencies in him.
Anyone have an idea or clue what possibly could happen to me ?
Thanks in advance.
From the error log it shows that you are missing the dependency com.company.... And it seems to me that it is a custom library you are using. If you have the source code, do clean install of the lib and then on the main project.
This may occur if you have a corrupt package(of the dependency) locally. To check this go to .m2 folder and verify that you have it, if so delete and try to run clean install again.

Run Maven archetype "quickstart" in Java 10?

When I create a new IntelliJ 2018.1 project from the Maven archetype maven-archetype-quickstart version 1.3 using Oracle 10.0.1 on macOS Sierra, I get this error when doing a Maven install.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project h2e2: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test failed.: NullPointerException -> [Help 1]
I am running this directly after creating the new project. I am writing no code. I can run the default line:
public static void main( String[] args ) { System.out.println( "Hello World!" ); }
…by choosing Run 'App.main()' from the context menu clicked in the code editor. That works, but the Maven install fails.
Executing clean and install in the Maven pane of IntelliJ does not solve the problem.
If I switch IntelliJ File > Project Structure > Project > Project SDK > from 10.0.1 to 1.8.0_171 (and set Project language level to 8 - Lambdas, type annotations etc.), then the Maven install succeeds.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
If I return that setting to Java 10, the Maven install fails again, with same error.
I am running external Maven 3.5.3 rather than IntelliJ’s bundled older version, for no particular reason.
My older existing projects based on Java 8 have no problem. My only problem is trying to create new Maven-based quickstart projects using Java 10.
Later version of maven-surefire-plugin
It seems the archetype is not yet updated for Java 10.
According to this blog post: http://joshlong.com/jl/blogPost/java-10.html, you can do the following to get it up and running...
.... I want to use Java 10, though, so I opened the pom.xml file and
changed the java.version property value to be 10. The Maven surefire
plugin broke the build next; it was complaining about not being able
to parse the version of the JDK. I overrode the version by redefining
the property for the plugin's version:
2.21.0.
The important part here is I think updating to the higher version of surefire, as mentioned in the comments. As of 2018-10, the current version is 2.22.1.
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
The Answer by Maarten is correct and crucial.
Set compiler source/target to 10
In addition to that Answer’s solution updating the version maven-surefire-plugin, to run that Maven "Quickstart" archetype based project on Java 10, you will need to change the POM file to indicate Java 10 is to be used by the compiler.
Change this:
<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>
to replace the pair of 1.7 occurrences to 10:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>

How do I update the Maven configuration in Eclipse Luna?

I am using Java 8 for my JRE in Eclipse Luna with with the m2e Maven plugin. I see this warning as soon as I create a Maven project: Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment. I see lots of older advice on this site on how to deal with this error, but nothing related to Java 8. I also that Oracle says J2SE was deprecated in 2008. The most promising answer I have found thus far comes from #Pascal Thivent here:
Warning - Build path specifies execution environment J2SE-1.4
But these instructions no longer seem to be relevant for Luna:
Eclipse project Properties > Maven > Update Project Configuration
I only see "Lifecycle mapping" under Maven.
Can someone please explain (1) what this error means (2) if it is still a worry, given that J2SE-1.5 seems to have been deprecated (3) how to best fix it in Luna?
This error is because the project pom file is instructing maven to compile against java 1.5.
It is best to compile and test to a current java version. In your case java 8.
I am unsure how to fix it inside the eclipse IDE, but the project pom file can be edited to include the compile version as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

Error running YOURPROJECTNAME [compile]: JAVA_HOME environment variable not defined IntelliJ 14 along with Maven

Starting fresh with the new IntelliJ I got this annoying error:
Error running MYARTIFACTNAME [compile]: JAVA_HOME environment variable not defined
It was a very nostalgic and a bit painful. After a bit of thinking I remembered what was missing:
My JAVA_HOME was set as before but somehow maven couldn't find it from within IntelliJ. So the solution was simple, I had to go to Preferences > ... > Maven > Runner and just set the JRE value to my current version of Java home that is 1.8.
My JAVA_HOME was set like before but somehow maven couldn't find it from within IntelliJ. So the solution was simple, I had to go to Preferences > ... > Maven > Runner and just set the JRE value to my current version (1.8) of Java home folder.
Other things to keep in mind is to make sure your target and source are set to the same version of JAVA in your pom.xml:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
I had the same error 7 years later - the solution was the same as in AmirHd's answer.
While we have a project JDK set, we also need to set up a jdk for Maven to use. These could be the same or different.
The Maven JDK is configured in:
Preferences --> Build, Execution Deployment --> Build Tools --> Maven --> Runner --> JRE (drop-down list)
The error goes away once this JDK too is set.

Maven + Delombok issue when compiling in Eclipse

I have a maven project in Eclipse that uses lombok/delombok.
When I build, from Eclipse, using a maven script (e.g. mvn clean package), everything works fine.
However, when I run directly from Eclipse (say with a clean/build of my project), I have a classpath issue concerning a class that should be present in the tools.jar from the JDK. I have tried adding the tools.jar directly in my project build path, without any success.
[Edit]
The stack trace is:
03/07/11 23:39:44 CEST: Maven Builder: FULL_BUILD
03/07/11 23:39:44 CEST: [WARN] The POM for com.google.code.gwt-log:gwt-log:jar:3.1.2 is missing, no dependency information available
03/07/11 23:39:44 CEST: Build errors for fiveorbs; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.projectlombok:maven-lombok-plugin:0.9.3.1:delombok (default) on project fiveorbs: Execution default of goal org.projectlombok:maven-lombok-plugin:0.9.3.1:delombok failed: A required class was missing while executing org.projectlombok:maven-lombok-plugin:0.9.3.1:delombok: com/sun/tools/javac/util/Context
-----------------------------------------------------
realm = plugin>org.projectlombok:maven-lombok-plugin:0.9.3.1
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/Daedin/.m2/repository/org/projectlombok/maven-lombok- plugin/0.9.3.1/maven-lombok-plugin-0.9.3.1.jar
urls[1] = file:/C:/Program%20Files/Java/jdk1.6.0_26/jre/../lib/tools.jar
urls[2] = file:/C:/Users/Daedin/.m2/repository/org/projectlombok/lombok/0.9.3/lombok-0.9.3.jar
urls[3] = file:/C:/Users/Daedin/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[maven.api, parent: null]]
-----------------------------------------------------
[/Edit]
My configuration is as follows:
Eclipse 3.6 Helios
Maven 2.3
JDK 1.6
Lombok 0.9.3
Delombok maven plugin 0.9.3.1
The part of the pom.xml that contains the declaration of the delombok plugin is as follows:
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>maven-lombok-plugin</artifactId>
<version>0.9.3.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.6</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</plugin>
I apologize if this question seems trivial, but I have been looking for an answer for a couple of hours, and I'm starting to get stuck.
Thanks in advance for any hint you may be able to provide - and please let me know if I have omitted any useful information.
You need to make sure Eclipse is launched using a JDK (not a JRE). To be sure, set the path to the executable in eclipse.ini
on *x systems (probably includind MacOS):
-vm /path/to/jdk/bin/javaw
on Win*:
-vm
C:\path to jdk\bin\javaw.exe
(needs to be on separate lines, no quotes - see https://wiki.eclipse.org/Eclipse.ini#-vm_value:_Windows_Example )
To determine which JVM Eclipse launched under, you can use Help->About, Installation Details, Configuration. Then look for the -vm line. If you see multiple -vm lines, or the -vm line points at a JRE instead of a JDK, adjust eclipse.ini then relaunch Eclipse and do a Maven->Update on the project.
I think the problem has been solved in Lombok 0.10.0 or higher
I had a similar issue with delombok when compiling on a Linux VM, when the source was using a mounted Windows share. In my case the problem was solved by moving the repository to another location exclusively on the Linux VM, then recompiling.
Have you configured your Eclipse by executing lombok.jar?
Also Lombok requires javac 1.6 or higher
I had this issue yesterday afternoon. I am using Java 8, Eclipse oxygen, maven 3.5.2.
Solution:
The issue got resolved by removing the Lombok dependency from pom and by adding the Lombok jar in the build path by downloading it separately.
I also edited the eclipse.ini and added the following:
-javaagent:lombok.jar
I downloaded 1.16.18 version of Lombok jar.

Categories