Build Multi Module project with Maven in Jenkins - maven

we're using jenkins and i'm wondering if it's possible to build all my modules using maven in 1 Job, our project structure is like this:
Web
├── Server
│ ├── moduleA
│ │ └── pom.xml <--- Module A POM
│ ├── moduleB
│ │ └── pom.xml <--- Module B POM
│ └── moduleC
│ └── pom.xml <--- Module C POM
│
|── Client
├── Pom.xml
The way we're working now is that we have a jenkins job for every module in Server and 1 jenkins job for client Side , is it possible to create only one job and build All the Client and Server modules ?

you can create a parent pom that will contain all modules , than Jenkins will build this parent pom.
another option is to trigger several MVN commands ( but the first option is much better)

Related

Why are deployment JARs packaged in production Quarkus app?

A vulnerability scan highlighted the presence of Maven JARs in the Docker image for our Quarkus app which surprised me. These are being picked up from quarkus-app/lib/main. Running mvn quarkus:dependency-tree shows the route by which they're getting included:
[INFO] --- quarkus-maven-plugin:2.2.3.Final:dependency-tree (default-cli) # my-app ---
[INFO] Quarkus application PROD mode build dependency tree:
[INFO] my-group:my-app:pom:1.x-SNAPSHOT
...
[INFO] ├─ io.quarkus:quarkus-undertow-deployment:jar:2.2.3.Final (compile)
...
[INFO] │ ├─ io.quarkus:quarkus-core-deployment:jar:2.2.3.Final (compile)
...
[INFO] │ │ ├─ io.quarkus:quarkus-bootstrap-core:jar:2.2.3.Final (compile)
...
[INFO] │ │ │ ├─ io.quarkus:quarkus-bootstrap-maven-resolver:jar:2.2.3.Final (compile)
[INFO] │ │ │ │ ├─ org.apache.maven:maven-embedder:jar:3.8.1 (compile)
Again, I was surprised to see that it was pulling in deployment JARs as, based on my limited understanding, I would have not expected these to be needed at runtime for a non-mutable production app.
EDIT: The POM just references the extension and then there is a parent POM that references the Quarkus BOM.
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow</artifactId>
</dependency>
If the deployment JARs are needed, why, and, if not, is there a way to exclude them?
As #Ladicek suggested, the cause of this issue was that one of dependencies was referencing the deployment artifact directly (just not the one I posted in the question!). This was then causing the deployment JARs for all of the extensions to be packaged in quarkus-app/lib/main.
Correcting quarkus-logging-json-deployment to quarkus-logging-json fixed the problem.

Maven with IntelliJ - Failing building process because dependencies can't be resolved

First of all, I'm entirely new to Maven.
I've imported a big complex maven project to IntelliJ. It contains multiple pom.xml, and it also depends on another local project (that I've already imported and works well).
The import process went well; on IntelliJ, nothing is red underlined. It seems to find every dependency (whether local or not). However when I try to build the .jar of one of the project via the Maven menu:
I get this output:
/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/bastiannanchen/Programmation/Backend/backend/Reconfigure "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=62186:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2018.3.4 compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Reconfigure 3.3.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for <local_project> is missing, no dependency information available
[...]
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.276 s
[INFO] Finished at: 2019-02-12T11:08:44+01:00
[INFO] Final Memory: 10M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Reconfigure: Could not resolve dependencies for project <project_name> The following artifacts could not be resolved: <local_project> [...]
[...]
Do you know how to resolve this problem? I suppose I'm not proceeding correctly with the building process, but I am having a hard time to find an answer on the internet.
Thanks!
UPDATE
The structure of the project in summary:
├── backend
│ ├── project_1
│ ├── project_2
│ ├── project_3
│ └── project_4
└── utils
├── project_utils_1
├── project_utils_2
└── project_utils_3
I'm trying to build, e.g., the project_2 that has dependencies with all the projects in backend and some projects in utils.
I finally find a way to build the .jar file. Before building the package, I needed to use the Maven install plugin for the dependencies. FYI The Install Plugin is used during the install phase to add artifact(s) to the local repository.
Thank you to everybody that tried to help me :)

Sonar: 0 files indexed in one project, properly scanned in another

I have 2 Jenkins shared libraries which contain groovy files to be scanned. Both projects are using the same sonarqube call using maven but in one project the groovy files are scanned, whereas in the other they are not
Sonarqube call
...
String scanCmd = "mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar " +
"-f pom.xml " +
"-Dsonar.branch=%GIT_BRANCH% " +
"-Dsonar.test.inclusions=**/*Test*/** " +
"-Dsonar.exclusions=**/*Test*/** " +
"-Dsonar.skipDesign=true "
bat scanCmd
...
We are using version 5.6.6, if that matters
Sonar scanner config
The sonar configuration is in the parent pom which contains the sonar properties
....
<properties>
<!-- Sonar -->
<sonar.sources>src,vars</sonar.sources>
<sonar.inclusions>**/**</sonar.inclusions>
</properties>
....
Both projects (pom.xml) use the this parent pom i.e. the same sonar properties
Project 1: 0 files indexed
The project structure looks like this:
D:.
│ .gitignore
│ Jenkinsfile
│ pom.xml
│ README.md
│
├───src
│ └───ch
│ └───swisscard
│ └───jenkins
│ └───pipeline
│ └───util
│ PipelineRabbitMQ.groovy
│
└───vars
ciPipeline.groovy
So there are two groovy files which should be scanned but the logfile shows 0 files indexed:
[INFO] Base dir: D:\jenkins\tools\ci-home\workspace\rabbitmq-ci-pipeline_master-2CYM2JXOI6CJM2T4MSNQTNPWY7LRY7PTSC3OG74TSX2Q2WNKXUSQ
[INFO] Working dir: d:\jenkins\tools\ci-home\workspace\rabbitmq-ci-pipeline_master-2CYM2JXOI6CJM2T4MSNQTNPWY7LRY7PTSC3OG74TSX2Q2WNKXUSQ\target\sonar
[INFO] Source paths: src, vars
[INFO] Binary dirs: target/classes
[INFO] Source encoding: UTF-8, default locale: en_US_US
[INFO] Index files
[INFO] Included sources:
[INFO] **/**
[INFO] Excluded sources:
[INFO] **/target/**/*
[INFO] **/*Test*/**
[INFO] **/*Test*/**
[INFO] Included tests:
[INFO] **/*Test*/**
[INFO] 0 files indexed
[INFO] 0 files ignored because of inclusion/exclusion patterns
Project 2: Files properly scanned
The second project structure looks like this:
D:.
│ .gitignore
│ Jenkinsfile
│ pom.xml
├───src
│ └───main
│ │ Utils.groovy
└───vars
checkQualityGate.groovy
defaultBuildApplication.groovy
ciPipeline.groovy
And here the log file indicates that all files were scanned:
[INFO] Load server rules (done) | time=98ms
[INFO] Base dir: D:\jenkins\tools\ci-home\workspace\pipeline_feature_sonar-scan-D6GRAK5PLQOMGCOOH2T6QP6BP4LA6O3LP23UC7VBSSL3RORI4ZXQ
[INFO] Working dir: d:\jenkins\tools\ci-home\workspace\pipeline_feature_sonar-scan-D6GRAK5PLQOMGCOOH2T6QP6BP4LA6O3LP23UC7VBSSL3RORI4ZXQ\target\sonar
[INFO] Source paths: src, vars
[INFO] Source encoding: UTF-8, default locale: en_US_US
[INFO] Index files
[INFO] Included sources:
[INFO] **/**
[INFO] Excluded sources:
[INFO] **/target/**/*
[INFO] **/*Test*/**
[INFO] **/*Test*/**
[INFO] Included tests:
[INFO] **/*Test*/**
[INFO] 5 files indexed
[INFO] 0 files ignored because of inclusion/exclusion patterns
Problem/Question
So apparently both projects have the same configuration and similar structure, however one is scanned and another not. At the moment I don't understand why?
I have checked other topics which did not help me
I do not have the sonar.basedir explicily set, but according to the log the base dir is fine
I had similar issue for my project. I added sonar.scm.exclusions.disabled=true in the sonar properties and the files were indexed and scanned fine.

Maven set version for multi module project where not all modules parent-pom is the same

I have a project where I bundle several independant modules and manage them through one project
I want to be able to set their versions in one command, like:
mvn versions:set versions:commit -DnewVersion="$newVersion"
The structure is the following:
base-pom/
|-- module1
| `-- pom.xml
|-- module2
| `-- pom.xml
|-- module3
| `-- pom.xml
`-- pom.xml
module1 is an infrastructure module and is used by both module2 and module3
The trick is that module1 and module2 parent pom is indeed my base-pom, but module3 parent pom is something else, available in the repo and relevant only to module3.
Since both module2 and module3 needs module1, I found this "reactor" pattern the best option for me, as I can use it as a dependency without any issues.
The only problem I suffer from so far is that I want to be able to set the versions for all modules in one command from the base-pom directory.
It works perfectly fine for base-pom, module1 & module2, but since module3 parent is not base-pom, It will not update.
Is there any way around it, other than an intermediate pom file? Seems too hacky in my opinion.

How to create a WAR file using the commandline?

I installed JBoss Developer Studio and it's possible to create a WAR file by "right mouse project > Export > WAR file" but I want to export my project to a WAR file using the commandline.
I have maven installed which is one of the requirements of the Studio and I read that I can generate a WAR file using maven but I require a file called pom.xml. When I searched through my workspace and project, pom.xml was missing. I may need to manually create pom.xml but I'm unsure how to.
My directory tree for my project is the following:
Siesta
├── build
│   └── classes
├── src
└── WebContent
├── extjs
├── extjs-4.2.0
├── extjs-4.2.2
├── index.jsp
├── META-INF
├── siesta
├── tests
└── WEB-INF
How do I create a WAR file for my Maven / JBoss project using the command line? I use Linux and would prefer not having to create a pom.xml file but if there isn't another way, then I'll use the xml file to generate the war file.
Edit:
So jar is the way to go to create a war file. I wrote up a tiny script that will create a war file for me for a specific directory.
#!/bin/bash
cd Siesta/WebContent/
jar -cvf ../../Siesta.war *
cd -
Then if you open the war file in a zip utility or archive manager in ubuntu, you'll see this structure
├── extjs
├── extjs-4.2.0
├── extjs-4.2.2
├── index.jsp
├── META-INF
├── siesta
├── tests
└── WEB-INF
I have to CD into the directory that I want to create a war file of which is kind of annoying. I think there may be a better way to do it using jar's -C option but when I used "jar -cvf Siesta.war -C Siesta/WebContent *" it didn't have the same result.
Edit2:
jar -cvf my-app.war myfolder/
For my application to work on TomCat, I use the following:
cd Siesta/WebContent
jar -cvf Siesta.war *
If this is a Maven project, then open your console, navigate to where the pom.xml file is and then run:
mvn package
It will create the {artifactId}-{version}.war file under ${basedir}/target directory. This assumes that your packaging POM element is set to war in your pom.xml file.
<project ...>
...
<packaging>war</packaging>
...
</project>
Some of the valid packaging values are jar, war, ear and pom. If no packaging value has been specified, it will default to jar.
More details here and here.
Alright here is a already existing SO with a couple of possibilities on how to create a war file: How to create war files.
I personaly prefer Maven over any other build scenario - Since i migrated from ANT i did not like Maven in the first place but after investing like a day or two into the documentations: http://maven.apache.org/pom.html i started to love it. In your case all you need is refactor your project to meet the maven standard file structure and create a minimum Maven project (a.k.a. pom.xml file) for your sources that has the packaging war instead of the default jar.
If you want to stick with the console only and dont use any build helpers beside the ones delivered by the JDK you can create your war with something like this:
jar cvf my-app.war
Have a look at this: https://docs.oracle.com/javase/tutorial/deployment/jar/build.html for a complete reference of the supported options.
(Note: A "war" in the context of java based web applications follows a standard format: http://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html while the technical ".war" file is just the same as a ZIP compressed folder renamed to ".zip".)
(Also note i would realy take the time to get in touch with maven since after that you know about a serious build tool and will be able to create jar, ear, war etc. in a standard process).
The simplest choice (if you are using Maven) is to create it with the maven-archetype-webapp:
mvn archetype:generate -DgroupId=com.sample -DartifactId=web-project -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
You can then refine your pom.xml to include the dependencies required, for example:
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
Source: How to create a Web application from the Command Line

Resources