Maven - Running mvn without arguments - maven

Does running mvn with no arguments in the directory of the project result in the default lifecylce being executed for that project?
What if a profile is specified with the -P flag? does it execute the default lifecycle and binds any plugins in the profile to the phases they declare?

On your pom you can use the tag defaultGoal to specify the goal that should be executed by maven if you do not specify nothing on the command line.
See POM reference

Related

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.

How do I set up a TeamCity build job to execute a maven job with no pom

We have an in-house developed MOJO that generates content and doesn't require you to have an existing project or POM. Think of the maven archetype plugin, where you can just run mvn [mojo]:[goal] and have maven just execute that goal without a POM.
This MOJO connects to a specific database instance in a specific environment, and generates some metadata for the contents of the database, so our testers can inspect the metadata and locate production-like data that has certain attributes they need for a given test.
When you execute the metadata mojo, maven resolves the MOJO from the available repo's (in our case an Artifactory repo), and it then does its work and returns. It does not create any artifacts or other outputs.
We use TeamCity as our CI server, but it also has metadata generation jobs so with one click a dev can kick of a metadata generation job against a specific database.
The problem with this is the Maven runner in TeamCity requires a POM. If TC hasn't already checked out a project from a VCS, or the project it's checked out doesn't have a POM, the maven runner won't do anything. In this case, there is nothing to check out (the MOJO is resolved from Artifactory) so there is no POM.
I can set up the TC job to use the Command Line runner and have it execute, say, mvn com.example:metadata-generate -DenvironmentName=UAT1, but then it's impossible to specify the maven settings file that maven should use.
So my question is, how do I do this? Is it possible to have the maven runner execute an arbitrary maven command without needing a POM? Alternatively, using the Command line runner, is it possible to have a TC job copy a specific maven settings file to the build agent so it can be referenced in the maven command as mvn com.example:metadata-generate -DenvironmentName=UAT1 -s {path-to-settings-file}?
So its turns out that TC handles pom-less maven builds just fine. My problem was that the MOJO was not declared to not require a project.
Comparing my MOJO with the MavenArchetypePlugin source, I needed to declare my MOJO with the class level javadoc tag #requiresProject false.
Once I had that in place, TC ran my pom-less job perfectly well. All I had to do was clear the Path to POM file: field in the TC build configuration and leave it blank.
You can customize the name of the pom file that you use as an argument into the maven build-step in the teamcity and use this as the second "build step".Lets call the parameter as pom.file.name
In the first step , resolve all the in-house dependencies that you have and set the name of the pom file you want to execute into the variable pom.file.name
If you want to know more about how to change tha value of a variable in teamcity, you can read about it here

Maven javadoc plugin should be skipped by default but should able to execute when needed

I want maven-javadoc-plugin to be skipped by default, during the
mvn clean install command, so I have added <skip>true<skip> in the pom.xml
But I want it to be executed whenever needed, so I am trying something like
mvn clean install -Dmaven.javadoc.skip=false But it seems that it is overriding this setting with that in pom.xml and not executing the javadoc plugin.
What can I do to resolve this problem?
You could create a profile for the plugin execution (move it from the normal build generation). Within the profile, simply state that the plugin should run when you want it. The idea is that when you do a run without the profile included in arguments, it won't run; if you include the profile argument, it'll be kicked off:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Run arguments would look something like:
mvn groupId:artifactId:goal -P profile-1

Maven dependency command not working

I can run mvn clean compile and mvn install from command prompt but mvn dependency: tree doesn't work. I get:
Invalid task 'dependency': you must specify a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId : pluginVersion: goal.
Also for mvn eclipse : eclipse , I get
Invalid task 'eclipse' :blah
Am I missing any configuration here?
Thanks.
It is
mvn dependency:tree
mvn eclipse:eclipse
The part before the colon indicates the maven plugin, the part after the colon is the goal within the plugin that should be invoked. There must not be a space between the plugin name, the colon and the goal so that maven recognizes it as one argument
mvn <plugin>:<goal>
If you put a space there, maven thinks that each is is a separate argument and would e.g. try to run a goal "dependency" and another goal "tree".
Default lifecycle names (clean, install, etc.) are built-in and not part of plugins - therefore they work as they are without the ":" notation.

Maven questions

When I just type mvn command in my machine where pom is located, which phase it is going to run? mvn install or deploy??
When I use mvn eclipse:eclipse in my machine to convert maven project to eclipse project, what phases it is going to execute from default life cycle? is it going to run all the phases again?
When I just type mvn command in my machine where pom is located, which phase it is going to run?
No goal is executed, instead you'll get:
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal [...]
You can specify default goal with the following pom.xml declaration:
<build>
<defaultGoal>install</defaultGoal>
...
</build>
When I use mvn eclipse:eclipse in my machine to convert maven project to eclipse project, what phases it is going to execute from default life cycle?
It's described in the documentation:
Attributes:
Requires a Maven project to be executed.
Invokes the execution of the lifecycle phase generate-resources prior to executing itself.
See also
How do you specify a string of goals as the defaultGoal in maven 2?

Resources