如何觸發Maven SCM插件根據現有目錄自動切換目標? (How to trigger Maven SCM plugin to automatically switch goals based on existing directory?)


問題描述

如何觸發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

  1. Place the goal in a property called scm.goal set to a default value ie update.
  2. Use a profile (bootstrap) to change the scm.goal property value from 'update' to 'checkout'.
  3. Activate the bootstrap profile based on missing .gitignore file.
  4. 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 garyMJames GrahamgaryM)

參考文件

  1. How to trigger Maven SCM plugin to automatically switch goals based on existing directory? (CC BY‑SA 2.5/3.0/4.0)

#maven-3 #maven #maven-plugin #maven-scm






相關問題

Maven <include> wildcard cocok dengan nama folder parsial (Maven <include> wildcard match on partial folder name)

Eclipse 中使用 MAVEN 3.04 的動態 Web 應用程序 (Dynamic web application in eclipse using MAVEN 3.04)

Множныя рэпазітары Maven3 (Maven3 multiple repos)

замена ўласцівасці архетыпа maven (maven archetype property substitution)

Maven 發布和版本 Maven 插件 (Maven release and versions maven plugin)

Maven-glassfish-plugin:如何指定部署目標? (Maven-glassfish-plugin: how to specify deploy target?)

在 Maven WAR 構建中添加其他類 (Adding Additional classes in maven WAR build)

分佈式 Jenkins - Linux 上的主控和 Windows 上的從屬 - 如何配置節點特定設置 (Distributed Jenkins- Master on Linux and slave on windows- How to configure node specific setting)

如何觸發Maven SCM插件根據現有目錄自動切換目標? (How to trigger Maven SCM plugin to automatically switch goals based on existing directory?)

使用 MongoDB 存儲數據的 Java 應用程序是否需要 Maven? (Is Maven necessary for a Java application that uses MongoDB to store data?)

“el-api”在 pom.xml 中什麼時候有用? (When is "el-api" useful in pom.xml?)

無法在 JDK7 上運行 Maven 3.6.3 (Can't run Maven 3.6.3 on JDK7)







留言討論