How to increase snapshot version or release version automatically through maven - maven

How to increase snapshot version or release version automatically through maven. I am aware we could use maven goals such as release:prepare or release:update-versions. But i have a scenario where my snapshot version or release version should increment automatically for each build. Should we add any custom line code in pom.. please suggest me a solution.

Related

How to halt the maven build if a release build for the same snapshot version is available in the repository?

Is there any plugin available in the community or I need to build one?
I wrote my own enforcer rule for that purpose because I could not find an "official" plugin or rule.
There's a Maven plugin that allow you to replace -SNAPSHOT versions with the corresponding release version here: https://www.mojohaus.org/versions-maven-plugin/use-releases-mojo.html
While this does not halt the build, it's a good start if you want to add the functionalilty.

Handle Build-Number for Maven Release Plugin

Say I have an artifact with version 1.0.0-SNAPSHOT (in the SVN). When I call Maven Release Plugin, I want it to build version 1.0.0-1, but leave the SVN at 1.0.0-SNAPSHOT. The next release then should be 1.0.0-2 (still with 1.0.0-SNAPSHOT in the SVN) etc.
How can I achieve this behaviour?
PS: If the build number should better be determined by a build server as Jenkins, I would also be glad to hear about that.

How does Maven decide what version of a plugin to use, when you don't specify any?

I recognized that Maven not always uses the latest version of a plugin.
For example org.codehaus.mojo:sonar-maven-plugin version 2.7 has beed released on 19th of October but on 23th of October, 2.6 was still used by Maven (mvn sonar:sonar).
I even remember some plugins, where the latest version was several minor releases above the version that Maven decided to use.
Is there any (central) index/list/database where Maven looks up what version to use? If yes, where can it be accessed manually?
I know this is an ancient thread but in the interest of posterity and accuracy: all pom.xmls logically inherit from the super POM. You can always see what your "real" pom.xml looks like by typing:
mvn help:effective-pom
The resulting pom.xml that is printed is a combination of the super POM, your pom.xml, and of course any parent POMs in the mix as well.
The super POM is provided by the org.apache.maven.model.superpom.DefaultSuperPomProvider class (https://github.com/apache/maven/blob/bce33aa2662a51d18cb00347cf2fb174dc195fb1/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java#L56-L85). The resource it loads is org/apache/maven/model/pom-4.0.0.xml (https://github.com/apache/maven/blob/bce33aa2662a51d18cb00347cf2fb174dc195fb1/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml#L23-L149).
As far as i know, this link will answer your question.
Automatic Plugin Version Resolution
When a plugin was invoked without an explicit version given in the POM
or on the command line, Maven 2.x used to pick the latest version
available where the latest version could either be a release or a
snapshot. For the sake of stability, Maven 3.x prefers the latest
release version over the latest snapshot version.
Given the threat of non-reproducible builds imposed by automatic
plugin version resolution, this feature is scheduled for removal as
far as plugin declarations in the POM are concerned. Users of Maven
3.x will find it output a warning when missing plugin versions are detected to encourage the addition of plugin versions to the POM or
one of its parent POMs. The Enforcer rule requirePluginVersions can be
used additionally check for missing plugin versions in the POM
For command line execution if a version is not specified Maven looks up the latest version from the GA (group ID/artifact ID) maven-metadata.xml file.
Example: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/maven-metadata.xml
If you're encoding command line execution of Maven goals into your builds you should specify a version for these, otherwise your builds may change as new versions of plugins are released.

Gradle Dependency Management: latest.integration vs. latest.release

I just came across a small question concerning Gradle's dependency management.
I know that I can declare dependencies using latest.integration to reference snapshots or use latest.release to reference artifacts from release builds.
My question is:
Does latest.integration exclusively and only refer the latest SNAPSHOT artifacts or will latest.integration resolve using a release artifact, if the latest release artefact has a higher version than the latest from integration?
Example:
latest snapshot artifact: 2.1
latest release artifact: 2.2
If using latest.integration, which one will be used to resolve the dependency?
If its the case that latest.integration also integrates release artifacts, by which rule can I explicitly refer to snapshot artifacts?
latest.integration resolves to latest snapshot or release, whichever is newer. There is no symbolic version for latest snapshot only (use 1.2.3-SNAPSHOT).

Maven install:? - how to create a release candidate?

Is it possible to create a release candidate from my current maven project without changing the version number in the pom.xml?
I just want to build a new maven artifact form my project with a specific version number.
For example: my current pom.xml has the version '0.0.1'. I have called mvn install to create the artifact in my local repository. Now I would like to create a second artifact with the version '0.0.1-RC1'
Is this possible from the mvn command line without changing the version number in my pom.xml?
I would advice against your suggestion of not changing the version number. One of the Maven's benefits is to keep your releases in sequence, i.e. after you have made your '0.0.1-RC1' candidate you will continue to work on the '0.0.1-RC2-SNAPSHOT' version (which may result in a '0.0.1-RELEASE').
That said, you don't have to change the version number manually. The Maven Release Plugin offers great help with this with commands such as mvn release:prepare and mvn release:perform. Also read the Maven build versions in the Maven reference manual. You may also find the discussion about Maven version scheme interesting.
As I see it you have two options:
Embrace the release plug-in. It's been designed to address this problem.
Use the versions plug-in and issue your own source code control commands.

Resources