How can I package a specific version with maven? - maven-2

I'd like to call
mvn clean install -Dsomeproperty=1.2.3-20110526-1836
to get
artifact-1.2.3-20110526-1836.jar
instead of
artifact-1.2.3-SNAPSHOT.jar
How can I pass that timestamp to maven ??

The following artifact setting in pom.xml seem to be doing what you want:
<groupId>testgroup</groupId>
<artifactId>testartifact</artifactId>
<version>${someproperty}</version>
Now if you execute "mvn clean install -Dsomeproperty=1.1.timestamp", the jar file produced also contains the timestamp in its name.
I'm not sure if this is what you are looking for.
EDIT
Another solution since the pom file cannot be changed.
Execute the "mvn clean install" command normally. This generates a jar file like artifact-1.2.3-SNAPSHOT.jar.
Install this file again - this time with "mvn install:install-file -Dfile=artifact-1.2.3-SNAPSHOT.jar -DgroupId=testgroup -DartifactId=testartifact -Dversion=1.2.3-123456-1234 -Dpackaging=jar. This will install artifact-1.2.3-123456-1234.jar in your local repository

While this will do what you specified:
<project ...>
<properties>
<someproperty>somproperty-default-value</someproperty>
</properties>
<build>
<finalName>artifact-${someproperty}</finalName>
....
</build>
....
</project>
I would recommend to use this: How do I add time-stamp information to Maven artifacts?

The fastest hack for this is to run
mvn clean install --offline
This will prevent from loading your nightly build from remote repos.
You may also play with settings.xml

Related

How to deploy pom.xml as SNAPSHOT with maven?

I have a pom.xml and i want to use it as the parent pom.xml of my project.
and want to make the name for the pom.xml which was uploaded on Nexus like ABC-root-pom-2.0.0-SNAPSHOT.pom
so could anyone tell me what the command is using maven ?
Thanks
Do not worry about what name the pom will have on the repository manager. The Maven repository format dictates that.
To get a Maven project with pom packaging deployed you have to do the normal steps of adding the distributionManagment to the pom and the credentials to the settings.xml. Then you run
mvn clean deploy
and thats it. Your other project can then reference it. An example for such a pom project is my progressive-organization-pom.

Maven packaging web application

i removed one un-used dependency from pom.xml of the project which had packaging of war kind.Even after removing it, it is getting bundled under lib folder.
Why is this so?
Appreciate your inputs
execute following command to see your actual pom
mvn help:effective-pom
or outout it to a file
mvn help:effective-pom > effective-pom.xml
now go through the generated effective-pom.xml

Using Maven ant task to install jar to local repository

At the end of my ant build id like it to call the equivalent of the command line call
mvn install:install-file -Dfile=my.jar -DgroupId=com.company.project -DartifactId=my_project -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
so that it will add the newly built jar to a maven repository which another project will rely on.
Ive tried using the maven-ant-task and have added the maven-ant-task jar to the ant built project and the following code to the build.xml:
<target name ="minstall" depends="jar">
<artifact:pom id="maven_install" file="maven_install.xml" />
<artifact:install file="${out.dir}/my_project.jar">
<pom refid="maven_install"/>
</artifact:install>
</target>
but seem to be missing something as it wont work for me. To begin with i get the error in the build.xml (ant build file) saying
The prefix "artifact" for element "artifact:pom" is not bound.
What am I doing wrong. I am fairly new to ant?
On a realted question what is the purpose of the associated POM file? I would not normally have a POM in this project as it is an ant build
Perhaps maven-ant-task jar is not installed, i.e. not in your ant CLASSPATH. You can follow this instruction for this.
As mentioned previously, you need to make sure the tasks are defined in your ant script, and the artifact namespace is understood.
The POM file is used (in this case) to tell the Maven repositories the dependencies of the JAR you are putting in the repository. The POM should also specify the JAR's identification information (groupId, artifactId, version number, license, etc.).
Strictly speaking, you do not need an external POM, you could define the information in your build.xml file as follows:
<!-- Assuming tasks defined, and 'artifact' namespace exists -->
<artifact:pom id="maven_install" groupId="com.whatever" artifactId="some-jar"
version="1.0" packaging="jar">
<dependency groupId="..." artifactId="..." version="..."/>
<dependency groupId="..." artifactId="..." version="..."/>
<license name="apache" url="http://www.apache.org"/> <!-- can be omitted -->
</artifact:pom>
<target name ="minstall" depends="jar">
<artifact:install file="${out.dir}/my_project.jar" pomRefId="maven_install"/>
</target>
When you install the JAR in the 'minstall' task, the POM should be generated with the appropriate dependencies in the local Repository.
That message means you are missing an xmlns:artifact attribute in your build.xml. Have a look at the installation page in the docs for an example.
As to the purpose of the POM file, it's mostly metadata so that maven can figure out dependencies properly. In a real maven build it also describes how to build, test and package. But in your case all that is done by ant instead.
I think that it makes no sense to put such commands in Ant's build.xml. If you want to have your jar file installed in your maven repo just use mvn install command.
Besides that, I guess that you are somehow confusing the purpose of Maven and Ant tools in your project. What I'd suggest is to use Maven as your main build tool. You can configure invokation of Ant targets in your POM file if you really need that. Personally, I think it is the best solution to have Ant called by Maven. Maven goals (such as clean, test, package, install and so on) are very simple to use and powerful (I guess that you can read it in every Maven tutorial).

maven install file manually without version

How do I add a jar file to my local repository without appending the version number to the jar file?
Lets say I have a jar file named abc.jar and run the following command, it will create abc-1.0.jar and if I bundle this artifact in a war file, the resulting file name will be abc-1.0.jar. If I remove the -Dversion, the command fails. If I mention blank value -Dversion="", then abc-.jar is created. How do I keep the original jar's filename(abc.jar)?
mvn install:install-file -Dfile="d:\abc.jar" -DgroupId=grp1 -DartifactId=art1 -Dversion=1.0 -Dpackaging=jar
How do I add a jar file to my local repository without appending the version number to the jar file?
You can't.
This works for war packages. I haven't tried it for jars.
<build>
<!-- Ensures that the version number is not included in the packaged file name -->
<finalName>myrenamedpackage</finalName>
</build>
You can not change the name of the arifact in your maven repository, but you can configure the war plugin to use a specific nming scheme for the libs it bundles in WEB-INF/lib using the outputFileNameMapping option. To remove version information and classifiers the mapping pattern would be #{artifactId}#.#{extension}#. If the artifact id matches the original filename this should give the wanted result.

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 :)