2011-09-07 72 views
18

我試圖使用maven發佈項目,但不是發佈到發佈存儲庫,而是將其放入我們的快照存儲庫。Maven部署到快照而不是發佈

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

您是否發現這個問題的解決方案? – mihn

+0

很久以前,但是IIRC我必須在我的pom.xml中定義單獨的版本庫和snapShotRepository ID值 –

回答

11
<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」。

+0

感謝您的提示,我試過了,但我仍然看到同樣的問題。 Maven輸出幫助? –

+3

爲什麼這是公認的答案,如果它沒有解決問題? – Ken

+0

@Ken兩個答案都是有效的,他們只是展示了問題的兩個不同方面。也許這兩個人一起解決了這個問題? –

12

POM顯示版本號爲SNAPSHOT版本。因此,如果您在POM處於此狀態下運行mvn deploy,它自然會將快照部署到快照存儲庫。

要做一個發佈,你需要使用release plugin的目標。


另一方面,也許你已經知道這一點,真正的答案是在肖恩帕特里克弗洛伊德的回答。

+0

哈哈,我忽視了顯而易見的(+1)! –

+0

我正在運行:mvn release:prepare release:執行NOT mvn deploy。 據我所知,釋放插件應該在部署前刪除-SNAPSHOT後綴,否? –

+1

@ user932509你應該運行準備和執行兩個單獨的步驟,因爲我懷疑準備改變正在運行的執行工件的版本(這將是邪惡的) –

19

萬一別人是有這個問題,並找出現有的答案,不解決他們的問題:

已經有這意味着release:prepare不承諾Git倉庫創建釋放標籤之前的錯誤一小撮。這意味着release:perform找到的pom文件中的版本號包含-SNAPSHOT,並且部署者將嘗試釋放到快照存儲庫。

這裏是負責這一行爲最近的缺陷:MRELEASE-875(影響2.5,固定在2.5.1)

+0

這正是我的問題,謝謝!出於某種原因,Maven正在撿起破碎的2.5版本;強制它通過指定POM中的版本對其進行排序來選擇2.5.1(http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-release-plugin/2.5.1)。 –

+0

只需確認!十分感謝。我找到了[幫助頁面](https://maven.apache.org/guides/mini/guide-releasing.html),它顯示了'maven-release-plugin'的2.5版本。我只是在[ML](http://mail-archives.apache.org/mod_mbox/maven-users/201507.mbox/thread)上發送一封電子郵件,要求他們更新此頁面。 – boly38

2

這個問題由其他原因引起下跌犯規......確保剝離插件簽出標籤,而不是具有相同名稱的分支!

我剛纔犯了這個......我創建了一個名爲「1.9.0」的分支,在其中執行我的發佈,然後運行mvn發佈:準備創建一個「1.9.0」標籤。當mvn發佈時:執行run時,它做了一個「1.9.0的git checkout」,最終拿起了1.9.0分支的HEAD,當然這裏有一個SNAPSHOT(1.10-SNAPSHOT)

這是我一生中的兩個小時我不會回來......未來我會在分支名稱中添加一個「-release」後綴(例如「1.9.0-release」)