2013-03-19 87 views
1

我想用maven-deploy-plugin部署一個文件。目前,我在我的POM如下:maven-deploy-plugin repository

 <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-deploy-plugin</artifactId> 
      <version>2.7</version> 
      <executions> 
       <execution> 
        <id>deploy-features-xml</id> 
        <phase>deploy</phase> 
        <goals> 
         <goal>deploy-file</goal> 
        </goals> 
        <configuration> 
         <repositoryId>${project.distributionManagement.snapshotRepository.id}</repositoryId> 
         <url>${project.distributionManagement.snapshotRepository.url}</url> 
         <groupId>${project.groupId}</groupId> 
         <artifactId>${project.artifactId}</artifactId> 
         <version>${project.version}</version> 
         <file>features.xml</file> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

我想基於版本快照和版本庫之間切換。如果項目版本爲1-SNAPSHOT,則應將文件部署到快照存儲庫,如果項目是1.0版,則應將文件部署到發佈存儲庫。但是maven-deploy-plugin會對它進行硬編碼嗎?

回答

2

我最終的解決方案是使用build-helper-maven-plugin和maven-resources-plugin。這個設置意味着隨着jar和pom和項目將部署一個xml文件,這個文件可以作爲project/xml/features在maven repo中引用。

相關POM插件:

 <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>build-helper-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>attach-artifacts</id> 
        <phase>package</phase> 
        <goals> 
         <goal>attach-artifact</goal> 
        </goals> 
        <configuration> 
         <artifacts> 
          <artifact> 
           <file>target/features/features.xml</file> 
           <type>xml</type> 
           <classifier>features</classifier> 
          </artifact> 
         </artifacts> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>copy-features</id> 
        <phase>generate-resources</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>target/features</outputDirectory> 
         <resources> 
          <resource> 
           <directory>src/main/features</directory> 
           <filtering>true</filtering> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
+0

很棒的回答。我結束了使用你的解決方案。看起來我們都在上傳Karaf features.xml – 2014-11-14 18:14:52

4

此行爲在默認情況下已經給出。但你應該使用repository manager。你可以通過mvn部署簡單地部署一個工件,通常在SNAPSHOT版本發佈的情況下,SNAPSHOT版本將進入SNAPSHOT版本庫,它將發佈到發佈版本庫。

+0

我不知道它在默認情況下給出的。該項目已經部署了一個罐子和POM。是否有另一種自動部署XML文件的方式? – 2013-03-19 09:59:34