2016-11-07 72 views
0

我有一個pom,它可以獲得一些zip,解壓並部署裏面的5個工件(jar + pom)。maven在單個pom中部署多個文件

它看起來是這樣的:

<plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-deploy-plugin</artifactId> 
       <version>2.8.2</version> 
       <executions> 
        <execution> 
         <id>default-deploy</id> 
         <phase>none</phase> 
        </execution> 
        <execution> 
         <id>deploy-api-jar</id> 
         <phase>deploy</phase> 
         <goals> 
          <goal>deploy-file</goal> 
         </goals> 
         <configuration> 
          <file>target/xxx.jar</file> 
          <pomFile>target/xxx/pom.xml</pomFile> 
          <sources>target/xxx-sources.jar</sources> 
          <repositoryId>${nexus-repository-id}</repositoryId> 
          <url>http://${nexus.deploy.server}/${nexus-repository-path}</url> 
         </configuration> 
        </execution> 

所以我有5所執行的5件不同的文物。 它適用於第一產物,但隨後因爲它試圖重新上傳失敗:

[INFO] Uploading: http://www.zzz.com:8081/nexus/content/repositories/mobile-r/xxx/server/deployall/8.1.17/deployall-8.1.17-dependencies.dot 

它失敗,因爲400 BadRequest depedencies.dot 8.1.17已經部署。

爲什麼它會嘗試上傳每個構件之間的depedencies.dot?我可以禁用它嗎?

+0

這些文件是由maven build自己構建還是由那些文件創建的文件? – khmarbaise

+0

也許相關:http://stackoverflow.com/questions/40402597/maven-deploy-file-goal-why-does-the-first-execution-interfere-with-the-second-o –

回答

0

編輯:答案錯了

它失敗,因爲Maven的,因此您的Nexus只允許一組給定的座標中的一個神器。

所以,如果你想將它們全部部署到相同的座標,你需要給他們不同的分類器。

你想做的事情是構建腳本的高度不規則使用。 Maven假定來自單個POM的所有工件具有相同的座標(但是不同的分類器)。如果需要,可以將工件附加到項目並使用生命週期中的普通deploy:deploy任務進行上載。您可以使用build-helper-maven-plugin爲:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>1.12</version> 
    <executions> 
    <execution> 
     <id>attach-artifacts</id> 
     <phase>package</phase> 
     <goals> 
     <goal>attach-artifact</goal> 
     </goals> 
     <configuration> 
     <artifacts> 
      <artifact> 
      <file>file1</file> 
      <type>extension of your file</type> 
      <classifier>x</classifier> 
      </artifact> 
      <artifact> 
      <file>file2</file> 
      <type>extension of your file</type> 
      <classifier>y</classifier> 
      </artifact> 
      ... 
      </artifacts> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

但既然你要上傳5件間斷文物,一聚甲醛是不是你想要的,使用bash腳本的上傳,而不是(調用mvn deploy:deploy-file多次)。

+0

座標你的意思groupId:artifactId ?但他們不共享相同的座標,他們是5個不同的工件。我通過調用執行相同的bash腳本來部署文件。你不推薦這個解決方案? – orepor

+0

好吧,我錯過了使用不同文件的不同POM的部分。在這種情況下,bash文件實際上是最乾淨的解決方案(我的答案的最後一段)。你沒有一個實際的項目,所以只需上傳它們。至於爲什麼發生這種情況,JF Meier對你的問題的評論指出了正確的解釋。 – blackbuild

相關問題