繁体   English   中英

Maven部署到快照而不是发布

[英]Maven deploys to snapshot instead of release

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

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

如果其他人遇到此问题并找到现有答案并未解决他们的问题:

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

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

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

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

要进行发布,您需要使用发布插件的目标。


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

用不同的原因搞砸了这个问题...确保release-plugin检出标签,而不是一个同名的分支!

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

那是我生命中的两个小时,我将不会回来......将来我将在分支名称中添加“ - release”后缀(例如“1.9.0-release”)。

如果问题仍然存在,则可能与您在父pom中指定的maven-release-plugin版本有关。 指定maven-release-plugin的2.2.2 肯定会失败并且只会部署快照(在某些条件下尚未完全解释)。 然而,最新的插件(即从pom.xml中删除标签)可行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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