Maven部署到快照而不是发布

时间:2011-09-07 10:48:38

标签: java maven release snapshot

我正在尝试使用maven发布一个项目,但不是发布到Releases存储库,而是将它放在我们的Snapshots存储库中。

我的pom看起来像:

<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>

5 个答案:

答案 0 :(得分:24)

如果其他人遇到此问题并且发现现有答案无法解决问题:

有一些错误意味着release:prepare在创建发布标记之前不会提交到git存储库。这意味着release:perform找到的pom文件中的版本号包含-SNAPSHOT,部署者将尝试发布到快照存储库。

以下是导致此行为的最新缺陷:MRELEASE-875(影响2.5,已在2.5.1中修复)

答案 1 :(得分:15)

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

这是问题所在,您对三个不同的存储库使用相同的ID。 Maven通过ID管理这些存储库,因此每个ID必须是唯一的!例如。使用“nexus-releases”,“nexus-snapshots”和“nexus”。

答案 2 :(得分:12)

POM显示版本号为SNAPSHOT版本。因此,如果您在此状态下使用POM运行mvn deploy,它自然会将快照部署到快照存储库。

要进行发布,您需要使用release plugin

的目标

另一方面,也许你已经知道这一点了,真正的答案是肖恩·帕特里克·弗洛伊德的回答。

答案 3 :(得分:2)

以不同的原因弄清楚这个问题...确保release-plugin检出标签,而不是同名的分支!

我刚刚犯了这个...我创建了一个名为&#34; 1.9.0&#34;在我的发布中,然后运行mvn release:prepare也创建了一个&#34; 1.9.0&#34;标签。当mvn发布:执行运行时,它执行了&#34; 1.9.0的git checkout,最终获得了1.9.0分支的HEAD,当然,其中有一个SNAPSHOT(1.10-SNAPSHOT)。

我生命中的两个小时我都没有回来......将来我会添加一个&#34; -release&#34;分支名称的后缀(例如&#34; 1.9.0-release&#34;)。

答案 4 :(得分:0)

如果问题仍然存在,则可能与您在父pom中指定的maven-release-plugin的版本有关。 绝对指定2.2.2的maven-release-plugin失败,并且只会部署快照(在某些条件下有待充分说明)。但是,最新的插件(即,从pom.xml中删除标签)有效。

相关问题