maven determine default lifecycle phase for plugin - maven

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

Related

how to disable other maven phases like we do with maven.test.skip=true?

my first.
I am looking for a way to disable maven resource and jar plugin phases from command line specifically,
something like -Dmaven.test.skip=true which seems to disable maven-surefire-plugin:version:test
-Dmaven.{jar,resource}.skip=true kind of.
Is this possible ?
For dependency plugin use maven.resources.skip property.
Regarding maven jar plugin, it seems there is not a similar property, but in the links below you may find alternatives.
Link1 and link2
Note that you cannot deactivate phases. You can only deactivate plugins. -Dmaven.test.skip=true does not deactivate the test phase, but the surefire plugin.
Therefore, you need to check for the different plugins if they have a skip parameter. #leopal gave you the right directions.

Execute maven goal in command line with phase as parameter

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.

Actual commands executed by Maven in a phase or goal

This is probably a question on Maven internals, and I haven't had much luck searching and finding the answer. Concisely, I'm interested in seeing what commands Maven actually execute for each phase or goal. For example, mvn package creates the jar file, so I'd think it must call the jar -cf command at some point.
Maven is opinionated so by design, this command doesn't show up in the .pom file. But which commands does Maven actually run for a specific phase and goal? Is there a way to see them?
The call creating a jar file is done in the maven-jar-plugin which is bound to the life cycle. You can do a mvn -X clean package to what happens behind the scenes. But you won't see many commands (except for javac compiling)... What do you mean by: Maven is opinionated so by design, this command doesn't show up in the .pom file?
The life cycles shows what kind of phases run bindings shows which plugins runs in which phase.
If you want to take a look into the sources of plugins all plugins can be found here: https://maven.apache.org/plugins/
On the right side you can see links to the appropriate version control system with links to it.
Each plugin has a link to the source code for example maven-jar-plugin: https://maven.apache.org/plugins/maven-jar-plugin/source-repository.html
Run mvn with the -X parameter, then look for lines starting with "[DEBUG] Executing command line:".
All the plugins are written in Java (or JVM-based languages), so if you can read it - you can find out what it does. Here are for example sources of the maven-jar-plugin: link1, link2.
But to get there you need to figure out which plugins and goals are executed when you run a phase. There are multiple ways:
In the output Maven says which goals it executes, example:
maven-resources-plugin:2.6:resources (default-resources) # module-name
If you generate an Effective POM, you'll be able to see all the plugins and which phases they are bound to: mvn help:effective-pom. Some plugins have default phases so people don't have to specify them explicitly - for these you'd have to look into the plugin meta information or into the sources.
Default plugins and goals are defined by the packaging. For the default packagings you could look into default-bindings.xml (role-hint is the packaging name).
After you know which plugins and goals are executed you can check out the sources of each plugin (the sources are usually open) and see its Mojos for the actual source code.
If you decide to learn the code it would be useful to be able to debug it when you run a mvn command. For that you can use mvnDebug instead of mvn.
More info: click1, click2.

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

Can somebody explain this Maven command to me?

Can you please explain this command detailedly, please? What is exec? and exec:exec? -Pexperiment? -DconfigFile?
mvn exec:exec -Pexperiment -DconfigFile=src/test/resources/configFile/configFile-demo000.js
Its runnng the exec goal defined by the exec plug-in using the 'experiment' profile. The 'configFile' value is also being defined in the command-line as an system property.
mvn is the Maven Command
exec:exec is a shortcut for the goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (version may differ). This is described here: http://mojo.codehaus.org/exec-maven-plugin/exec-mojo.html.
-Pexperiment is telling maven to use a Build Profile called experiment. Build Profiles are described here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
-DconfigFile=... is a system property that is being used by maven in the pom file or by a plugin. Maven properties are described here: http://www.sonatype.com/books/mvnref-book/reference/resource-filtering-sect-properties.html. How to configure plugins is described here: http://maven.apache.org/guides/mini/guide-configuring-plugins.html

Resources