Execute maven goal in command line with phase as parameter - maven

I want to run a maven plugin goal using command line. This plugin is not defined in my pom and for this reason can not specify the phase with configuration. Even so, maven is able to find it in the repo and execute the goal properly. The problem is that these goals are executed in the order they appear in the command line, is there a way to link this goal to a specific phase with a command line parameter? I'm looking for something like:
mvn org.something:plugin-name:1.0.0:plugin-goal -phase=test package
This would execute all the phases before package and in the test phase, my goal would be executed? Is it possible?

No.
The way to solve this problem is to add the plugin to the POM and specify the execution in the phase test.

Related

Maven run plugin goal and preceding phases

Usually when we run a plugin goal in maven directly from the command line, the build phases preceding the one the plugin goal is bound to will not be run.
How can we run the plugin goal and all its preceding build phases?
There is no special support for this. But you can call
mvn preceding-phase goal:you-want-to-call
which will be essentially what you want.

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 invoke a goal of a particular version of a Maven plugin?

I would like to invoke a goal of a particular version in a Maven plugin from the command line.
How can this be achieved?
I'm looking for something along the lines of:
mvn org.foo:my-plugin:1.2.3-SNAPSHOT:do-something
Your first guess is correct. The scheme for such a command is
mvn groupid:artifactid:version:goal
Example:
mvn org.apache.maven.plugins:maven-compiler-plugin:3.0:compile

maven determine default lifecycle phase for plugin

I'm using a maven plugin and I'm trying to determine that default goal it binds to. Is there a command to run to figure that out?
I was able go into the source and find the #phase annotation, but I would like to be able to figure it out from the command line if possible.
You can use the maven-help-plugin to get such kind of information:
For example for the maven-compiler-plugin:
mvn help:describe -DartifactId=maven-jar-plugin -DgroupId=org.apache.maven.plugins -Ddetail=true -Dgoal=jar

Executing a specific Maven phase

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.

Resources