如何使用主pom文件签出Web应用程序的所有模块并构建所有模块

时间:2012-03-05 18:25:22

标签: maven build-automation multi-module build-management

我有一个依赖于几个模块的Web应用程序。所以为了构建它,我有一个主pom.xml文件。我想要这个pom文件做的是检查所有模块。 下面是我的pom文件。

        <executions>
        <execution>
                    <id>check-out-project1</id>
                    <phase>generate-sources</phase>
                    <goals>
                    <goal>checkout</goal>
                    </goals>
                    <configuration>    
                    <checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
                    <connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
                    <!--<developerConnection>scm:svn:svn://svnserver/svn/module1/trunk</developerConnection>!-->
                    <username>username</username>                             
                    <password>password</password>             
                    </configuration>
         </execution>

          <execution>
                    <id>check-out-project2</id>
                    <phase>generate-sources</phase>
                    <goals>
                    <goal>checkout</goal>
                    </goals>
                    <configuration>    
                    <checkoutDirectory>${project.build.directory}/module1</checkoutDirectory>
                    <connectionUrl>scm:svn:svn://svnserver/svn/module1/trunk</connectionUrl>
                          <username>username</username>                             
                          <password>password</password>             
                    </configuration>
            </execution>
        </executions>

我尝试了 mvn scm:checkout mvn scm:checkout -check-out-project1 ,但它给了我错误:   无法运行checkout命令:无法加载scm提供程序。您需要定义connectionUrl参数。

我不明白为什么会发生这种情况,因为我已经在pom文件中定义了connectionUrl参数,我希望得到的想法是将pom文件配置为能够同时签出多个项目时间。请让我知道我在这里做错了什么,在此先感谢。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的情况,我找到了一个解决方案 - 使用你的代码:D-可以在我的电脑上运行:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.xxx.internet</groupId>
    <artifactId>my-app</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>Maven Quick Start Archetype</name>
    <url>http://www.mySite.de</url>
    <scm>
        <connection>scm:svn:http://svn-repo-adress:8080/repo/myDirectory</connection>
        <developerConnection>http://svn-repo-adress:8080/repo/myDirectory</developerConnection>
        <tag>HEAD</tag>
        <url>http://svn-repo-adress:8080/repo/myDirectory</url>
    </scm>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-scm-plugin</artifactId>
               <version>1.6</version>
               <configuration>
                 <goals>checkout</goals>
                 <checkoutDirectory>target/checkout</checkoutDirectory>
                 <username>username</username>
                 <password>userpassword</password>
               </configuration>
              <executions>
                <execution>
                    <id>check-out-project1</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>checkout</goal>
                    </goals>
                </execution>
            </executions>   
            </plugin>
        </plugins>
     </build>
</project>

在cmd控制台上执行“mvn scm:checkout”后,它确实有效。

我认为重要的一点是在执行构建标记之前首先添加scm标记。

答案 1 :(得分:2)

我发现,如果将每个结帐放入自己的<execution> ... </execution>并在其中的位置,则单个<configuration> ... </configuration>可用。例如:

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-plugin</artifactId>
            <version>1.9.4</version>
            <executions>
                <execution>
                    <id>repo1-dependency</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <connectionUrl>${my.repo1.url}</connectionUrl>
                        <scmVersion>${my.repo1.branch}</scmVersion>
                        <scmVersionType>branch</scmVersionType>
                        <checkoutDirectory>${project.build.directory}/${my.repo1}-${my.repo1.branch}</checkoutDirectory>
                    </configuration>
                    <goals>
                        <goal>checkout</goal>
                    </goals>
                </execution>
                <execution>
                    <id>repo2-dependency</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <connectionUrl>${my.repo2.url}</connectionUrl>
                        <scmVersion>${my.repo2.branch}</scmVersion>
                        <scmVersionType>branch</scmVersionType>
                        <checkoutDirectory>${project.build.directory}/${my.repo2}-${my.repo2.branch}</checkoutDirectory>
                    </configuration>
                    <goals>
                        <goal>checkout</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>