如何触发Maven SCM插件根据现有目录自动切换目标?

时间:2016-04-01 15:50:11

标签: maven maven-3 maven-plugin maven-scm

我是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>

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

方法是

  1. 将目标放在名为scm.goal的属性中,将其设置为默认值 即更新。
  2. 使用配置文件(引导程序)更改scm.goal属性值 '更新'到'结帐'。
  3. 根据缺少的.gitignore文件激活引导程序配置文件。
  4. 将属性scm.goal放在SCM插件中 目标要素。
  5. 代码:

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