[英]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.