Java version and Maven

Hello community.
Little by little I am taking steps and understanding the logic in how Jenkins works.
I have understood that it is not necessary to connect to a Maven repository that I have, if not, that the best thing is to install Maven, on the same Jenkins server where I will do the compilation.
On the other hand, my Jenkins server defaults to the openjdk version “” 2023-08-24 Java version, but I need to compile my applications with Java 1.8.
So the specific questions are:

  1. Once Maven is installed on the Jenkins server, where should I add the libraries that I currently use with Sonatype?

  2. How do I tell Jenkins to compile with a certain version of Java, which is not the default version on the system?

Thank you.

Good afternoon.
I have seen that just by indicating the pom.xml file in my code it is not necessary to install maven on my Jenkins server… is this possible?

I have already been able to install Java 1.8 and add the installation from tools, but I do not understand why Maven says that it does not support the version, when the project must be compiled in that version.

Which version of maven are you using? Is it by chance Maven 4 which is still alpha?
How are you running your job? Do you use a pipeline?

Thanks for your response, I’m going crazy xdddd
I will detail in a future message what I do step by step.

It’s already solved, thank you very much @mawinter69 .
I have been correcting error by error in each module until all the modules are compiled without errors and the .war files are generated.
The Maven plugin is impressive, since I do not have maven installed on the Jenkins server… on the other hand, what does seem “strange” to me is that on the server I have Java 17 by default, but this application should compile with Java 1.8, it still compiles without errors.

Are you really using the maven plugin? Have you read the warning here: Maven Integration
You might be able to build with java17 and the result is usable with java8 when you have the corresponding java compiler options set. But usually this has the risk that you can use apis from java17 which are not available in java8. And as the units tests run also with java17 you will not notice until you really run the things with java8. And when you use the api only in special situations, you might notice this only late.

This is the Maven plugin I am using, it should be said that I do not have Maven installed on the Jenkins server either.
Even though I also have Java version 1.8 installed, I am not able to tell the job to use that version…


Would it be from here?


Thanks !!!

So you’re using a pipeline job. Can you post the pipeline script or the Jenkinsfile?
The withMaven might auto download a maven version. And will use whatever java it finds in the path probably.

1 Like

No, I am using a project with Maven, which collects all the configuration directly from the pom.xml file in the repository.

I understand that from here, I can tell you to use a specific Java installation, and that if it is installed on the server, I can tell you where to look for it…


I can only recommend not to use this job type. This job type will always use the jvm of the controller or agent, which on recent Jenkins means at least Java 11. You can’t make it compile with java 8 directly, only by configuring the maven compiler plugin to set src and target to 1.8.
I strongly recommend to use Pipeline Maven Integration and configure a maven tool under …/manage/tools and inside the withMaven step you call an sh step where you can also set JAVA_HOME

1 Like

Ok @mawinter69 Thank you very much for the advice… also the “project” does not end here… I have solved the compilation part, but now I am missing the delivery part. I have to configure the part where the war files. The resulting results must be delivered to the tomcats of many machines in production, after clear testing. So in the end, as you say, I will have to use a pipeline.
Thank you very much, if you don’t mind, I would ask you for future questions.
Thank you very much for your help.