2016-04-01 48 views
1

我是Maven的新手,遇到了一個問題,我試圖根據源是否已簽出,自動將SCM插件目標從checkout更改爲更新如何觸發Maven SCM插件根據現有目錄自動切換目標?

任何人都可以告訴我一個代碼示例,讓它工作嗎? 這是插件配置:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-scm-plugin</artifactId> 
    <version>1.9.4</version> 
     <executions> 
      <execution> 
       <phase>generate-sources</phase> 
       <goals> 
        <goal>checkout</goal> 
       </goals> 
       <configuration> 
        <connectionType>developerConnection</connectionType> 
        <scmVersion>master</scmVersion> 
        <scmVersionType>branch</scmVersionType> 
        <checkoutDirectory>${project.basedir}/src</checkoutDirectory> 
        <workingDirectory>${project.basedir}/src</workingDirectory> 
       </configuration> 
      </execution> 
     </executions> 
</plugin> 

回答

0

變化goal

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-scm-plugin</artifactId> 
    <version>1.9.4</version> 
     <executions> 
      <execution> 
       <phase>generate-sources</phase> 
       <goals> 
        <goal>update</goal> 
       </goals> 
       <configuration> 
        <connectionType>developerConnection</connectionType> 
        <scmVersion>master</scmVersion> 
        <scmVersionType>branch</scmVersionType> 
        <checkoutDirectory>${project.basedir}/src</checkoutDirectory> 
        <workingDirectory>${project.basedir}/src</workingDirectory> 
       </configuration> 
      </execution> 
     </executions> 
</plugin> 

參考
https://maven.apache.org/scm/maven-scm-plugin/
https://maven.apache.org/scm/maven-scm-plugin/update-mojo.html

+0

由於做的,如果該項目不使用Google Checkout自舉更新失敗。這是如何根據結帳是否完成而在結帳和更新之間自動切換的?我澄清了這個問題。 – garyM

+0

此鏈接可能對您有所幫助:https://maven.apache.org/scm/maven-scm-plugin/examples/bootstrapping-with-pom.html –

+0

謝謝,我想自動切換。我編輯了該問題以澄清 – garyM

0

要更改SCM插件的目標是通過DJO NHU啓發Vý(上圖)。

方法是

  1. 放置在設置爲默認值即 更新的屬性稱爲scm.goal的目標。
  2. 使用配置文件(bootstrap)將scm.goal屬性值從 'update'更改爲'checkout'。
  3. 激活基於缺少.gitignore文件的引導配置文件。
  4. 將屬性scm.goal放置在SCM插件 目標元素中。

代碼:

<properties> 
     <scm.dest.path>${project.basedir}/src</scm.dest.path> 
     <scm.goal>update</scm.goal> 
    </properties> 

    <profiles> 
     <profile> 
      <id>bootstrap</id> 
      <activation> 
       <file> 
        <missing>./src/.gitignore</missing> 
       </file> 
      </activation> 
      <properties> 
       <scm.goal>checkout</scm.goal> 
      </properties> 
     </profile> 
    </profiles> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-scm-plugin</artifactId> 
       <version>1.9.4</version> 
       <executions> 
        <execution> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>${scm.goal}</goal> 
         </goals> 
         <configuration> 
          <connectionType>developerConnection</connectionType> 
          <scmVersion>master</scmVersion> 
          <scmVersionType>branch</scmVersionType> 
          <checkoutDirectory>${scm.dest.path}</checkoutDirectory> 
          <workingDirectory>${scm.dest.path}</workingDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 
...