14

I am unable to release a snapshot version of an artifact which I build using maven to nexus. The version of my artifact states 1.0.0-SNAPSHOT.

I can execute mvn clean install without an issue. But when I try to deploy using mvn deploy , I get the following error :

Return code is: 400, ReasonPhrase: Repository version policy: RELEASE does not allow version: 1.0.0-20161019.214318-1. -> [Help 1]

According to what I was able to find out was that maven3 adds the timestamp instead of the SNAPSHOT suffix on the artifact that I want to deploy. The <uniqueVersion> tag of maven is not supported in maven3. What is the approach that I need to take to deploy these artifacts using mvn deploy command.

Updated : pom.xml

   <distributionManagement>
    <repository>
      <id>my-nexus-snapshots</id>
      <name>Internal Snapshot Releases</name>
      <url>http://localhost:9999/repository/maven-snapshots/</url>
    </repository>
    <snapshotRepository>
      <id>my-nexus-releases</id>
      <name>Internal Releases</name>
      <url>http://localhost:9999/repository/maven-releases/</url>
    </snapshotRepository>
  </distributionManagement>

settings.xml

    <server>
        <id>my-nexus-snapshots</id>
        <username>user</username>
        <password>user123</password>
    </server>
    <server>
        <id>my-nexus-releases</id>
        <username>user</username>
        <password>user123</password>
    </server>
hYk
  • 764
  • 1
  • 8
  • 21
  • nexus has the repository snapshot where you only can deploy artifact with snapshot version and repository releases where you only deploy artifact with release version. if you want deploy in nexus as release you need before change de artifact vesion as 1.0.0-RELEASE or 1.0.0 and next to do deploy. use maven version plugin to change the artifact version. – johnnymnmonic Oct 19 '16 at 22:04
  • I would like to keep snapshot versions as 1.0.0-SNAPSHOT and released versions as 1.0.0. Is this possible to do ? – hYk Oct 20 '16 at 01:42

2 Answers2

13

Usually, your nexus has separate repositories "snapshots" and "releases". SNAPSHOT versions are deployed to the former, non-SNAPSHOT versions to the latter. For deployment, these repositories have to be specified by you. You can do this by adding the distributionManagement section to your pom. There you can define specific targets for both targets.

<distributionManagement>
  <repository>
    <id>releases</id>
    <name>releases</name>
    <url>http://somerepo:8081/nexus/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
    <id>snapshots</id>
    <name>snapshots</name>
    <url>http://somerepo:8081/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
</distributionManagement>
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Yes, I have the same setup in my pom.xml. But when I execute "mvn deploy" I get that error – hYk Oct 20 '16 at 14:53
  • And you really checked this line by line that you did not confuse a SNAPSHOT repository with a release repository? Some options might be case sensitive. – J Fabian Meier Oct 20 '16 at 14:55
  • 1
    Thank you for your question edit: You actually DID confuse the two repositories. Just rename to and vice versa. – J Fabian Meier Oct 20 '16 at 14:56
  • When I execute "mvn deploy" how does it know whether it should deploy to snapshot repo or released repo ? Isnt it based on the "-SNAPSHOT" suffix of the artifact ? – hYk Oct 20 '16 at 14:57
  • Yeah, everything was mixed up in my pom.xml file. Thanks! – hYk Oct 20 '16 at 17:10
1

If you are using Gradle it can be done in your repositories settings.
Just add the maven-snapshots url

For example:

 repositories {
        maven {
            url = 'http://nexus.something.com/repository/maven-central/'
        }
        maven {
            url = 'http://nexus.something.com/repository/maven-releases/'
        }
        maven {
            url = 'http://nexus.something.com/repository/maven-snapshots/'
        }
    }
Dias Abdraimov
  • 1,027
  • 12
  • 11