2011-06-21 106 views
7

我正在使用maven-antrun-plugin與Ant進行一堆工作,最終導致一個zip文件。我想將zip文件部署到我們的maven服務器(Artifactory)。 Maven-antrun部分按預期工作併成功創建zip文件;然而,部署失敗,出現以下錯誤信息:如何部署使用maven-antrun-plugin創建的zip文件?

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy (default-deploy) on project projectname: The packaging for this project did not assign a file to the build artifact

我的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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.company.division</groupId> 
    <artifactId>projectname</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <parent> 
     <groupId>com.company.product</groupId> 
     <artifactId>parentproject</artifactId> 
     <version>1.0.0</version> 
    </parent> 

    <distributionManagement> 
     <snapshotRepository> 
      <id>artifactory</id> 
      <name>artifactory-snapshots</name> 
      <url>http://localartifactoryserver/artifactory/libs-snapshot-local</url> 
      <uniqueVersion>false</uniqueVersion> 
     </snapshotRepository> 
    </distributionManagement> 

    <dependencies> 
     <!-- Some dependencies... --> 
    </dependencies> 

    <build> 
     <plugins> 
      <!-- Compiler plugin --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.6</source> 
        <target>1.6</target> 
        <encoding>UTF8</encoding> 
        <optimize>true</optimize> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.6</version> 
       <executions> 
        <execution> 
         <id>compile</id> 
         <phase>compile</phase> 
         <configuration> 
          <target> 
           <!-- Do lots of other stuff with Ant. --> 

           <!-- Create a zip file. --> 
           <zip basedir="mydir" destfile="${WORKSPACE}/MyZip.zip" /> 
          </target> 
         </configuration> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-deploy-plugin</artifactId> 
       <version>2.6</version> 
       <configuration> 
        <groupId>${project.groupId}</groupId> 
        <artifactId>${project.artifactId}</artifactId> 
        <version>${project.version}</version> 
        <packaging>zip</packaging> 
        <file>MyZip.zip</file> 
        <url>${project.distributionManagement.snapshotRepository.url}</url> 
       </configuration> 
       </plugin> 
     </plugins> 
    </build> 
</project> 

當我調用這個(從父POM)與mvn -U -pl projectname clean deploy期間我得到上述錯誤部署階段。有誰知道我做錯了什麼或我該如何解決這個問題?

回答

10

爲我工作的解決方案(我不知道這是否是理想的,它似乎相當的hackish)是切換到deploy:deploy-file目標:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-deploy-plugin</artifactId> 
    <version>2.6</version> 
    <goals> 
     <goal>deploy-file</goal> 
    </goals> 
    <configuration> 
     <repositoryId>artifactory</repositoryId> 
     <packaging>zip</packaging> 
     <generatePom>true</generatePom> 
     <url>${project.distributionManagement.snapshotRepository.url}</url> 
     <artifactId>${project.artifactId}</artifactId> 
     <groupId>${project.groupId}</groupId> 
     <version>${project.version}</version> 
     <file>${WORKSPACE}/MyZip.zip</file> 
    </configuration> 
</plugin> 

,並明確調用它:

mvn -U -X -pl projectname clean install deploy:deploy-file 
+0

假設您的項目爲' pom',必須注意的是,如果您以這種方式部署工件,則此類項目的傳遞依賴性將不會被解決(稍後將由其他項目解決)。 – carlspring

+0

什麼將解決將是神器本身。 – carlspring

+0

挽救生命。我不得不在命令行上執行此操作。很高興知道如何在pom.xml文件中執行此操作。 –

相關問題