如何使Maven Release克隆Git子模块?

15
我有一个包含一些Git子模块的Maven项目。一切都很正常,直到我执行release:prepare或者release:perform命令时,这些命令所执行的干净检查不包含子模块(换句话说,git clone不是递归的)。
我找不到一种合适的方式来配置Maven调用git clone命令时带上--recursive选项。
我考虑使用SCM提供程序配置 (http://maven.apache.org/scm/git.html) 或者直接在pom.xml中配置发布插件,但无法使其工作。
谢谢。

1
据我所知,无法使用子模块进行工作。在这种情况下,Maven 假定所有内容都在一个 git 存储库中,而不是多个存储库中。我认为,如果您有多个 git 存储库,则可以独立发布不同的 Maven 模块。 - khmarbaise
2个回答

24

以下是没有脚本的相同解决方案:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <inherited>false</inherited> <!-- only execute these in the parent -->
    <executions>
        <execution>
            <id>git submodule update</id>
            <phase>initialize</phase>
            <configuration>
                <executable>git</executable>
                <arguments>
                    <argument>submodule</argument>
                    <argument>update</argument>
                    <argument>--init</argument>
                    <argument>--recursive</argument>
                </arguments>
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这非常有帮助,正是我所需要的。感谢您的发布! - AO_
谢谢,克隆工作是这样的。但是当mvn release:prepare尝试提交子模块pom时失败了。我收到了[ERROR] fatal: Pathspec 'basic-utils\pom.xml' is in submodule 'basic-utils'。 - Ionut Bilica

14

我刚刚添加了以下插件:

<!-- This is a workaround to get submodules working with the maven release plugin -->
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <phase>initialize</phase>
            <id>invoke build</id>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>git</executable>
        <arguments>
           <argument>submodule</argument>
           <argument>update</argument>
           <argument>--init</argument>
           <argument>--recursive</argument>
        </arguments>
    </configuration>
</plugin>

11
你可以使用"git submodule update --init --recursive"代替update.sh。 - cornz
1
不,你不能这样做。如果你真的能在那里写一个命令,那就太聪明了... exec-maven-plugin 找不到某些东西(对于显然存在的东西说“未找到”)。你需要使用 shell 脚本(在使用 chmod +x /path/to/script.sh 命令使其可执行之后)。 - Kalle Richter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接