Maven is the build tool for the language called java. Let say Developer write a code in language called java. The code contains various functions and all those functions and methods are normally a part of some module that we have to import.
Module : some kind of program file written by some developer in the open community and it contains various functions that we can use it.
If we want to use any module or any third party program then we have to install some software which is called as library.
so which library is required its all depend on the program which is required and usually we used to import them and use them some sought of installation of libraries are done by the IDE (integrated developement enviroment)
When we upload the code in github they usually upload the code not libraries because library is third party
In maven os we have only code not any library so if we compile the code then it will not run or let say maven os have libraries the code uses the library version 2.4 due to security purpose but maven have version 2.6 then may we some sought of code may not work properly.
The question is that who will install these libraries and where we get?
so this problem is solved by the Maven like in redhat the libraries are called as software or package so here yum is the one who know where to download the software and how to download it but in case of java we used to do this with the help of maven. Maven know where to install the libraries, which version to download.
Since java is the open source so lots of public resource for the library is maven central where all the libraries are located.
maven central: https://central.sonatype.com/?smo=true
The developer have to tell which software should be installed and version of software and this all things are stored in the filename pom.xml.
so what happen developer send which file? code or pom.xml file
The answer is developer has to send the code as well as pom.xml file which is further sent to the jenkins then in maven.
what maven can do is
--> downloading libraries (pom.xml)
--> compile tests
--> installing dependencies
Thats why maven is the build tool for java.
src >> main >> java >> com >> mycompany >> app
then we see the main file which contain code
$ cat App.java package com.mycompany.app;
/**
Hello world! */ public class App {
private final String message = "Hello World!";
public App() {}
public static void main(String[] args) { System.out.println(new App().getMessage()); }
private final String getMessage() { return message; }
}
also there is test code which also contains lots of libraries
so maven will handle about installation of all the libraries.
and pom.xml file is
three requirements :
slave is connected to master
git should be installed in slave
build tool(maven) should be installed in slave (either manually or using ansible)
this shows that slave is connected to master
this shows that git and build tool maven is installed in slave node
if you want to build manually then you can do using mvn .
but here I can't build manually instead it is done by jenkins for this jenkins should know how to contact github, docker, maven etc for this it require plugins like for github we have to install github plugins , for maven we have install maven plugins.
How can we install plugins?
go to dashboard >> manage jenkins >> system configeration >> plugins
like we have already installed github plugins so if we see that whether it is installed or not
but if we search for maven
this shows that there is no plugins installed for maven
to install maven plugin we have to search under available plugins for maven
we see different types of plugins are available for maven but here "maven integration" plugin is required
so to download it we have to check it then click down arrow on right corner then click install after restart
most of jenkins plugins activate after the jenkins restart
to restart jenkin click on check box of restart jenkins
then create the job for javamaven and put the project url under github project by this direct link of github project came in javamavenjob12
then restrict that this job should run on particular node in my case it is running on slave node then select git and add the repository not to put the key inside it
after the scroll down under build steps column we are able to see " invoke top-level maven targets"
after clicking invoke top level maven target we have to write the goal that what we want to do
under pom section we have to write the file name of pom file with proper path
then click save
when we saw the slave node then there is no job of javamavenjob12 is available but as soon as we build it then all thing is available
It look like we are into jenkins but because this job is run on the slave no 1
slave no 1 is different computer altogether managed by agent, so agent has one more capability what are the workspace that slave node has , it connect the workspace of slave node to master node. It look like that we are in master node but it is coming from the slave.
But there is one issue?
They build on the slave is nice, they create a package on the slave is also nice but storing the package in slave is not nice because this slave is permanent we are not going to delete this node.
Whenever you use any build system launch a new, setup new, use this thing packaging or building after packaging delete the system and next time new build came up then again rebuild the system again.
one of the reason let say maven will download the different different libraries which may conflict
that is the reason we don't wanna a go for permanent and thats is the reason we don't use normal vms or instances instead we use docker as it do the same thing faster and faster.
since in this case slave is permanent but normally the slave is dynamic that is slave is deleted as soon is packaging is completed so the file that is under target (jar file) we have to transfer this from slave node to master node before get deleted
for this we have a option in configure ( post build )
under this there is a option called "Archive the Actions"
this archive will saved in master system
see this time archiving artifacts came in console output (link also came)
when you copy the link address of my-app-1.0-SNAPSHOT.jar then we see the ip of master node.
now lets run the jar file for this we have to edit or configure it
then save and again build
we see the desired output that is Hello World!
after that it would be deleted automatically
I hope you guys enjoys the blog do share and like it
want to connect with me ๐๐๐