Sunday, July 23, 2017

Oracle Linux - Configure Jenkins for Maven

When you are working a lot with Oracle Java and you have the ambition to start developing your Java applications with Maven in a manner that you can automate a lot of the steps by leveraging Jenkins you will have to configure Jenkins. The use of Jenkins in combination with Maven can speed up your continuous integration and continuous deployment models enormously.

I already posted an article on how to install Jenkins on Oracle Linux in another post on this weblog, you can find the original post here. Originally the post was coming from a project where we did not use Maven, we did use Jenkins for some other tasks. However, now the need arises to use Maven as well.

Configuring Maven under Jenkins is relative easy, you can use the "global tool configuration" menu under Jenkins to make the needed configurations. Advisable is to not have Jenkins make the installation however install Maven manually and after that configure it into Maven.

The common error
The common error when configuring Maven is that you tend to define the location of mvn as the maven home the first time you look at this. In our case mvn was located in /usr/bin on our Oracle Linux instance. However, stating /usr/bin as the maven home resulted in the error : /usr/bin doesn’t look like a Maven directory

Finding the maven home
As we just found out that /usr/bin is not the maven home we have to find the correct maven home. The resolution can be found in the mvn --version command as shown below

[root@jenkins /]#
[root@jenkins /]# mvn --version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /usr/share/apache-maven
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-2.b16.el6_9.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.1.12-61.1.33.el6uek.x86_64", arch: "amd64", family: "unix"
[root@jenkins /]#
[root@jenkins /]#

As you can see the Maven home is stated in the output. Providing the Maven home /usr/share/apache-maven to Jenkins will ensure you will have configured maven correctly.

No comments: