18

I've been trying to figure this out for a few days now, I have looked all over stackoverflow and none of the answers fix my issue. I am trying to have the <version> in my Pom.xml.

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>maven.Test</groupId>
  <artifactId>Hello</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>jar</packaging>

<distributionManagement>
    <repository>
        <id>Artifactory</id>
        <name>Artifactory-releases</name>
        <url>${publish.location}</url>
    </repository>
    <snapshotRepository>
        <id>Artifactory</id>
        <name>Artifactory-snapshots</name>
        <url>${publish.location}</url>
    </snapshotRepository>
</distributionManagement>

</project>

I am using Maven 3.3.3 currently, I have looked into SCM plugins but those don't seem to be working. I know you can have it increment versions by setting them as variables but that isn't ideal for my developers. When a build is run using the command mvn deploy I want the version to auto increment to 1.0.1 and so on.

EDIT:

I tried doing the maven release but am running into an issue which may be on me. For the release plugin are there edits I need to make to my Pom.xml? I ran mvn release:prepare but ran into this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3
.2:prepare (default-cli) on project Hello: Unable to check for local modificatio
ns
[ERROR] Provider message:
[ERROR] The svn command failed.
[ERROR] Command output:
[ERROR] 'svn' is not recognized as an internal or external command,
[ERROR] operable program or batch file.
Macauley
  • 379
  • 2
  • 6
  • 17
  • You cannot make releases when your local code has uncommitted changes or snapshot dependencies. Maybe what you are looking for are unique snapshots? Set the version in your POM to something that ends in `-SNAPSHOT` and then the deploy command should add a timestamp-like suffix when deploying. – rec Dec 28 '15 at 23:31
  • Btw. the error you see above is because you don't seem to have "svn" (Subversion) installed as a command line tool. – rec Dec 29 '15 at 00:00
  • Okay so I need to commit all my changes, and have the svn command line installed to have the release plugin working properly? – Macauley Dec 29 '15 at 17:09
  • Yes. And you cannot have any -SNAPSHOT dependencies in your module. But as I said: you should consider if what you want are unique SNAPSHOTs as done by the deploy plugin or proper releases as done using the release plugin. Cf. http://stackoverflow.com/questions/9554688/maven-versioning-best-practices – rec Dec 29 '15 at 23:06

3 Answers3

9

Picking up @rec's answer:

Use:

$ mvn -B release:prepare release:perform

Note the -B. It will run in batch mode and the release plugin won't ask at all.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
6

Versions are increased as part of the "release" workflow. Check out the Maven Release Plugin. In short:

$ mvn release:prepare
$ mvn release:perform

The release plugin will increment the version but ask you for confirmation, so it is not fully automatic.

rec
  • 10,340
  • 3
  • 29
  • 43
  • You can set the release plugin to silent mode, which will automatically increment the version number – TrueDub Dec 28 '15 at 17:56
  • @TrueDub I was looking for a silent mode, but I didn't find one (http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html) - can you tell us how to activate it? – rec Dec 28 '15 at 18:08
  • Have you tried to use `mvn -q ...`? Or what do you mean by `silent mode..`..? – khmarbaise Dec 28 '15 at 18:45
  • That page you've linked to doesn't mention it, but this page - http://maven.apache.org/maven-release/maven-release-plugin/examples/non-interactive-release.html - describes it. You use -B or --batch-mode – TrueDub Dec 28 '15 at 19:15
  • I followed this advice and ran into an issue, see my edit above – Macauley Dec 28 '15 at 20:05
3

@Michael-O has answered the original question. However, the error 'svn' is not recognized as an internal or external command, is occurred because Maven can not execute svn command line. To solve this problems add svn in your PATH environment variable. Usually if you install sliksvn client, It will add the path for you. In addition to @Michael-O, you may have to include username and password.

mvn -B -Dpassword=**** -Dusername=**** clean release:prepare release:perform 

If the subversion server certificate is rejected, you have to add the server certificate to svn configuration. The easiest way is by executing svn from command line and accept the certificate when prompted by the svn client.

Harun
  • 667
  • 7
  • 13