mvn -pl <name> -am command - java

I have the following command, which I'm using to build a specific microservice (<ms-name>):
./mvnw -DskipTests clean install -pl <ms-name> -am
clean, instal, and -DskipTest are clear. But I don't understand what -pl and -am are doing.
logs:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] <utils-1> [jar]
[INFO] <utils-2> [jar]
[INFO] <ms-name> [jar]
and after it starts executing clean install on , , and in the end <ms-name>
I have checked the pom.xml but could not see the relations somewhere.
My question is: What are -pl and -am and where I can find this 'order' building relation between <ms-name>, <utils-1>, and <utils-2>?

From documentation,
-pl is,
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
-am is,
If project list is specified, also build projects required by the list
where I can find this 'order' building relation ..?
It is handled by reactor (and internal program within maven) which collects all the available modules to build, sorts the projects into the correct build order and builds the selected projects in order.
To get understand more about maven reactor, here is a StackOverflow answer which is more detailed enough.
What is the "reactor" in Maven?

Related

Facing Issue with Maven custom archtype

I'm trying to generate custom maven archtype, I'm trying below example to generate custom maven spring boot archtype:
Custom Maven Archtype
If I try to run the below maven generate command - works good
mvn archetype:generate \
-DarchetypeGroupId=com.romeh.spring-boot-archetypes \
-DarchetypeArtifactId=spring-boot-quickstart \
-DarchetypeVersion=1.0.0 \
-DgroupId=com.test \
-DartifactId=sampleapp \
-Dversion=1.0.0-SNAPSHOT \
-DinteractiveMode=false
But if I change the Group ID with my custom name - it started failing
For example if I change this from -DarchetypeGroupId=com.romeh.spring-boot-archetypes to -DarchetypeGroupId=com.test.spring-boot-archetypes
I'm getting below error message - if I change the group id.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:26 min
[INFO] Finished at: 2018-04-19T11:45:36-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project spring-boot-quickstart: The desired archetype does not exist (com.test.spring-boot-archetypes:spring-boot-quickstart:1.0.0) -> [Help 1]
Please note that - before executing this command I've changed group id in pom.xml and archetype-catalog.xml as well.
Can you please help me to fix this issue - not sure what i'm doing wrong here.
You just should not do that. These properties
-DarchetypeGroupId=com.romeh.spring-boot-archetypes
-DarchetypeArtifactId=spring-boot-quickstart
-DarchetypeVersion=1.0.0
identifies the archetype; it's like when you have some JAR and you want to add it to your project you need to provide groupId, artifactId and version.
The same approach is used for archetypes! Archetypes are packaged up in a JAR and they consist of the archetype metadata which describes the contents of the archetype.
Those properties say Maven what archetype (like what JAR) it should run to generate your app skeleton. And if you change them - Maven won't just find the appropriate JAR in the repository.
Instead, you should modify:
-DgroupId=com.test
-DartifactId=sampleapp
-Dversion=1.0.0-SNAPSHOT
Those will be properties of your project generated by that archetype.

Maven Jenkins job skips all modules if one fails to build

In Jenkins, I have a Maven project with the following structure:
x proftaakmaven
- AutosimulatieSysteem
- LandenMonitoringSysteem
- PolitieSysteem
x Verplaatsingssysteem
- VerplaatsingREST
- VerplaatsingSOAP
- VerplaatsingCommon
- VerplaatsingenRabbitMQ
- RabbitMQ-Proof-of-Concept
- VerplaatsingenRabbitMQTestClient
The Maven reactor constructs this building order:
[INFO] Reactor Build Order:
[INFO]
[INFO] AutoSimulatie
[INFO] LandenMonitorSysteem
[INFO] PolitieSysteem
[INFO] VerplaatsingenSysteem
[INFO] VerplaatsingenCommon
[INFO] VerplaatsingenREST
[INFO] VerplaatsingenSOAP
[INFO] RabbitMQ-Proof-of-Concept
[INFO] VerplaatsingenRabbitMQ
[INFO] VerplaatsingenRabbitMQTestClient
[INFO] proftaakmaven
However, due to a current failure in 'LandenMonitorSysteem' source code, Maven fails on building the other modules as well. This makes the Jenkins job fail.
I have tried running Maven with --fail-never and --fail-at-end. But neither seem to have any effect.
How would I be able to continue building all the modules, even if one fails?
Thanks.
--fail-at-end should be the thing to use.
If that doesn't work you could use -pl to specify the list of working projects.
If you use the -am flag as well you can specify the target you are interested in building and Maven will calculate the dependency tree for you.
I.E. mvn clean install -pl VerplaatsingenRabbitMQTestClient -am
I have found the solution. The problem was the way that I provided the argument. In Jenkins 2.0, the job should be configured like this :
The settings inside the job

How are maven plugin aliases mapped

I am trying to understand what mvn clean:clean actually does.
mvn -B help:describe -Dcmd=clean
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample-one 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) # sample-one ---
[INFO] 'clean' is a lifecycle with the following phases:
* pre-clean: Not defined
* clean: org.apache.maven.plugins:maven-clean-plugin:2.5:clean
* post-clean: Not defined
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.689 s
[INFO] Finished at: 2015-12-10T10:20:16-08:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------
It appears to me that mvn clean:clean is same as doing mvn org.apache.maven.plugins:maven-clean-plugin:2.5:clean. Therefore I am assuming the first clean in mvn clean:clean is just an alias for org.apache.maven.plugins:maven-clean-plugin:2.5. Similarly mvn maven-surefire-plugin:2.12.4:test is same as mvn surefire:test.
So somehow, maven-surefire-plugin:2.12.4 seems to refer to surefire and org.apache.maven.plugins:maven-clean-plugin:2.5 to clean.
When I look at the effective-pom, I see the following
maven-surefire-plugin
2.12.4
default-test
test
test
maven-clean-plugin
2.5
default-clean
clean
clean
As you can see, the pom doesnt seem to define alias. So following are my questions
Is my understanding about plugin aliases correct
If my understanding about aliases is correct - a) how and where are they defined? b) Is there a way to list all aliases.
From official Maven documentation about plugins development:
Shortening the Command Line
There are several ways to reduce the amount of required typing:
If you need to run the latest version of a plugin installed in your local repository, you can omit its version number. So just use mvn sample.plugin:hello-maven-plugin:sayhi to run your plugin.
You can assign a shortened prefix to your plugin, such as mvn hello:sayhi. This is done automatically if you follow the convention of using ${prefix}-maven-plugin (or maven-${prefix}-plugin if the plugin is part of the Apache Maven project). You may also assign one through additional configuration - for more information see Introduction to Plugin Prefix Mapping.
Finally, you can also add your plugin's groupId to the list of groupIds searched by default. To do this, you need to add the following to your ${user.home}/.m2/settings.xml file:
<pluginGroups>
<pluginGroup>sample.plugin</pluginGroup>
</pluginGroups>
At this point, you can run the mojo with mvn hello:sayhi.
So, alias are not defined in the pom file but part of built-in mechanism of maven. Further details are also provided in the official documentation about Plugin Prefix Resolution.

Maven: Build only one module out of multi-module project

I have a multi-module Maven project wherein I just want to release an update module rather than the entire project. This is due to some specific requirements, wherein a release of entire project is uncalled for - only a subset of the library needs the fixes and thus the release.
However, when I run a mvn release:prepare I get the following error Non-resolvable parent POM - I have setup the parent POM relationship in the module project with relativePath tag but that does not seem to work.
Is it possible to release only a module rather than releasing the entire project.
Thanks in advance.
EDIT
Parent pom
<groupId>com.domain</groupId>
<artifactId>project-parent</artifactId>
<version>0.5.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>library1</module>
<module>library2</module>
<module>library3</module>
</modules>
The module POMs are as under:
<parent>
<groupId>com.domain></groupId>
<artifactId>project-parent</artifactId>
<version>0.5.1-SNAPSHOT</version>
</parent>
<artifactId>library1</artifactId>
Now I just want to release the new version of library1 and not others
mvn -pl .,library1 clean install
The "." will build your parent pom.xml and "library1" is the module name you gave it.
If you don't want to build the parent pom.xml, you can also do:
mvn -pl library1 clean install
or in your case, maybe:
mvn -pl library1 deploy
I used "deploy" because "release" is not a Maven build lifecycle phase.
Try running the maven commands from the parent project/directory with the -pl <project name> switch.
the trick is both:
to repeat the -pl Param inside an additional -Darguments Param, to pass the -pl Param to the Child-Maven-Processes
the mysterious mavenExecutor, to be able to create the Child-Maven-Processes using the given -pl Param
This should work:
mvn -pl library1 -DmavenExecutorId=forked-path -Darguments="-pl library1"
I think maven is trying to tell you that the parent you defined is not released/stable. In your pom the parent version is "0.5.1-SNAPSHOT" which can not/should not work if you want to release a single library module as it would be pointing to something that is not uniquely defined. Is there a stable version you can point to instead? Otherwise maybe the -am switch works in combination with -pl?
Edit
I tried this just now with maven 3.2 and it does ask me for what version the parent should be set/resolved to. It is as I stated previously you need stable version numbers for the release to work
mvn release:prepare -pl library1
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building library1 1.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.3.2:prepare (default-cli) # library1 ---
[INFO] Verifying that there are no local modifications...
[INFO] ignoring changes on: **\release.properties, **\pom.xml.next, **\pom.xml.releaseBackup, **\pom.xml.backup, **\pom.xml.branch, **\pom.xml.tag [INFO] Executing: cmd.exe /X /C "git status"
[INFO] Working directory: C:\temp\mavenTest\library1
[INFO] Checking dependencies and plugins for snapshots ...
There are still some remaining snapshot dependencies.
: Do you want to resolve them now? (yes/no) no: : yes
Dependency type to resolve,: specify the selection number ( 0:All 1:Project Dependencies 2:Plugins 3:Reports 4:Extensions ): (0/1/2/3) 1: : 1
Dependency 'testme:parent' is a snapshot (1.1-SNAPSHOT)
: Which release version should it be set to? 1.1: :

Maven error: "You don't have a SNAPSHOT project in the reactor projects list."

What on earth does this mean? Cant find any help via google.
> mvn release:prepare
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Base 1.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.3.2:prepare (default-cli) # base ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.386s
[INFO] Finished at: Tue Oct 08 08:22:46 EST 2013
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project base: You don't have a SNAPSHOT project in the reactor projects list. -> [Help 1]
release:prepare command is supposed to prepare your snapshot project for the release. It sounds like you don't have such a snapshot project.
Here's the full details what it'll do: http://maven.apache.org/maven-release/maven-release-plugin/examples/prepare-release.html
If you're sure you should be releasing, you should be working on a maven module that has version ending with -SNAPSHOT.
Update: like noted by #khmarbaise in the comments, if your release has failed, you should do release:rollback to go back to previous state. Note though that it is not supported if you release through jenkins (jenkins issue), and it won't rollback the tags.
Don't needed manually edit pom.xml.
You can use "mvn versions:set" for batch update, something like this:
mvn versions:set -DnewVersion=1.0.3-SNAPSHOT
I've had the same error with Jenkins. In a previous release, Jenkins updated the version of the POM to a non-snapshot version, but the build failed before Jenkins could set the version to a -SNAPSHOT version again. Afterwards, making a release resulted in the error described above.
Fixing this is easy: just manually change the version of your app in pom.xml to a -SNAPSHOT version.
I know this is an old question but I had this issue recently and I found 2 solutions that others may find useful. I am using bamboo as my CI tool. The issue was that there was an error in the bamboo build leaving bamboo in an incorrect state. It had locally updated my project pom.xml with the new release version but had not checked this into SVN. The two solution that worked for me were:
Either
Delete the bamboo build-dir directory for the project and run the release again: rm -rf /opt/bamboo-home/xml-data/build-dir/PROJECT_NAME-RELEASE-JOB1
OR
Run the maven release from the command line using the following commands:
mvn release:prepare -DignoreSnapshots -Dresume=false
mvn release:perform
No need to update versions manually as that is time consuming, if version change is all you need, there is a different command that only updates the pom versions, just like updating them manually:
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=1.0.XX-SNAPSHOT

Categories