30

How to configure maven project to deploy both snapshot and releases to Nexus?

<distributionManagement>
    <repository>
        <id>InternalReleases</id>
        <name>Internal Releases</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/releases/</url>
    </repository>
    <repository>
        <id>InternalSnapshots</id>
        <name>Internal Snapshots</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/snapshots/</url>
    </repository>
</distributionManagement>

This configuration creates error in Eclipse 3.8 with m2e 1.2

Project build error: Non-parseable POM D:\Workspaces\W\Parent\pom.xml: Duplicated tag: 'repository' (position: START_TAG 
 seen ...

I want the artifact deployed to the InternalSnapshots repository when the pom's version is suffixed with -SNAPSHOT and deployed to the InternalReleases repository when it is RELEASE. This should happen using the same pom.xml file and executing the same mvn deploy command.

whyceewhite
  • 6,317
  • 7
  • 43
  • 51
Paul Verest
  • 60,022
  • 51
  • 208
  • 332

3 Answers3

44

You need to distinguish between the releases and snapshots repository. <distributionManagement> only allows one <repository> and one <snapshotRepository> child.

http://maven.apache.org/pom.html#Distribution_Management

nabcos
  • 1,074
  • 8
  • 13
  • 1
    Profiles allow one to use different sections. If you had multiple and then you could accomplish it with use of different profiles. – P. Rower Oct 11 '16 at 17:45
29

Example of pom.xml configuration

<!-- http://maven.apache.org/pom.html#Distribution_Management -->
<distributionManagement>
    <snapshotRepository>
        <id>InternalSnapshots</id>
        <name>Internal Snapshots</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
    <repository>
        <id>InternalReleases</id>
        <name>Internal Releases</name>
        <url>http://192.168.16.232:8081/nexus/content/repositories/releases/</url>
    </repository>
</distributionManagement>

Snippets for .m2/settings.xml for default Nexus installation

<server>   
    <id>thirdparty</id>   
  <username>deployment</username>
  <password>deployment123</password>
</server>
<server>
  <id>InternalReleases</id>
  <username>deployment</username>
  <password>deployment123</password>
 </server>  
<server>
  <id>InternalSnapshots</id>
  <username>deployment</username>
  <password>deployment123</password>
 </server>  
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
0

You can do both.

Add the maven-release-plugin 2.5.3

Run the following:

mvn deploy clean:release release:prepare release:perform
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
Scott Jones
  • 175
  • 2
  • 12
  • 2
    That is nice, but it requires maven and project to be already configured, and that was the salt of the question: how to configure – Paul Verest Jul 25 '17 at 15:34