Want to only build specific submodules of a maven project - maven

I have a multi module maven project with multiple levels of directory heirarchy. Normally we build the whole project, but have hit some resource issues building docker images (these are orchestrated from the maven modules), and a workaround is to create multiple build jobs, each of which builds a single image.
One option is to simply cd to the relevant subdirectory and build from there, but I would ideally like to use the 'mvn -pl' option, though am struggling with the useage
We use groupid 'org.odpi.egeria' & The pom is structured as
. (egeria)
open-metadata-resources (open-metadata-resources)
open-metadata-deployment (open-metadata-deployment)
docker (open-metadata-docker)
egeria (open-metadata-docker-egeria)
This is just one part of the tree to demonstrate the issue
Using the -pl option specifying directory names to build
Using the -pl option specifying artifacts to build
mvn -pl open-metadata-resources/open-metadata-deployment/docker/egeria clean install
mvn -pl org.odpi.egeria:open-metadata-docker-egeria clean install
In both cases I get:
[ERROR] [ERROR] Could not find the selected project in the reactor: open-metadata-resources/open-metadata-deployment/docker/egeria #
[ERROR] Could not find the selected project in the reactor: open-metadata-resources/open-metadata-deployment/docker/egeria -> [Help 1]

Related

Sonarqube analysis for selected modules

I have a multimodules project with many dependencies. Until now after successful build I was performing sonar analysis of whole project. To save time and build project I detect which modules have been changed and run maven command:
mvn install -pl module1,module5,module2 -amd
Is there any way to do static analysis only for built modules? Something like mvn sonar:sonar -pl module1,module5,module2 -amd? of course it doesn't work, do you have any idea?
I know that there is option:
mvn sonar:sonar -pl !module2
but my project has more than 50 modules so if commit change only 5 modules I will have to list 45 others modules.
SonarQube always requires full scan. If you exclude some modules and execute the scanner, then excluded modules will disappear from SonarQube. It means there is no such flag.
Read more: How to analyse only new added lines of code?

How to skip some java files from compilation in maven using command line?

I am using maven with jenkins. On eclipse the project build works fine. When I use jenkins I get the following error
[ERROR] /E:/jenkins/workspace/product/src/test/java/com/new/ftp/FTPTest.java:[102,55] package com.fasterxml.jackson.databind does not exist
The options for maven are as follows:
mvn clean install -X
I want to know if I can pass some arguements to maven to skip that package. I don't want to modify my pom.xml yet .
P.S - The project consists of a main pom.xml which calls other child modules.

Could not find the selected project in the reactor Maven : Jenkins

I’m using Jenkins to build a multi-module Maven project. Recently, I removed a module from our parent pom
when we run the build in Jenkins with the following options …
mvn -T 8C clean install -PTata
However, the build ultimately fails with the below error.
“Could not find the selected project in the reactor: com.customization:Avg”
Project Structure
- src
Customization
Tata
Avg
Qlip
Suggest to solve this issue...

Maven build second level+ child projects using reactor option -pl

My maven project structure is as below
Project A
pom.xml
- ProjectB
pom.xml
- ProjectC
pom.xml
- ProjectD
pom.xml
- ProjectY
pom.xml
By using maven reactor options i can
clean install -pl projectB or clean install -pl projectY
But while trying to build the second level child modules using clean install -pl projectC, maven throws
org.apache.maven.MavenExecutionException: Could not find the selected project in the reactor: projectC
how to build the second level+ child modules using maven reactor options
From the documentation for the -pl option it states the following:
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path.
The important part for you is: "or by its relative path".
So to build projectC, you simply need to refer to it by its relative path (projectB/projectC). So the command you need is:
mvn clean install -pl projectB/projectC
This is an answer from a similar question that is also relevant here.
By using artifactIds you don't have to know the structure of your project.
If you only use the artifactIds of the given project you have to define that correctly on command line:
help output of Maven (mvn --help)
Comma-delimited list of specified reactor projects to build of all
projects. A project can be specified by [groupId]:artifactId or by its
relative path
This means in your case you have to define:
mvn clean install --projects :projectC,:ProjectY
Notice the : that is prepended to the artifactIds to indicate you omit the groupId
Just in case someone else has this one too:
I also encountered this error message. The reason was that by accident I had been in one of my (sub-)modules in the path in terminal.
Of course the command has to be executed in the project's root hierarchy. According to the example above you have to assure that you execute a command like:
clean install -pl projectB
at Poject A
not e.g. at ProjectY or somewhere else deeper in the project structure.
Correct:
user:~/workspace/IdeaProjects/pojecta{master}$ clean install -pl projectB
Wrong:
user:~/workspace/IdeaProjects/pojecta/projecty{master}$ clean install -pl projectB

Maven reactor and site

I have a multi-module project with a parent pom.xml and several modules where some of the modules depend on each other. In the project directory I can call
mvn test
to run unittests in each module. No problem here. But if I call
mvn site
one of the modules reports
[ERROR] Failed to execute goal on project myModule_C: Could not resolve dependencies
for project org.myModule_C:jar:0.0.1-SNAPSHOT: The following artifacts could not be
resolved: org.myModule_A:jar:0.0.1-SNAPSHOT, org.myModule_B:jar:0.0.1-SNAPSHOT: Failure
to find org.myModule_A:jar:0.0.1-SNAPSHOT in http://artifactory-server:8081/artifactory/repo
was cached in the local repository, resolution will not be reattempted until the update
interval of server has elapsed or updates are forced -> [Help 1]
I think this should not happen since these dependencies are found during "mvn test". Also, they are not in the artifactory-server but part of the parent project. The goal that is mentioned in the ERROR is the goal site. Why does the mvn test succeed (with respect to dependencies it finds) and mvn site does not? Do I have to build the site in a special way - because this is a reactor build?
You should execute the mvn install as least once. Please see further information at the Maven Build Life Cycle and Maven in 5 Minutes.
Here is the overview
Maven Phases
Although hardly a comprehensive list, these are the most common default lifecycle phases executed.
validate: validate the project is correct and all necessary information is available
compile: compile the source code of the project
test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package: take the compiled code and package it in its distributable format, such as a JAR.
integration-test: process and deploy the package if necessary into an environment where integration tests can be run
verify: run any checks to verify the package is valid and meets quality criteria
install: install the package into the local repository, for use as a dependency in other projects locally
deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
There are two other Maven lifecycles of note beyond the default list above
They are:
clean: cleans up artifacts created by prior builds
site: generates site documentation for this project
I hope this may help.

Resources