I am using Maven 3.6.0 in a project where the version of my project is set using a revision property as described in https://maven.apache.org/maven-ci-friendly.html and I want to automatically update the project's version in command line.
I tried to look on the side of maven release plugin (https://maven.apache.org/maven-release/maven-release-plugin/update-versions-mojo.html) using the release:update-versions command, which seems to work, but instead of updating the property revision it updates the version property.
Current setup :
<version>${revision}</version>
<properties>
<revision>1.1-SNAPSHOT</revision>
</properties>
When running mvn release:update-versions :
<version>1.2-SNAPSHOT</version>
<properties>
<revision>1.1-SNAPSHOT</revision>
</properties>
Expected:
<version>${revision}</version>
<properties>
<revision>1.2-SNAPSHOT</revision>
</properties>
Following is the explanation why this is happening:
When mvn release:update-versions is executed then it will bump the version by first fetching value of revision property. This command does not care about updating property value as well.
In general, property value in maven can be updated using -D flag within command line as follows:
mvn release -Drevision=1.2-SNAPSHOT
Following links could also be helpful:
https://maven.apache.org/maven-release/maven-release-plugin/examples/non-interactive-release.html
https://maven.apache.org/maven-release/maven-release-plugin/update-versions-mojo.html
Finally, I achieved to get the same result by using maven versions plugin, but it's not using ${revision} tag.
mvn versions:set -DnextSnapshot=true
Versions plugin is much more flexible than release plugin for managing your project's version.
Related
I have just cloned a git repository for a maven project and then imported the project into STS as a maven project.
I set up the project and sub-modules as java 1.8 projects and then ran a maven update and then noticed that all the java 1.5 compiler settings seem to have been reapplied.
I cant figure out why eclipse is resetting this, even if I uncheck 'Enable project specific settings' it still reverts back to having this checked and for java 5 to be the default.
I read a post about setting the version in the maven-compiler-plugin configuration but this project does not currently have any configuration for that plugin in any of the pom files.
In your pom.xml put this:
<project>
...
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
...
</project>
The reason you'll have to do this is that "the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with". See Maven Compiler Plugin for further details.
When you run Maven update command from Eclipse without setting the explicit java version, the project will take the default Maven settings, that's why you end up with 1.5 Java version.
Eclipse Photon Release (2018) only seems to recognize up to Java 10. Using
<project>
...
<properties>
<jdk.version>11</jdk.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
...
</project>
caused it to revert to 1.5. Replacing "11" with "10" was the best I could do to avoid compiler errors.
I'm trying to configure in Jenkins a maven release build with customized release version that includes the branch from which the release was made.
It looks something like this:
release:prepare -DreleaseVersion=${project.version}-${GIT_LOCAL_BRANCH}-Release release:perform
everything works fine, except that the 'project.version' placeholder, which calculated based on the pom, contains the '-SNAPSHOT' postfix.
is there other placeholder which I can use to get it without the '-SNAPSHOT'?
I know that the maven release plugin, by default, will set the right version - only I want to manipulate that value.
See the offical docu https://maven.apache.org/maven-ci-friendly.html.
There are 3 properties maven supports since 3.5: ${revision}, ${sha1} and ${changelist}. So you can use something like
<version>${revision}${changelist}</version>
...
<properties>
<revision>1.3.1</revision>
<changelist>-SNAPSHOT</changelist>
</properties>
And call it with
release:prepare -DreleaseVersion=${revision}-${GIT_LOCAL_BRANCH}-Release
But the maven-release-plugin does not work nicely together with the CI friendly versions. Read: it will probably overwrite your placeholders in the version tag. So in the end you might just manipulate the -SNAPSHOT string via bash commands.
is there other placeholder which I can use to get it without the '-SNAPSHOT'?
Unfortunately I believe the answer to your question is "no, there is no built-in variable that will satisfy your needs". However, you could try creating a property and then using that property inside of your project's version tag.
I am not able to test this as I don't have the appropriate environment set up and it's rather late so I'm not going to have the time to set it up right now. I will outline my idea and perhaps it will help you:
You could do something like this in your POM:
<version>${artifactReleaseVersion}-SNAPSHOT</version>
<properties>
<artifactReleaseVersion>0.0.1</artifactReleaseVersion>
</properties>
Then run your goals using that property:
release:prepare -DreleaseVersion=${artifactReleaseVersion}-${GIT_LOCAL_BRANCH}-Release release:perform
I have Java projects compiled with maven. Each project has its own POM which looks like the following :
<project ...>
<groupId>group.id</groupId>
<artifactId>scripts</artifactId>
<version>1.0.1-SNAPSHOT</version>
...
<dependencies>
<dependency>
<groupId>global</groupId>
<artifactId>common</artifactId>
<version>10.2.3-SNAPSHOT</version>
</dependency>
</dependencies>
...
</project>
SNAPSHOT as a RELEASE
If I do a mvn install, it will compile/install it the first time I execute the command.
Next times, it won't install it. It seams that maven consider it as a RELEASE, weither it is a SNAPSHOT.
I can see that in the timestamp included into the installed package. if I don't change the version number, the timestamp does not change either.
I believe I miss a maven configuration but this impacts a lot our development as we're force to change the projects versions (and their dependancies) for every test deployment.
Notes :
I'm using maven 3.3.3. It looks like I had not this behavior in 3.1.0 (I'm not 100% sure of the old version. Very old anyway).
Maven is coupled with Nexus. Maybe the issue comes from it and I'm focussing on the wrong horse.
Thank you for the hints.
Edit :
the question is :
How can I get maven installing SNAPSHOTs everytime instead of the first time only like a RELEASE ?
EDIT SOLVED
We've always done mvn install to compile and install the sources. For some reason, we haven't used the mvn clean command.
The correct maven command to recompile all the sources is mvn clean install.
Thank you #VinayVeluri
If versions are needed for the code changes, Please version yourself for the code base, though it is cumbersome gives the idea of versioning.
If it has to automatic regarding the snapshots update, then use
mvn -u clean install
Once added, this command line arg forces Maven to check all snapshots in a remote repository and update your local repository if it’s out of date.
source
I want to replace a Maven property in a pom.xml file with a command line call via some Maven plugin.
<properties>
<my.property>ISO-8859-1</my.property>
<properties>
Do you know of a plugin which is able to do that?
The versions plugin takes very long since it checks whether some dependency is available. Besides that it doesn't work in my case.
All you need to do is add the following when running maven on the command line
-Dmy.property=propertyValue
In a project I'm working on we are also using custom archetypes to make it easier to generate new domains/connectors. After trying to write automated tests to validate these archetypes I came across a problem with the generation of these archetypes. For some reason not all properties that are provided either using the -D flags or using the interactive mode are applied to the generated pom.xml
The archetype looks like this.
Running this command results in this pom.xml being generated. It applied the fields for the properties ${package} and ${domainInterface}, but not the ones for groupId, artifactId, version and name.
So my question is, am I doing something wrong, is the archetype broken or is that a bug in the maven archetype plugin?
I tried reproducing this by cloning the GitHub repository, installing the archetype locally and then running your command.
git clone https://github.com/openengsb/openengsb-framework.git
cd openengsb-framework/tooling/archetypes/domain
vim pom.xml
Removed the parent pom reference and then:
mvn clean install
mvn archetype:generate -DarchetypeGroupId=org.openengsb.tooling.archetypes -DarchetypeArtifactId=org.openengsb.tooling.archetypes.domain -DarchetypeVersion=3.0.0-SNAPSHOT -DgroupId=org.openengsb.domain -DartifactId=org.openengsb.domain.foodomain -Dversion=1.0.0-SNAPSHOT -Dname=FooDomain -DopenengsbVersion=3.0.0-SNAPSHOT -Dpackage=org.openengsb.domain.foodomain -DdomainInterface=FooDomain -DdomainName=foodomain -DinteractiveMode=false
cd org.openengsb.domain.foodomain/
cat pom.xml
Renders this pom.xml (only part of it pasted here):
<properties>
<bundle.symbolicName>org.openengsb.domain.foodomain</bundle.symbolicName>
<bundle.namespace>org.openengsb.domain.foodomain</bundle.namespace>
<domain.name>FooDomain</domain.name>
</properties>
<groupId>org.openengsb.domain</groupId>
<artifactId>org.openengsb.domain.foodomain</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>FooDomain</name>