2010-11-04 167 views
6

我在嘗試設置項目以部署到內部聯繫存儲庫時目前遇到問題。由於我對整個Maven都比較陌生,因此我認爲在如何建立分銷管理方面我並沒有真正理解的東西。爲什麼Maven(錯誤地?)將我的SNAPSHOT部署到版本庫和快照庫?

基本問題是,當我執行「mvn deploy」時,工件已成功部署到快照存儲庫,但Maven也試圖將其部署到發佈存儲庫,因爲它應該是失敗的。我對當前配置的理解是,它不應該將其部署到發佈存儲庫。

我已經包含了各種配置元素下方,但如果我其實應該是管理與配置文件中的部分,以便建立快照只定義,併發布版本只定義我想知道。

對此的任何幫助/澄清將不勝感激。

我在我的POM配電管理的以下內容:

<distributionManagement> 
<repository> 
    <id>internal-releases</id> 
    <name>Internal Releases</name> 
    <url>http://localhost:8081/nexus/content/repositories/releases</url> 
</repository> 
<snapshotRepository> 
    <id>internal-snapshots</id> 
    <name>Internal Snapshots</name> 
    <url>http://localhost:8081/nexus/content/repositories/snapshots</url> 
</snapshotRepository> 
</distributionManagement> 

其他地方我有以下設置爲允許使用這些存儲庫中獲得文物POM:

<repositories> 
<repository> 
    <id>internal-releases</id> 
    <url>http://localhost:8081/nexus/content/repositories/releases</url> 
    <snapshots><enabled>false</enabled></snapshots> 
</repository> 
<repository> 
    <id>internal-snapshots</id> 
    <url>http://localhost:8081/nexus/content/repositories/snapshots</url> 
    <snapshots><enabled>true</enabled></snapshots> 
</repository> 
<!-- other repos, etc, etc --> 
</repositories> 

我在我的settings.xml中有正確的設置來提供證書,以便能夠發佈到我的計算機上運行的此測試nexus實例,並且實際上它正在成功部署快照。

的問題是,它也試圖部署快照釋放存儲庫,它被配置爲禁止快照。

從「MVN部署」輸出包括以下內容:

[INFO] [deploy:deploy {execution: default-deploy}] 
[INFO] Retrieving previous build number from internal-snapshots 
Uploading: http://localhost:8081/nexus/content/repositories/snapshots/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-8.war 
405K uploaded (service-1.0.0-20101104.170338-8.war) 
[INFO] Retrieving previous metadata from internal-snapshots 
[INFO] Uploading repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' 
[INFO] Retrieving previous metadata from internal-snapshots 
[INFO] Uploading repository metadata for: 'artifact com.internal:service' 
[INFO] Uploading project information for service 1.0.0-20101104.170338-8 
[INFO] [deploy:deploy-file {execution: default}] 
[INFO] Retrieving previous build number from remote-repository 
[INFO] repository metadata for: 'snapshot com.internal:service:1.0.0-SNAPSHOT' could not be found on repository: remote-repository, so will be created 
Uploading: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD ERROR 
[INFO] ------------------------------------------------------------------------ 
[INFO] Error deploying artifact: Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar. Return code is: 400 

Nexus的日誌包含以下(因爲我希望它):

jvm 1 | 2010-11-04 13:03:39 INFO [p-759477796-118] - o.s.n.p.m.m.M2Repos~   - Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository 
jvm 1 | 2010-11-04 13:03:39 ERROR [p-759477796-118] - o.s.n.r.ContentPlex~   - Got exception during processing request "PUT http://localhost:8081/nexus/content/repositories/releases/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar": Storing of item releases:/com/internal/service/1.0.0-SNAPSHOT/service-1.0.0-20101104.170338-1.jar is forbidden by Maven Repository policy. Because releases is a RELEASE repository 

回答

5

所以最好的線索其實原來是正確的日誌在我的眼前。我曾經想過的唯一的工件是由我正在使用的POM生成的.war,但是您會注意到在日誌中,Maven試圖部署到該版本的工件實際上是一個.jar。

這是不夠的指針(即提供尖上有人Maven用戶郵件列表)來尋找,最終發現有人列入部署階段以下額外的配置。

<plugin> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-deploy-plugin</artifactId> 
<executions> 
<execution> 
    <phase>deploy</phase> 
    <goals> 
     <goal>deploy-file</goal> 
    </goals> 
    <configuration> 
     <packaging>jar</packaging> 
     <generatePom>true</generatePom> 
     <url>${project.distributionManagement.repository.url}</url> 
     <artifactId>${project.artifactId}</artifactId> 
     <groupId>${project.groupId}</groupId> 
     <version>${project.version}</version> 
     <file>${project.build.directory}/${project.build.finalName}.jar</file> 
    </configuration> 
    </execution> 
</executions> 
</plugin> 

請注意,這實際上是直接引用${project.distributionManagement.repository.url}。另外,這種配置有些誤導,應該通過war插件的attachClasses屬性來完成。

2

難道是因爲神器版本沒有-SNAPSHOT後綴?

+0

的神器版本是1.0.0,快照,因此沒有。 – imaginaryboy 2010-11-06 02:52:56

+1

這個答案應該是一個評論,我想 – 2016-03-11 16:11:17

9
  1. 定義下列財產在你的POM Maven的部署,插件

    <deployFileUrl>${project.distributionManagement.snapshotRepository.url}</deployFileUrl> 
    
  2. 更改配置如下:

    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-deploy-plugin</artifactId> 
        <version>2.5</version> 
        <configuration> 
         <skip>true</skip> 
        </configuration> 
        <executions> 
         <execution> 
          <phase>deploy</phase> 
          <configuration> 
           <packaging>jar</packaging> 
           <generatePom>true</generatePom> 
           <url>${deployFileUrl}</url> 
           <artifactId>${project.artifactId}</artifactId> 
           <groupId>${project.groupId}</groupId> 
           <version>${project.version}</version> 
           <file>${project.build.directory}/${project.build.finalName}.jar</file> 
          </configuration> 
          <goals> 
           <goal>deploy-file</goal> 
          </goals> 
         </execution> 
        </executions> 
    </plugin> 
    
  3. 添加以下配置文件設定與存儲庫中的deployFileUrl財產網址

    <profiles> 
        <profile> 
         <id>release-mode</id> 
         <properties> 
          <deployFileUrl>${project.distributionManagement.repository.url}</deployFileUrl> 
         </properties> 
        </profile> 
    </profiles> 
    
  4. 最後調用此配置文件中的maven釋放小插件

    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-release-plugin</artifactId> 
        <version>2.0-beta-9</version> 
        <configuration> 
         <releaseProfiles>release-mode</releaseProfiles> 
        </configuration> 
    </plugin> 
    
相關問題