問題描述
如何觸發Maven SCM插件根據現有目錄自動切換目標? (How to trigger Maven SCM plugin to automatically switch goals based on existing directory?)
我是 Maven 新手,遇到一個問題,我試圖根據源是否已經是自動將 SCM 插件目標從 checkout
更改為 update簽出。
誰能給我看一個代碼示例來讓它工作?這是插件配置:
<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>
參考解法
方法 1:
change 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>
Reference
https://maven.apache.org/scm/maven‑scm‑plugin/
https://maven.apache.org/scm/maven‑scm‑plugin/update‑mojo.html
方法 2:
To change the goal of the SCM plugin was inspired by Đỗ Như Vý (above).
Approach was to
- Place the goal in a property called scm.goal set to a default value ie update.
- Use a profile (bootstrap) to change the scm.goal property value from 'update' to 'checkout'.
- Activate the bootstrap profile based on missing .gitignore file.
- Place the property scm.goal in the SCM plugin goal element.
Code:
<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>
...
(by garyM、James Graham、garyM)