Executing a specific Maven phase - maven

Is there any way to execute a specific phase in a maven build. For example, if I only want to run those plug-ins that execute in the pre-integration-phase, does Maven provide a means to do that?
e.g.
mvn pre-integration-phase

You can't call the life-cycle-phase itself but you can call the goals of the plugins which are bound to the life-cycle-phases.
mvn compile:testCompile
mvn failsafe:integration-test
but usually this shouldn't be needed...

No. You'd have to run the plugins manually.

Related

How to completely skip unit tests and integration tests during maven release prepare and perform with maven release plugin

I have set up some automation to perform maven semantic versioining using maven release plugin. As such i am using the below :-
mvn -B clean release:clean -DpreparationGoals=clean release:prepare -Darguments="-DskipTests" -Darguments="-DskipITs" -Darguments="-Dmaven.javadoc.skip=true" release:perform -Dusername=$GIT_USERNAME -Dpassword=$GIT_PASSWORD
Everything works great except for the fact that during perform phase, i still see the TESTS being executed in our jenkins logs.
I am wondering what would be the best way to skip any kind of tests during this maven release prepare and perform without having to make any changes in existing pom.xml as i would like to enforce that through maven arguments passed as CLI arguments so that we don't have to update 1000 of poms using this automation
Any help or suggestions here would be greatly appreciated as always.
You can use the arguments property to do this. Quoting can be very important.
Example:
mvn release:prepare ... -Darguments="-Dmaven.test.skip=true -DsomethingElse=whatever"
Here, I pass the maven.test.skip property (defined by the maven-surefire-plugin's test goal) through to the execution of mvn run by the prepare goal of the maven-release-plugin.

Execute maven install phase without executing maven compile

Working with a multi-module project. Want to run maven commands as follows:
mvn clean compile
Then maven install phase without again executing maven compile
Not possible.
You would need to call the goals directly, phases cannot be run separately.
you can (now) skip phases by directly calling the goal via
mvn <plugin>:<goal>
e.g.
mvn compiler:compile
see this answer for details.
for install it should be mvn install:install

Create custom Maven script to run other maven scripts in given order

In gradle I can define task that runs other tasks in particular order, is it possible to do the same in maven?
For example, instead of running
mvn clean spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=dev"
or
mvn clean spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=prod"
I want to create single scripts like
mvn server-run:dev or mvn server-run:prod respectively
In Maven, goals are executed in the order of build phases and then in the order the goals are defined in pom.xml.
You could attach different execution goals to same build phase and place them in certain order in pom.xml. You will need to add "execution" nodes to spring-boot plugin. Follow to further reading for inspiration: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Is there a way to simplify this maven command for sonar?

I'm running the following sonar command with maven:
mvn clean compile sonar:sonar
I'd like to just run:
mvn sonar:sonar
(ie have the sonar task trigger the clean and compile steps)
Is there a way to express this as a dependency in maven?
Quick Answer: No - not by declaring dependencies nor by having the plugin be in charge of the lifecycles and their phases to be run prior to the plugin's goal.
By mvn clean compile sonar:sonar you are instructing Maven to first run the entire clean-lifecycle with all its phases - then continoue with the default lifecycle to the phase compile and finally to call the goal sonar of the plugin sonar - i personally think the command is relativly short for what is going on and must not be simplified any further (what would be the actual benefit of a shorter command executing the same phases/ goals in the background?).
You can however bind plugins to certain build phases so that if the phase is run (say the phase process-classes right after phase compile in the default lifecycle) the plugin's goal will be executed automaticially.
This would abstract the need of explicitly calling sonar:sonar and allow for example to just call mvn clean process-classes and have sonar:sonar beeing executed in the process-classes phase of the default lifecycle.
Now to come back to your question one could generally ask if a Maven plugin can take controll of the lifecycles and phases beeing executed prior to its own goal which is as faar as i know not possible with "standard Maven techniques" (I however dont know of the possibilities if you write your own plugin).

Maven-assembly-plugin & incremental build

It seems that the assembly plugin (or jar/war plugin) are just dumb.
They just can't figure out whenever there is just nothing to do.
A basic "Makefile" won't recompile a target if all its dependencies are older than the target.
For maven, it seems that the packaging is done "all the time" !
if I do "mvn package" and then "mvn integration-test", Maven will process the packages again and again.
Since I build some fat-standalone jars : it takes a while !
Is it also the way is works for you, or is there something broken in my configuration.
Thanks in advance for your help,
Raphaƫl
In Maven exists a Life-Cycle which is run through every time you call a phase.
mvn integration-test
means to run all phases which are before integration-test (incl. integration-test itself) which includes in your case the package phase. Furthermore you shouldn't call integration-test cause the post-integration-test will not run in this case. You should call mvn verify instead.
The result from the above is you should simply call mvn integration-test and the package phase will run automatcially. Maven is not Make.

Resources