# Maven Integration plugin

In 
Published 2022-12-03

This tutorial explains to you how to integrate Jenkins with Maven (using Maven Integration plugin).

For doing this we will create the executable jar file for a Spring Boot Maven application in Jenkins.

We need to create a simple Jenkins job first.

When we install for the first time Maven Integration plugin, we need to configure Maven and JDK for Jenkins.

For doing this we need to go to "Dashboard" -> "Manage Jenkins" -> "Global Tool Configuration".

Here we need to configure Maven:

Here we need to configure JDK as well:

The next steps are similar with the ones we have followed in Integrate Jenkins with Maven (without Maven Integration plugin) excepting the fact that we can specify Maven installation (we can have many Maven installations on Jenkins machine):

When we run the job, we will have an output like this:

Started by user admin
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\Job1
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
[Job1] $ cmd.exe /C "C:\MySOFT\maven\apache-maven-3.8.7\bin\mvn.cmd -f D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\pom.xml clean package && exit %%ERRORLEVEL%%"
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.example:rest-demo:jar:v1
[WARNING] The expression ${parent.version} is deprecated. Please use ${project.parent.version} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] -----------------------< com.example:rest-demo >------------------------
[INFO] Building rest-demo v1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ rest-demo ---
[INFO] Deleting D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\target
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ rest-demo ---
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ rest-demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ rest-demo ---
[INFO] skip non existing resourceDirectory D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ rest-demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ rest-demo ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.restdemo.RestDemoApplicationTests
20:55:35.482 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [RestDemoApplicationTests]: using SpringBootContextLoader
20:55:35.486 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.restdemo.RestDemoApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}.
20:55:35.486 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.example.restdemo.RestDemoApplicationTests]: RestDemoApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
20:55:35.507 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using ContextCustomizers for test class [RestDemoApplicationTests]: [ExcludeFilterContextCustomizer, DuplicateJsonObjectContextCustomizer, MockitoContextCustomizer, TestRestTemplateContextCustomizer, DisableObservabilityContextCustomizer, PropertyMappingContextCustomizer, Customizer]
20:55:35.560 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\target\classes\com\example\restdemo\RestDemoApplication.class]
20:55:35.562 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.example.restdemo.RestDemoApplication for test class com.example.restdemo.RestDemoApplicationTests
20:55:35.634 [main] DEBUG org.springframework.test.context.util.TestContextSpringFactoriesUtils - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom TestExecutionListener classes or make the default TestExecutionListener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
20:55:35.635 [main] DEBUG org.springframework.test.context.util.TestContextSpringFactoriesUtils - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom TestExecutionListener classes or make the default TestExecutionListener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
20:55:35.637 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners for test class [RestDemoApplicationTests]: [ServletTestExecutionListener, DirtiesContextBeforeModesTestExecutionListener, ApplicationEventsTestExecutionListener, MockitoTestExecutionListener, DependencyInjectionTestExecutionListener, DirtiesContextTestExecutionListener, EventPublishingTestExecutionListener, ResetMocksTestExecutionListener, RestDocsTestExecutionListener, MockRestServiceServerResetTestExecutionListener, MockMvcPrintOnlyOnFailureTestExecutionListener, WebDriverTestExecutionListener, MockWebServiceServerTestExecutionListener]
20:55:35.638 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: class [RestDemoApplicationTests], class annotated with @DirtiesContext [false] with mode [null]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.1)

2023-01-23T20:55:35.872+02:00  INFO 12688 --- [           main] c.e.restdemo.RestDemoApplicationTests    : Starting RestDemoApplicationTests using Java 19.0.1 with PID 12688 (started by DELL-LAPTOP$ in D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo)
2023-01-23T20:55:35.873+02:00  INFO 12688 --- [           main] c.e.restdemo.RestDemoApplicationTests    : No active profile set, falling back to 1 default profile: "default"
2023-01-23T20:55:36.816+02:00  INFO 12688 --- [           main] c.e.restdemo.RestDemoApplicationTests    : Started RestDemoApplicationTests in 1.15 seconds (process running for 1.842)
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.795 s - in com.example.restdemo.RestDemoApplicationTests
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.3.0:jar (default-jar) @ rest-demo ---
[INFO] Building jar: D:\GitHub-Projects\Projects\Spring-Boot\APIs\SimpleAPI\rest-demo\target\rest-demo-v1.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:3.0.1:repackage (repackage) @ rest-demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.262 s
[INFO] Finished at: 2023-01-23T20:55:38+02:00
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS