Hi Meier I have used the following goal
mvn org.codehaus.mojo:versions-maven-plugin:2.7:update-property -
Dproperty=emom.web.dependency.shr.version -DallowSnapshots=true
My Job B pom.xml is
<dependency>
<groupId>com.safeway.app</groupId>
<artifactId>emom-shr</artifactId>
<version>${emom.web.dependency.shr.version}</version>
</dependency>
Under the properties it has version harcoded
<emom.web.dependency.shr.version>19.6.5-
SNAPSHOT</emom.web.dependency.shr.version>
My Job A pom.xml
<groupId>com.safeway.app</groupId>
<artifactId>emom-shr</artifactId>
<version>20.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
When I run the above goal maven is picking the latest version i,e(20.1.0)
from artifactory but when I check the pom.xml of Job B under properties it still says 19.6.5 I need a way to change the 19.6.5 or current version to latest version available. Am I doing something wrong not able to figure it out.
You need versions:update-property to update the content of properties in your POM.
See https://www.mojohaus.org/versions-maven-plugin/update-property-mojo.html
Related
Is it somehow possible to change the version of a Maven project without manipulating the POM file?
Let's say I have a Maven project with version 1.5.0-SNAPSHOT but I want to build it as 1.5.46.
The Versions Maven Plugin unfortunately modifies the POM files.
Since Maven 3.5.0 this is possible using a special predefined property: ${revision}. Define the property with a default value (e.g. 1.5.0-SNAPSHOT) and when needed, set it during execution to a specific version (e.g. 1.5.46).
For example, define the following in your pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>foo</artifactId>
<name>Foo Module</name>
<version>${revision}</version>
...
<properties>
<revision>1.5.0-SNAPSHOT</revision>
</properties>
</project>
Build it using the default value:
mvn clean install
This will produce an artifact identified as org.example:foo:1.5.0-SNAPSHOT.
In order to build a specific version, set the revision property, for example:
mvn clean install -Drevision=1.5.46
This will produce an artifact identified as org.example:foo:1.5.46.
For further details, see the Maven CI Friendly Versions page.
Try to override project version with
mvn versions:set -DnewVersion=<version>
in your particular case:
mvn versions:set -DnewVersion=1.5.46
You can
Make a copy of your pom as temppom.xml
Replace the version in temppom.xml
Build with mvn -f temppom.xml.
Delete temppom.xml.
Maven supports delivery friendly versions, see https://issues.apache.org/jira/browse/MNG-5576 .
For more details I would suggest to talk with #khmarbaise
The plugin provides a goal to revert the changes made by it:
mvn versions:revert
The parent pom.xml of my application contains the following snippet:
...
<version>2.0-SNAPSHOT</version>
...
<properties>
<property.version>1.0-SNAPSHOT</property.version>
</properties>
Essentially, I would like to update both the -SNAPSHOT versions to release versions. i.e., I want my resultant pom.xml to be like:
...
<version>2.0</version>
...
<properties>
<property.version>1.0</property.version>
</properties>
[Note: v1.0 of <property.version> is not yet deployed to the artifactory and also might not be the latest version available
There might exist more properties with SNAPSHOT versions that I do not want to update to release versions]
I figured out a way to update the <version> using maven versions:set plugin. However, I could not find any solution for updating the version (by removing -SNAPSHOT) inside the <properties> tag.
I've looked at documentations for versions:update-properties, versions:update-property.
I am trying to achieve this by using the mvn versions plugin, otherwise I would have to write a script (eg. shell) which would parse and do the needful.
I have a pom file in which version numbers of some dependencies rely on the project version property specified in the settings of the pom file. Can I overwrite this via the command-line? If so, how?
Here's the long story:
We are currently transitioning our projects to maven, but we're not all the way there yet. There are multiple modules that are still not built with maven and are therefore dependencies in our project (they are built into jars through ant). Upon release, we want all of these jars to be built and contain the same version number as the parent project. For a release, two steps are performed (until we can get everything using maven)
The jars are built in ant with the correct release version (12.12.4.0).
The maven release plugin is used to deploy the project to our artifact repository.
In the second step command-line arguments are used to specify the release:
mvn release:prepare -DreleaseVersion=12.12.4.0 -DdevelopmentVersion=12.12.4.1-SNAPSHOT -Dtag=iv-12.12.4.0
I would like the pom file to be updated with the version specified. However, when this command is run, the version within the pom file (12.12.4.0-SNAPSHOT) is still being used. This fails the "checking dependencies and plugins for snapshots" step and I am required to resolve my jars that still have the 12.12.4.0-SNAPSHOT version used from the maven version property.
This led me to the original question of how I can override this so that the version resolves to that specified on the command line.
Additional questions that could get me past this is:
How to allow the maven release plugin to update the pom file before this check?
How to skip the snapshot check (not desirable)
I could create a property within the pom file that I can overwrite, but then I'd have to maintain the version number in two places within the pom file.
Thoughts?
Put parameters directly to pom from command line for example:
mvn clean install -Dtestng.version=6.3.1
Example:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<name>test</name>
<properties>
<testng.version>6.4</testng.version>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
If you run it normally testng version 6.4 will be used. But if you run it like: mvn clean install -Dtestng.version=6.3.1 testng version 6.3.1 will be used.
See Setting Maven params in Jenkins
Here is one more option:
<Logger name="com.mypackagename" level="${env:LOG_LEVEL:-error}" additivity="false">
<AppenderRef ref="Console-Appender"/>
</Logger>
${env:LOG_LEVEL:-error} means env = environment variable, LOG_LEVEL = env name, -error = default level error.
I have a project A which depends on artifact B. I made some hack on B, and want to see it in A. So I don't want A to use the version in my local repository, instead, I want A to use my hacked version of B.
I'm looking for a solution that can specify my-hacked-B.jar as dependency of A, like this:
cd A && mvn package -Ddependency.org.groupB.B.jar.path=path/to/my-hacked-B.jar
Is it possible, or I have to install the modified B in my local repository?
You can't do it on the command line, but you can set the dependency scope to system in the pom.xml and provide a path to the dependency.
<dependency>
<groupId>org.groupB</groupId>
<artifactId>B</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/path/to/hacked-B.jar</systemPath>
</dependency>
There is no way to resolve dependency from command line, but there is a way to let maven resolve dependency externally.
I created a temporal wrapper pom.xml which aggregates the two projects. It works, without install anything into local repository.
The only problem is that I am unable to use absolute path in <module/>.
See http://maven.apache.org/pom.html#Aggregation
A little bit late :) You can do it with properties:
<properties>
<org.groupB.B.scope>compile</org.groupB.B.scope>
<org.groupB.B.path></org.groupB.B.path>
</properties>
<dependency>
<groupId>org.groupB</groupId>
<artifactId>B</artifactId>
<version>2.0</version>
<scope>${org.groupB.B.scope}</scope>
<systemPath>${org.groupB.B.path}</systemPath>
</dependency>
and then:
mvn package -Dorg.groupB.B.scope=system -Dorg.groupB.B.path=path/to/my-hacked-B.jar
You could mvn clean install your hacked version into your local maven repo, over the version you downloaded from the 'net. You'd need to make sure that project B's pom reflects the version you are depending on and not a snapshot version. (Or, to put it more generally: The version of project B that you mvn clean install must match the version you require in project A. Whether you edit A's pom or B's pom doesn't matter.)
I am pretty new to maven.
Now I have a maven project developed. My another project needs to depend on this one.
Does anyone know how can I generate my own dependency? So that my second project can add the first one as a dependency in pom.
thank you very much
Since your first project is already a maven-project, just install it in your local repository by running mvn install in the first project's root directory.
Then you can include a dependency in your second project by simply referencing the groupId, artifactId and version you defined in the first project.
So if your first project had the following in its pom:
<project>
<groupId>com.yourdomain</groupId>
<artifactId>yourcomponent</artifactId>
<version>1.0</version>
... <!-- more here -->
you can include this in your second project:
<dependencies>
<dependency>
<groupId>com.yourdomain</groupId>
<artifactId>yourcomponent</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Unless you deploy your project 1 jar to a central maven repository, this will only work if your jar is in your local repository (via mvn install).
Maven projects are identified by the "Maven coordinates", that is, the ArtifactID, GroupID and version.
Say you create your first project and run maven install. Your local repository (in $HOME/.m2/) will now contain the compiled project plus whatever coordinates you put in there.
Your second project must now only depend on the said coordinates.
I would suggest googling a bit on maven. I made a tutorial a long time ago that might help you, even if the examples are a little simple. Here you go and good luck!