maven:pom中多个配置文件的顺序

时间:2012-02-14 06:51:54

标签: java maven axis2

我有一个定义了3个配置文件的pom。 我想要:

  1. 始终在所有其他人(如果需要)之前运行“生成”个人资料
  2. 基于例如属性运行dev / normal profile pom snip:

    <profiles>
        <profile>
            <id>generate-axis-stubs</id>
            <activation>
                <file>
                    <missing>target/generated-sources</missing>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.axis2</groupId>
                        <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                        <configuration>
                            <generateServerSide>true</generateServerSide>
                            <generateServicesXml>true</generateServicesXml>
                            <outputDirectory>target/generated-sources</outputDirectory>
                            <packageName>${genclasses.package}</packageName>
                        </configuration>
                        <executions>
                            <execution>
                                <id>ESISGeneralSigningStatusUpdate_V1_0</id>
                                <goals>
                                    <goal>wsdl2code</goal>
                                </goals>
                                <phase>generate-sources</phase>
                                <configuration>
                                    <wsdlFile>${wsdl.src.dir}/ESISGeneralSigningStatusUpdate_V1_0.wsdl</wsdlFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    
        <profile>
            <id>normal</id>
            <activation>
                <property>
                    <name>!env</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>**/JdbcDataServiceImplTest.java</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    
    <!-- This profile should be used to run tests that requires access to DB It is activated in case system variable env=dev -->
    <profile>
        <id>run-db-tests</id>
        <activation>
            <property>
                <name>env</name>
                <value>dev</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                        </includes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    
  3. 问题是在干净编译时,这恰好每隔一次就能正常工作。 我启用了-X调试并比较了输出。 - 失败了,+是有效的。

    @@ -1551,6 +1551,10 @@
     [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, 
    generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, 
    package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
     [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
     [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    +[DEBUG] Using mirror nexus (http://nexus.edb.com/nexus/content/groups/public/) for apache.snapshots (http://repository.apache.org/snapshots).
    +[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
    +[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
    +[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
     [DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
     [DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
     [DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
    @@ -1563,7 +1567,7 @@
     [DEBUG] === PROJECT BUILD PLAN ================================================
     [DEBUG] Project:       com.edb.esign:gssWsServer:2.3-SNAPSHOT
     [DEBUG] Dependencies (collect): []
    -[DEBUG] Dependencies (resolve): [compile]
    +[DEBUG] Dependencies (resolve): [compile, test]
     [DEBUG] Repositories (dependencies): [nexus (http://nexus.edb.com/nexus/content/groups/public/, releases+snapshots)]
     [DEBUG] Repositories (plugins)     : [nexus (http://nexus.edb.com/nexus/content/groups/public/, releases+snapshots)]
     [DEBUG] -----------------------------------------------------------------------
    

    当我运行帮助时:active-profile

    1. 成功后显示: 以下配置文件处于活动状态:

      • 正常(来源:pom)
      • nexus(来源:settings.xml)
    2. 失败后显示: 以下配置文件处于活动状态:

      • generate-axis-stubs(来源:pom)
      • 正常(来源:pom)
      • nexus(来源:settings.xml)
    3. 如果我手动清理它然后编译 - 它一直有效。但为什么它不能始终用于干净的编译? 谢谢!

1 个答案:

答案 0 :(得分:2)

因为配置文件只评估一次。所以问题不是clean compile,而是启动Maven时文件夹target/generated-sources是否存在。

如果存在,clean compile必须失败,因为clean会删除文件夹,但Maven不再关心。