如何忽略子模块中的Maven配置文件? [英] How to ignore maven profiles in child module?

查看:219
本文介绍了如何忽略子模块中的Maven配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行简单的流程,我有6个配置文件:

生成模式,解包战争,运行码头,测试,停车码头,start-stop-app

当我在mvn目标/属性中声明测试配置文件时,该测试配置文件将在其他子模块上运行: * clean --activate-profiles generate-schema,unpack-war,start-stop-app,test --project apm-tests,apm-tests \ apm-adapter-tests验证.*

如何使子模块仅运行测试并跳过其余配置文件(generate-schema等)?

父pom示例:

    <?xml version="1.0" encoding="UTF-8"?>
    <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">

    <project>

        <parent>
            <artifactId>apm-root</artifactId>
            <groupId>com.apm.platform</groupId>
            <version>12.50.9999-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>

        <artifactId>apm-tests</artifactId>

        <packaging>pom</packaging>

        <modules>
            <module>alm-coverage-report</module>
        </modules>

            <profile>
                <id>test</id>
                <build>
                    <plugins>
                        <plugin>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <skipTests>true</skipTests>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>

    <profile>
                <id>generate-schema</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>

                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <id>generate-schema</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>java</goal>
                                    </goals>
                                    <configuration>
                                        <mainClass>com.apm.platform.siteadmin.setup.Setup</mainClass>
                                        <classpathScope>test</classpathScope>
                                        <systemProperties>
                                            <systemProperty>
                                                <key>InstallationFolder</key>
                                                <value>${tests.runtime}</value>
                                            </systemProperty>
                                            <systemProperty>
                                                <key>RepositoryFolder</key>
                                                <value>${tests.runtime}/repository</value>
                                            </systemProperty>
                                            <systemProperty>
                                                <key>LogFolder</key>
                                                <value>${tests.runtime}/log</value>
                                            </systemProperty>
                                            <systemProperty>
                                                <key>mercury.td.sa_config_dir</key>
                                                <value>${tests.runtime}</value>
                                            </systemProperty>
                                            <systemProperty>
                                                <key>CreateLabProject</key>
                                                <value>${create.lab.project}</value>
                                            </systemProperty>
                                        </systemProperties>
                                        <arguments>
                                            <argument>--auto</argument>
                                            <argument>${db.schema}</argument>
                                        </arguments>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>start-jetty</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-maven-plugin</artifactId>
                            <configuration>
                                <war>${unpacked.war.directory}</war>
                                <contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
                                <webApp>
                                    <contextPath>/qcbin</contextPath>
                                </webApp>
                                <systemProperties>
                                    <systemProperty>
                                        <name>mercury.td.sa_config_dir</name>
                                        <value>${tests.runtime}</value>
                                    </systemProperty>
                                    <systemProperty>
                                        <name>jetty.port</name>
                                        <value>${jetty.start.port}</value>
                                    </systemProperty>
                                </systemProperties>
                                <stopPort>${jetty.stop.port}</stopPort>
                                <stopKey>STOP</stopKey>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>start-jetty</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>deploy-war</goal>
                                    </goals>
                                    <configuration>
                                        <scanIntervalSeconds>0</scanIntervalSeconds>
                                        <daemon>false</daemon>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>

          <profile>
            <id>start-stop-app</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <configuration>
                            <war>${unpacked.war.directory}</war>
                            <contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
                            <webApp>
                                <contextPath>/qcbin</contextPath>
                            </webApp>
                            <systemProperties>
                                <systemProperty>
                                    <name>mercury.td.sa_config_dir</name>
                                    <value>${tests.runtime}</value>
                                </systemProperty>
                                <systemProperty>
                                    <name>jetty.port</name>
                                    <value>${jetty.start.port}</value>
                                </systemProperty>
                            </systemProperties>
                            <stopPort>${jetty.stop.port}</stopPort>
                            <stopKey>STOP</stopKey>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-jetty</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>deploy-war</goal>
                                </goals>
                                <configuration>
                                    <scanIntervalSeconds>0</scanIntervalSeconds>
                                    <daemon>true</daemon>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-jetty</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

            <profile>
                <id>stop-jetty</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-maven-plugin</artifactId>
                            <configuration>
                                <stopPort>${jetty.stop.port}</stopPort>
                                <stopKey>STOP</stopKey>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>stop-jetty</id>
                                    <phase>post-integration-test</phase>
                                    <goals>
                                        <goal>stop</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>


            <!-- create project profile -->
            <profile>
                <id>create-project</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <properties>
                    <serverUrl>http://localhost:${env.JETTY_PORT}/qcbin</serverUrl>
                    <saUser>sa</saUser>
                    <projectUserName>restuser</projectUserName>
                    <domain>UNITEST</domain>
                    <project>resttest</project>
                    <overwrite>true</overwrite>
                </properties>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>com.apm.maven.plugins.alm</groupId>
                            <artifactId>rest-create-project</artifactId>
                            <version>1.0.8.2</version>
                            <executions>
                                <execution>
                                    <id>clean-create</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>create-project</goal>
                                    </goals>
                                    <configuration>
                                        <serverUrl>${serverUrl}</serverUrl>
                                        <saUser>${saUser}</saUser>
                                        <projectUserName>${projectUserName}</projectUserName>
                                        <projectUserPassword>${projectUserPassword}</projectUserPassword>
                                        <domain>${domain}</domain>
                                        <project>${project}</project>
                                        <overwrite>${overwrite}</overwrite>
                                        <extensions>${extensions}</extensions>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>

        </profiles>
    </project>

子模块pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <groupId>com.apm.platform</groupId>
        <artifactId>apm-tests</artifactId>
        <version>12.50.9999-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>apm-adapter-tests</artifactId>
    <packaging>pom</packaging>


    <properties>
        <tests.version>${project.version}</tests.version>
    </properties>

    <dependencies>
       <dependency>
                      <groupId>com.apm.platform</groupId>
                      <artifactId>apm-synchronizer-adapter-testing</artifactId>
                      <version>1.10.9999-SNAPSHOT</version>
                      <classifier>test-jar-with-dependencies</classifier>

       </dependency>
    </dependencies>

    <profiles>
        <!--run integration tests using surefire plugin -->
        <profile>
            <id>itest</id>

            <build>
                <plugins>
                    <plugin>

                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${surefire.version}</version>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-report-plugin</artifactId>
                                <version>${surefire.version}</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>integration-test</id>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <excludedGroups>com.apm.platform.CAPQIntegrationTestCategory</excludedGroups>
                                    <skipTests>false</skipTests>
                                    <excludes>
                                      <exclude>junit/**/*.java</exclude>
                                      <exclude>org/**/*.java</exclude>
                                    </excludes>
                                    <argLine>-Xmx1536m</argLine>

                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>sync-adapter</id>
            <dependencies>
                <dependency>
                      <groupId>com.apm.platform</groupId>
                      <artifactId>apm-synchronizer-adapter-testing</artifactId>
                      <version>1.10.9999-SNAPSHOT</version>
                      <classifier>test-jar-with-dependencies</classifier>
                      <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <!--copies dependent classes from test-jars-->
                                <id>unpack-tests</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.apm.platform</groupId>
                                            <artifactId>agm-synchronizer-adapter-testing</artifactId>
                                            <version>1.10.9999-SNAPSHOT</version>
                                            <classifier>test-jar-with-dependencies</classifier>
                                            <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

13:03:13 2015-11-30 13:03:14.422:INFO:oejs.Server:main:已启动

@ 207555ms 13:03:13 [INFO]启动了Jetty服务器13:03:13 [INFO]

13:03:13 [INFO] --- maven-surefire-plugin:2.16:test(集成测试)

@ apm-tests --- 13:03:14 [INFO] 没有要运行的测试. 13:03:14 [INFO]

13:03:14 [INFO] --- jetty-maven-plugin:9.1.3.v20140225:stop

(stop-jetty)@ apm-tests --- 13:03:14 [INFO] 13:03:14 [INFO] ---

maven-source-plugin:2.2.1:jar-no-fork(attach-sources)@ alm-tests ---

2015-11-30 13:03:14

13:03:14.820:INFO:oejs.ServerConnector:ShutdownMonitor:已停止

ServerConnector @ 4c8d3b5c {HTTP/1.1} {0.0.0.0:5729} 13:03:14 [INFO]

13:03:14 [INFO] --- maven-source-plugin:2.2.1:test-jar-no-fork

(attach-test-sources)@ alm-tests --- 13:03:14 [INFO]

13:03:14 [INFO]

--------------- 13:03:14 [INFO]构建agm-synchronizer-adapter-testing

12.50.9999-SNAPSHOT 13:03:14 [INFO] ------------

解决方案

请允许我阐明一些也可以潜在解决您问题的要点,因为我发现您的方法可能缺少一些好的做法:

  • 配置文件应用于可选/附加行为,而默认版本应始终为SUCCESSFUL而不考虑已声明的配置文件
  • 如果应该执行测试的模块并且测试仅位于该模块中,则应仅在该特定模块中声明配置文件,而不能在其父模块中声明配置文件.此外,在这种情况下,也不需要配置文件,因为它是默认的模块行为.但是,仅在模块中定义了配置文件,即使从父级执行整个构建,也可以将其关闭.要关闭配置文件,只需使用!-批注:mvn clean install -P!profile-name,如官方文档

    我还建议再次阅读Maven官方文档的配置文件陷阱",

    此外,要跳过作为父构建的一部分的模块,还可以在父POM中定义一个配置文件,该配置文件重新声明模块部分并省略要跳过的模块,如其他answer .

        ...
       <modules>
          <module>module1</module>
          <module>module2</module>  
          ...
      </modules>
      ...
      <profiles>
         <profile>
           <id>skip-some-modules-profile</id>
              <modules>
                <module>module1</module>
                ...
                <module>module-integration-test</module>
              </modules> 
          </profile>
      </profiles>
     ...
    

    这样,您可以根据要执行的配置文件来构建特殊的多模块构建.

    总而言之,请注意,过多地使用没有提供任何实际伪像的配置文件和模块可能会影响您的构建可读性和维护性.

    I want to run the simple flow, I have 6 profiles:

    generate-schema,unpack-war,run-jetty,test,stop-jetty,start-stop-app

    the test profile will run on a different child module when I declare it in the mvn goals/properties: * clean --activate-profiles generate-schema,unpack-war,start-stop-app,test --projects apm-tests,apm-tests\apm-adapter-tests verify.*

    How can I make the child module run only the tests and skip the rest of the profiles (generate-schema and etc.) ?

    Parent pom sample:

        <?xml version="1.0" encoding="UTF-8"?>
        <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">
    
        <project>
    
            <parent>
                <artifactId>apm-root</artifactId>
                <groupId>com.apm.platform</groupId>
                <version>12.50.9999-SNAPSHOT</version>
            </parent>
            <modelVersion>4.0.0</modelVersion>
    
            <artifactId>apm-tests</artifactId>
    
            <packaging>pom</packaging>
    
            <modules>
                <module>alm-coverage-report</module>
            </modules>
    
                <profile>
                    <id>test</id>
                    <build>
                        <plugins>
                            <plugin>
                                <artifactId>maven-surefire-plugin</artifactId>
                                <configuration>
                                    <skipTests>true</skipTests>
                                </configuration>
                            </plugin>
                        </plugins>
                    </build>
                </profile>
    
        <profile>
                    <id>generate-schema</id>
                    <activation>
                        <activeByDefault>false</activeByDefault>
                    </activation>
    
                    <build>
                        <plugins>
                            <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>exec-maven-plugin</artifactId>
                                <executions>
                                    <execution>
                                        <id>generate-schema</id>
                                        <phase>pre-integration-test</phase>
                                        <goals>
                                            <goal>java</goal>
                                        </goals>
                                        <configuration>
                                            <mainClass>com.apm.platform.siteadmin.setup.Setup</mainClass>
                                            <classpathScope>test</classpathScope>
                                            <systemProperties>
                                                <systemProperty>
                                                    <key>InstallationFolder</key>
                                                    <value>${tests.runtime}</value>
                                                </systemProperty>
                                                <systemProperty>
                                                    <key>RepositoryFolder</key>
                                                    <value>${tests.runtime}/repository</value>
                                                </systemProperty>
                                                <systemProperty>
                                                    <key>LogFolder</key>
                                                    <value>${tests.runtime}/log</value>
                                                </systemProperty>
                                                <systemProperty>
                                                    <key>mercury.td.sa_config_dir</key>
                                                    <value>${tests.runtime}</value>
                                                </systemProperty>
                                                <systemProperty>
                                                    <key>CreateLabProject</key>
                                                    <value>${create.lab.project}</value>
                                                </systemProperty>
                                            </systemProperties>
                                            <arguments>
                                                <argument>--auto</argument>
                                                <argument>${db.schema}</argument>
                                            </arguments>
                                        </configuration>
                                    </execution>
                                </executions>
                            </plugin>
                        </plugins>
                    </build>
                </profile>
                <profile>
                    <id>start-jetty</id>
                    <activation>
                        <activeByDefault>false</activeByDefault>
                    </activation>
                    <build>
                        <plugins>
                            <plugin>
                                <groupId>org.eclipse.jetty</groupId>
                                <artifactId>jetty-maven-plugin</artifactId>
                                <configuration>
                                    <war>${unpacked.war.directory}</war>
                                    <contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
                                    <webApp>
                                        <contextPath>/qcbin</contextPath>
                                    </webApp>
                                    <systemProperties>
                                        <systemProperty>
                                            <name>mercury.td.sa_config_dir</name>
                                            <value>${tests.runtime}</value>
                                        </systemProperty>
                                        <systemProperty>
                                            <name>jetty.port</name>
                                            <value>${jetty.start.port}</value>
                                        </systemProperty>
                                    </systemProperties>
                                    <stopPort>${jetty.stop.port}</stopPort>
                                    <stopKey>STOP</stopKey>
                                </configuration>
                                <executions>
                                    <execution>
                                        <id>start-jetty</id>
                                        <phase>pre-integration-test</phase>
                                        <goals>
                                            <goal>deploy-war</goal>
                                        </goals>
                                        <configuration>
                                            <scanIntervalSeconds>0</scanIntervalSeconds>
                                            <daemon>false</daemon>
                                        </configuration>
                                    </execution>
                                </executions>
                            </plugin>
                        </plugins>
                    </build>
                </profile>
    
              <profile>
                <id>start-stop-app</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.eclipse.jetty</groupId>
                            <artifactId>jetty-maven-plugin</artifactId>
                            <configuration>
                                <war>${unpacked.war.directory}</war>
                                <contextXml>${unpacked.war.directory}/WEB-INF/jetty-web.xml</contextXml>
                                <webApp>
                                    <contextPath>/qcbin</contextPath>
                                </webApp>
                                <systemProperties>
                                    <systemProperty>
                                        <name>mercury.td.sa_config_dir</name>
                                        <value>${tests.runtime}</value>
                                    </systemProperty>
                                    <systemProperty>
                                        <name>jetty.port</name>
                                        <value>${jetty.start.port}</value>
                                    </systemProperty>
                                </systemProperties>
                                <stopPort>${jetty.stop.port}</stopPort>
                                <stopKey>STOP</stopKey>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>start-jetty</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>deploy-war</goal>
                                    </goals>
                                    <configuration>
                                        <scanIntervalSeconds>0</scanIntervalSeconds>
                                        <daemon>true</daemon>
                                    </configuration>
                                </execution>
                                <execution>
                                    <id>stop-jetty</id>
                                    <phase>post-integration-test</phase>
                                    <goals>
                                        <goal>stop</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
    
                <profile>
                    <id>stop-jetty</id>
                    <activation>
                        <activeByDefault>false</activeByDefault>
                    </activation>
                    <build>
                        <plugins>
                            <plugin>
                                <groupId>org.eclipse.jetty</groupId>
                                <artifactId>jetty-maven-plugin</artifactId>
                                <configuration>
                                    <stopPort>${jetty.stop.port}</stopPort>
                                    <stopKey>STOP</stopKey>
                                </configuration>
                                <executions>
                                    <execution>
                                        <id>stop-jetty</id>
                                        <phase>post-integration-test</phase>
                                        <goals>
                                            <goal>stop</goal>
                                        </goals>
                                    </execution>
                                </executions>
                            </plugin>
                        </plugins>
                    </build>
                </profile>
    
    
                <!-- create project profile -->
                <profile>
                    <id>create-project</id>
                    <activation>
                        <activeByDefault>false</activeByDefault>
                    </activation>
                    <properties>
                        <serverUrl>http://localhost:${env.JETTY_PORT}/qcbin</serverUrl>
                        <saUser>sa</saUser>
                        <projectUserName>restuser</projectUserName>
                        <domain>UNITEST</domain>
                        <project>resttest</project>
                        <overwrite>true</overwrite>
                    </properties>
                    <build>
                        <plugins>
                            <plugin>
                                <groupId>com.apm.maven.plugins.alm</groupId>
                                <artifactId>rest-create-project</artifactId>
                                <version>1.0.8.2</version>
                                <executions>
                                    <execution>
                                        <id>clean-create</id>
                                        <phase>pre-integration-test</phase>
                                        <goals>
                                            <goal>create-project</goal>
                                        </goals>
                                        <configuration>
                                            <serverUrl>${serverUrl}</serverUrl>
                                            <saUser>${saUser}</saUser>
                                            <projectUserName>${projectUserName}</projectUserName>
                                            <projectUserPassword>${projectUserPassword}</projectUserPassword>
                                            <domain>${domain}</domain>
                                            <project>${project}</project>
                                            <overwrite>${overwrite}</overwrite>
                                            <extensions>${extensions}</extensions>
                                        </configuration>
                                    </execution>
                                </executions>
                            </plugin>
                        </plugins>
                    </build>
                </profile>
    
            </profiles>
        </project>
    

    Child module pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <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">
        <parent>
            <groupId>com.apm.platform</groupId>
            <artifactId>apm-tests</artifactId>
            <version>12.50.9999-SNAPSHOT</version>
        </parent>
    
        <modelVersion>4.0.0</modelVersion>
    
        <artifactId>apm-adapter-tests</artifactId>
        <packaging>pom</packaging>
    
    
        <properties>
            <tests.version>${project.version}</tests.version>
        </properties>
    
        <dependencies>
           <dependency>
                          <groupId>com.apm.platform</groupId>
                          <artifactId>apm-synchronizer-adapter-testing</artifactId>
                          <version>1.10.9999-SNAPSHOT</version>
                          <classifier>test-jar-with-dependencies</classifier>
    
           </dependency>
        </dependencies>
    
        <profiles>
            <!--run integration tests using surefire plugin -->
            <profile>
                <id>itest</id>
    
                <build>
                    <plugins>
                        <plugin>
    
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>${surefire.version}</version>
                            <dependencies>
                                <dependency>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-surefire-report-plugin</artifactId>
                                    <version>${surefire.version}</version>
                                </dependency>
                            </dependencies>
                            <executions>
                                <execution>
                                    <id>integration-test</id>
                                    <phase>integration-test</phase>
                                    <goals>
                                        <goal>test</goal>
                                    </goals>
                                    <configuration>
                                        <excludedGroups>com.apm.platform.CAPQIntegrationTestCategory</excludedGroups>
                                        <skipTests>false</skipTests>
                                        <excludes>
                                          <exclude>junit/**/*.java</exclude>
                                          <exclude>org/**/*.java</exclude>
                                        </excludes>
                                        <argLine>-Xmx1536m</argLine>
    
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
    
            <profile>
                <id>sync-adapter</id>
                <dependencies>
                    <dependency>
                          <groupId>com.apm.platform</groupId>
                          <artifactId>apm-synchronizer-adapter-testing</artifactId>
                          <version>1.10.9999-SNAPSHOT</version>
                          <classifier>test-jar-with-dependencies</classifier>
                          <scope>test</scope>
                    </dependency>
                </dependencies>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <executions>
                                <execution>
                                    <!--copies dependent classes from test-jars-->
                                    <id>unpack-tests</id>
                                    <phase>pre-integration-test</phase>
                                    <goals>
                                        <goal>unpack</goal>
                                    </goals>
                                    <configuration>
                                        <artifactItems>
                                            <artifactItem>
                                                <groupId>com.apm.platform</groupId>
                                                <artifactId>agm-synchronizer-adapter-testing</artifactId>
                                                <version>1.10.9999-SNAPSHOT</version>
                                                <classifier>test-jar-with-dependencies</classifier>
                                                <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
                                            </artifactItem>
                                        </artifactItems>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    </project>
    

    13:03:13 2015-11-30 13:03:14.422:INFO:oejs.Server:main: Started

    @207555ms 13:03:13 [INFO] Started Jetty Server 13:03:13 [INFO]

    13:03:13 [INFO] --- maven-surefire-plugin:2.16:test (integration-test)

    @ apm-tests --- 13:03:14 [INFO] No tests to run. 13:03:14 [INFO]

    13:03:14 [INFO] --- jetty-maven-plugin:9.1.3.v20140225:stop

    (stop-jetty) @ apm-tests --- 13:03:14 [INFO] 13:03:14 [INFO] ---

    maven-source-plugin:2.2.1:jar-no-fork (attach-sources) @ alm-tests ---

    13:03:14 2015-11-30

    13:03:14.820:INFO:oejs.ServerConnector:ShutdownMonitor: Stopped

    ServerConnector@4c8d3b5c{HTTP/1.1}{0.0.0.0:5729} 13:03:14 [INFO]

    13:03:14 [INFO] --- maven-source-plugin:2.2.1:test-jar-no-fork

    (attach-test-sources) @ alm-tests --- 13:03:14 [INFO]

    13:03:14 [INFO]

    --------------- 13:03:14 [INFO] Building agm-synchronizer-adapter-testing

    12.50.9999-SNAPSHOT 13:03:14 [INFO] ------------

    解决方案

    Please let me clarify few important points which could also potentially solve your issue since I see some good practices may be missing in your approach:

    • Profiles should be used for optional/additional behaviors, while default build should always be SUCCESSFUL regardless of the declared profiles
    • If a module is supposed to execute tests and tests are only located in that module, then the profile should only be declared in that specific module and not in its parent. Moreover, in such a case a profile would also not be required since it would be the default module behavior. However, having a profile defined only in a module would allow you to switch it off even when executing the whole build from the parent. To switch off a profile simply use the ! or the - annotation: mvn clean install -P!profile-name as explained in the official documentation here. That will allow to ignore maven profiles in child module (to come to your questions) if the profile was only declared in that module.

    You can apply the same concept to the generate-schema action: is it required in all modules? Probably not, then you can declare the profile only on the specific module requiring it and then switch it on/off as above (if by default should be on, then declare the profile as active by default).

    Concerning jetty, integration tests requiring jetty should also be part of the same module, so that the module's build would follow the classic flow: start/test/stop. If you really need to have start, test and stop in different modules, then you can follow explanation on our previous question, here.

    I would also suggest to go through the Profile Pitfalls of the Maven official documentation, again, here for a better understanding of profile usage and misuses.

    Additionally, if of any help, you can even skip an entire module build as part of a multimodule maven build, using the command line -pl option. Check mvn -help for further details. As such you could supply the list of modules to build. Since maven 3.2.1 you can also supply the list of modules to skip as following: mvn -pl !module-to-skip install.

    When using the ! notation for skipping profiles or modules, beware that it is also a special character for bash in linux, hence put it between single quotes (mvn -pl'!module-to-skip' install). The same doesn't work on Windows however, where double quotes should be used instead (mvn -pl "!module-to-skip" install`).

    Additionally, to skip modules as part of the parent build, you could also define a profile in your parent POM which re-declares the modules section and omit the modules you want to skip, as explained in this other answer.

        ...
       <modules>
          <module>module1</module>
          <module>module2</module>  
          ...
      </modules>
      ...
      <profiles>
         <profile>
           <id>skip-some-modules-profile</id>
              <modules>
                <module>module1</module>
                ...
                <module>module-integration-test</module>
              </modules> 
          </profile>
      </profiles>
     ...
    

    As such, you could craft a special multimodule build depending on the profile you want to execute.

    All in all, beware that playing too much with profiles and modules which don't deliver any real artefact may affect your build readability and maintenance.

    这篇关于如何忽略子模块中的Maven配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆