简体   繁体   中英

Maven deploys to snapshot instead of release

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>

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)

<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! Eg use "nexus-releases", "nexus-snapshots" and "nexus".

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.

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").

If the problems persist they're probably related to the version of maven-release-plugin you are specifying in the parent pom. Specifying 2.2.2 of the maven-release-plugin definitely fails and will only deploy a snapshot (under certain conditions yet to be fully explained). The latest plugin (ie. remove the tag from the pom.xml) however works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM