1

我是 Maven 新手,遇到一个问题,我试图根据源是否已签出自动将 SCM 插件目标更改checkout更新。

谁能给我看一个代码示例来让它工作?这是插件配置:

<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>
4

2 回答 2

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

于 2016-04-01T16:15:08.273 回答
0

改变 SCM 插件的目标的灵感来自 Đỗ Như Vý(上图)。

方法是

  1. 将目标放在名为 scm.goal 的属性中,设置为默认值,即更新。
  2. 使用配置文件(引导程序)将 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>
...
于 2016-04-01T19:23:01.877 回答