Passing extra parameters to release:prepare, but not to release:perform - maven-2

When preparing the release of a Maven 2 project which includes a GWT module, mvn -B release:prepare release:perform builds the GWT module twice, which takes up most of the time of the build.
Running a full GWT build is not necessary when executing release:prepare, a validate-only build is enough. This would be achieved by specifying the -Dgwt.validateOnly=true flag on the command line, but the command line arguments are passed to a single execution when using the Maven 2 Release plugin plugin under Hudson.
How can I pass the -Dgwt.validateOnly flag to release:prepare but not to release:perform?

Do it yourself and create two steps.
mvn -B release:prepare -Dgwt.validateOnly=true
mvn -B release:perform
EDIT: Just read the documentation of the M2 Release Plugin. I suggest to use the standard Release Plugin or the Batch Task Plugin .

Related

Find classpath maven is using for running testng testcase

what options to maven can I use to determine what classpath maven is running a testng test case with?
You didn't provide the Maven version, but at least in 3.x (and maybe also 2.x) you can run commands with the -X (debug) option. That way the Test Classpath is printed out before tests are run.
mvn test -X
In general you can find the classpath that maven is using by using the built-in maven dependency plugin and its build-classpath goal.
If you want the classpath uses for compiling and running the test you need to select the test dependency scope. This scope is the default, but if you want to be explicit you can set it with -DincludeScope=test.
Other scopes include runtime, compile, provided and system.
Depending on how you want to consume the output you can play with the options -Dmdep.outputFilterFile and -Dmdep.outputFile. The mdep.outputFilterFile makes it easier to parse the output from a script and the outputFile option writes to a file instead which some tools can read directly.
Here are some examples:
$ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFilterFile=true|grep 'classpath='
classpath=xxx.jar:yyy.jar
$ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=cp.txt
$ cat cp.txt
xxx.jar:yyy.jar
I couldn't format my response in my comment so submitting the grepped version here:
mvn test -X | grep "maven.dependency.classpath"

question on mvn -e clean install

In maven, what does "-e" stands for in the following command.
mvn -e clean install
Moreover, what is the difference between
mvn clean install
and
mvn clean compile
As Satish stated, the "-e" switch will display execution errors in the maven output.
As to the difference in "install" vs "compile", those are different Maven lifecycle stages. See the Introduction to the Build Lifecycle documentation for help with that. The key to remember is that Maven will execute all lifecycle stages up to and including the one you specify, and then stop.
Specifically in your case, "mvn clean compile" will run Maven with two lifecycle targets, the first being "clean", and the second being "compile". The "compile" lifecycle phase will run the build up to and including the compilation of project source code. The "install" lifecycle phase will run all the way through packaging your project into it's container (jar, war, etc) and will install it to your local maven repository, which resides on your local machine. When a project is installed to your local repository, other projects you build on your machine can reference it without having to have any knowledge of where the source code or project build artifacts actually reside.
the e flag (e = errors) prints out more detailed error messages.
mvn clean install, does compilation, linking and installs (copies to app server etc)
for more maven options look at this ref card
http://www.scribd.com/doc/15778516/DZone-Refcard-55-Apache-Maven-2
or maven command list
http://cvs.peopleware.be/training/maven/maven2/mvnCommand.html
mvn clean install - First, cleans already compiled class files (probably in target/ directory). Then, it compiles the classes, generate the jar, and then install the created jar to your local m2 repository (probably located at ~/.m2/repository/).
mvn clean compile - The clean does the same thing as above. And, then, it compiles the java files in the project. And, stops there. It doesn't create the jar nor install anything to the local maven repository.
-e switch will display the stack-traces occur when your build is failed. It's a normal stack-trace that java programs produce when exceptions occur. Do note that Maven itself is a Java program.

Execute many commands maven (mvn install:install-file) in a project free style of Hudson

I want to create a project *free style* using Hudson and i want to execute in it commands that installs jar in the repository of Maven by using : mvn install:install-file
When i put one command it works but when i put more that one command:
mvn install:install-file
mvn install:install-file
Hudson executes the first command only!!
Who has a solution for this please?
I have 120 jar file, it only runs the first one and exits to the command prompt.
So i've found a solution : by using the call command for each call to mvn like this:
call mvn install:install-file ...
call mvn install:install-file ...
By this method you can put many commands Maven in only one project free style in Hudson.
Why don't you setup separate jobs in Hudson, and add a post build action on the first one to kick off the second, or a trigger on the second to kick-off after the first job completes.

A simple command line to download a remote maven2 artifact to the local repository?

I have a library that I distribute using maven 2. The typical user of this library doesn't use maven to build their applications, but is likely somewhat familiar with maven and probably has it installed.
I'd like to document a "simple" one line command they can use to download my library's artifacts to their local ~/.m2/repository without requiring that they set up a pom.xml to do it.
I thought there was a way to do this, but I can't seem to find it after looking through the install:install-file and dependency plugin documentation. I tried things like:
mvn install:install-file -DrepositoryId=java.net -Durl=http://download.java.net/maven/2/ -Dfile=robo-guice-0.4-20091121.174618-1.jar -DpomFile=robo-guice-0.4-20091121.174618-1.pom -DgroupId=robo-guice -DartifactId=robo-guice -Dversion=0.4-SNAPSHOT -Dpackaging=jar
but I think I'm barking up the wrong tree since it appears that the install plugin is used to copy locally built files into the local repository, rather than download remote artifacts into the local repository.
This is the artifact I'd like to install: http://download.java.net/maven/2/robo-guice/robo-guice/0.4-SNAPSHOT/
Is this possible using maven?
Since version 2.1 of the Maven Dependency Plugin, there is a dependency:get goal for this purpose. To make sure you are using the right version of the plugin, you'll need to use the "fully qualified name":
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
-DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=robo-guice:robo-guice:0.4-SNAPSHOT
Give them a trivial pom with these jars listed as dependencies and instructions to run:
mvn dependency:go-offline
This will pull the dependencies to the local repo.
A more direct solution is dependency:get, but it's a lot of arguments to type:
mvn dependency:get -DrepoUrl=something -Dartifact=group:artifact:version
As of version 2.4 of the Maven Dependency Plugin, you can also define a target destination for the artifact by using the -Ddest flag. It should point to a filename (not a directory) for the destination artifact. See the parameter page for additional parameters that can be used
mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get \
-DremoteRepositories=http://download.java.net/maven/2 \
-Dartifact=robo-guice:robo-guice:0.4-SNAPSHOT \
-Ddest=c:\temp\robo-guice.jar

Maven install-file won't generate pom.xml

I've installed some third party jars to my repository using the following command:
mvn install:install-file -Dfile=/home/anotherCoder/Downloads/nifty-1.0.jar -DgroupId=nifty-gui -DartifactId=nifty-gui -Dversion=1.0 -Dpackaging=jar
However, once I do mvn compile, maven complains that there is no pom file in the repository and attempts to download it, but can't cause it is not published at any remote repository.
Here is the exact message from maven:
Downloading: http://repo1.maven.org/maven2/nifty-gui/nifty-gui/1.0/nifty-gui-1.0.pom
[INFO] Unable to find resource 'nifty-gui:nifty-gui:pom:1.0' in repository central (http://repo1.maven.org/maven2)
So how do I get maven to generate a pom file for that jar and put it in my local repository?
You tell it to! :-)
mvn install:install-file
-Dfile=/home/anotherCoder/Downloads/nifty-1.0.jar
-DgroupId=nifty-gui
-DartifactId=nifty-gui
-Dversion=1.0
-Dpackaging=jar
-DgeneratePom=true
(Command placed on multiple lines so you can easily see the last parameter.)
Nice, huh? In the future you can go to a plug-in's documentation, view its goals, and you can see all the parameters it accepts. For example, the install-file goal.
Edit:
Regarding the question of the default behavior of the generatePom flag, the documentation indicates it defaults to true, and the code appears to support that. However, using Maven 2.0.9 with the maven-install-plugin version 2.2 (both versions are slightly out of date), it does not generate a POM. So, perhaps incrementing the version(s) will allow the default to work.
> touch DeleteMe.jar
> mvn install:install-file -DgroupId=Delete -DartifactId=Me -Dversion=0.0.0 -Dpackaging=jar -Dfile=DeleteMe.jar
...
[INFO] BUILD SUCCESSFUL
...
> ls ~/.m2/repository/Delete/Me/0.0.0/
Me-0.0.0.jar
(No generated POM.)
The install:install-file goal has an optional parameter generatePom (since version 2.1) that allows to:
Generate a minimal POM for the
artifact if none is supplied via the
parameter pomFile.
Defaults to
true if there is no existing POM in
the local repository yet.
This parameter defaults to true since version 2.3 (and false in 2.1, 2.2). So if you're using a version of the install plugin prior to 2.3, you'll have to pass the parameter in the command.
Just in case, the syntax to explicitly use the version 2.3 of the install plugin would be:
mvn org.apache.maven.plugins:maven-install-plugin:2.3:install-file \
-Dfile=/home/anotherCoder/Downloads/nifty-1.0.jar -DgroupId=nifty-gui \
-DartifactId=nifty-gui -Dversion=1.0 -Dpackaging=jar
I had the same issue I think as you, I had a shell script using the install:install-file goal like this:
mvn -o install:install-file -e
-DgroupId=org.jfree.jcommon
-DartifactId=jcommon
-Dversion=1.0.15
-Dpackaging=jar
-Dfile=jcommon-1.0.15.jar
Couple of things to note:
artifactId cannot contain '.' ... not sure why but the install would fail if this contained '.'
Running the above command only generated a pom with maven 3.x. By adding the following arguments, I was able to get the jar's to be copied:
-DgeneratePom=true -DupdateReleaseInfo=true
Well and in case your third party library really is "nifty gui" all you need to do is to add the nifty maven repository to your pom.xml:
<repositories>
<repository>
<id>nifty-maven-repo.sourceforge.net</id>
<url>http://nifty-gui.sourceforge.net/nifty-maven-repo</url>
</repository>
</repositories>
and your maven project will automatically download nifty :D
PS: I know that this was not your actual question but it might help with nifty integration :)