Maven deploys to snapshot instead of release

27,909

Solution 1

<repository>
    <id>nexus</id><!--etc-->
</repository>
<snapshotRepository>
    <id>nexus</id><!--etc-->
</snapshotRepository>
<!-- etc -->
<repositories>
    <repository>
        <id>nexus</id>
        <!-- etc -->
    </repository>
</repositories>

This is the problem, you are using the same id for three different repositories. Maven manages these repositories by ID, so each ID must be unique! E.g. use "nexus-releases", "nexus-snapshots" and "nexus".

Solution 2

In case anyone else is having this problem and find the existing answers do not solve their issues:

There have been a handful of bugs which mean that release:prepare does not commit to the git repository before creating the release tag. This means that the version number in the pom files that the release:perform finds contains -SNAPSHOT and the deployer will try to release to the snapshot repository.

Here is the most recent defect responsible for this behavior: MRELEASE-875 (affects 2.5, fixed in 2.5.1)

Solution 3

The POM shows the version number to be a SNAPSHOT version. So if you ran mvn deploy with the POM in this state, it would naturally deploy a snapshot to the snapshots repository.

To do a release, you need to use the goals of the release plugin.


On the other hand, maybe you already know this, and the real answer is in Sean Patrick Floyd's answer.

Solution 4

Fell foul of this problem with a different cause... make sure that the release-plugin is checking out a tag, and not a branch with the same name!

I just fell foul of this... I created a branch called "1.9.0" in which to do my release, and then ran mvn release:prepare which also created a "1.9.0" tag. When mvn release:perform ran it did a git checkout of "1.9.0, and ended up picking up the HEAD of the 1.9.0 branch, which, of course, had a SNAPSHOT in it (1.10-SNAPSHOT).

That's two hours of my life I won't get back... In future I shall be adding a "-release" suffix to the branch name (eg "1.9.0-release").

Share:
27,909
Leon Roy
Author by

Leon Roy

Updated on July 12, 2020

Comments

  • Leon Roy
    Leon Roy almost 4 years

    I'm trying to release a project using maven but instead of releasing to the Releases repository it puts it in our Snapshots repo.

    My pom looks like:

    <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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.my.profiler</groupId>
    <artifactId>profilerlib</artifactId>
    <name>Profiler Lib</name>
    <version>1.0.2-SNAPSHOT</version>
    <description>Profiler Library</description>
    <scm>
        <connection>scm:svn:https://svn.example.com/my-project/profilerlib/trunk
        </connection>
        <developerConnection>scm:svn:https://svn.example.com/my-project/profilerlib/trunk
        </developerConnection>
    </scm>
    <distributionManagement>
        <!-- Publish the versioned releases here -->
        <repository>
            <id>nexus</id>
            <name>nexus</name>
            <url>http://repo.example.com:8081/nexus/content/repositories/releases
            </url>
        </repository>
        <!-- Publish the versioned releases here -->
        <snapshotRepository>
            <id>nexus</id>
            <name>nexus</name>
            <url>http://repo.example.com:8081/nexus/content/repositories/snapshots
            </url>
        </snapshotRepository>
    </distributionManagement>
    <!-- download artifacts from this repo -->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>EXAMPLE Public Repository</name>
            <url>http://repo.example.com:8081/nexus/content/groups/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <dependencies>
        ...
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <tagBase>https://svn.example.com/my-project/profilerlib/tags
                    </tagBase>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <powermock.version>1.4.6</powermock.version>
    </properties>
    </project>
    
  • Sean Patrick Floyd
    Sean Patrick Floyd almost 13 years
    Haha, I overlooked the obvious (+1)!!
  • Leon Roy
    Leon Roy almost 13 years
    I'm running: mvn release:prepare release:perform NOT mvn deploy. From what I understand, the release plugin should remove the -SNAPSHOT suffix before deploying, no?
  • Leon Roy
    Leon Roy almost 13 years
    Thanks for the tip, I tried that but I'm still seeing the same problem. Would the full Maven output help?
  • Sean Patrick Floyd
    Sean Patrick Floyd almost 13 years
    @user932509 you should run prepare and perform in two separate steps, because I doubt that prepare changes the version of the running execution artifact (that would be evil)
  • Leon Roy
    Leon Roy almost 13 years
    Run it separately as well. Same issue. According to this prepare does change the version: stackoverflow.com/questions/810957/…
  • Ken
    Ken about 10 years
    why is this the accepted answer if it didn't solve the problem?
  • Sean Patrick Floyd
    Sean Patrick Floyd about 10 years
    @Ken both answers are valid, they just show two different aspects of what the problem may be. perhaps the two together solved the problem?
  • Alice Purcell
    Alice Purcell over 9 years
    This was exactly my problem, thanks! For some reason Maven was picking up the broken 2.5 release; forcing it to choose 2.5.1 (mvnrepository.com/artifact/org.apache.maven.plugins/…) by specifying the version in the POM sorted it out.
  • boly38
    boly38 almost 9 years
    Just confirm that ! thanks a lots. I found an help page that is showing 2.5 version of maven-release-plugin. I just send an email on the ML to ask them to update this page.