如何最小化Maven POM.XML文件

时间:2014-11-03 09:03:29

标签: java maven parameters pom.xml maven-profiles

我是Maven的新手,我试图对现有项目进行一些改进。 我确信这是一种有效的方法来构建带参数的配置文件或以某种方式减少任务的行大小。

当前的配置文件就像这样构建:

    <profile>
        <id>green</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.smart.soapui</groupId>
                    <artifactId>soapui-pro-maven-plugin</artifactId>
                    <version>5.1.2</version>
                    <configuration>
                        <projectFile>resources/api/API-NEW-automation.xml</projectFile>
                        <junitReport>true</junitReport>
                        <reportName>sanity-api</reportName>
                        <printReport>true</printReport>
                        <reportFormat>HTML</reportFormat>
                        <outputFolder>target</outputFolder>
                        <projectProperties>
                            <value>message=Running API Sanity test</value>
                        </projectProperties>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <configuration>
                                <tasks>
                                    <delete file="src/main/resources/config.properties" />
                                    <copy file="src/main/resources/green/config.properties"
                                        tofile="src/main/resources/config.properties" />
                                    <delete file="src/main/resources/TestData.properties" />
                                    <copy file="src/main/resources/green/TestData.properties"
                                        tofile="src/main/resources/TestData.properties" />
                                    <delete file="src/main/resources/loginTestData.csv" />
                                    <copy file="src/main/resources/green/loginTestData.csv"
                                        tofile="src/main/resources/loginTestData.csv" />
                                    <delete file="src/main/resources/browsingTestData.csv" />
                                    <copy file="src/main/resources/green/browsingTestData.csv"
                                        tofile="src/main/resources/browsingTestData.csv" />
                                    <delete file="src/main/resources/endUsersDetails.csv" />
                                    <copy file="src/main/resources/green/endUsersDetails.csv"
                                        tofile="src/main/resources/endUsersDetails.csv" />
                                </tasks>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

由于每个配置文件都有这些任务(并且这里有更多内容),我使用的是通用代码。你们有没有经历过这样的事情?

感谢。

1 个答案:

答案 0 :(得分:1)

您可以通过编写自己的自定义Ant任务(将配置文件ID也作为参数传递)和外部化属性文件的路径来实现。然后,您可以在每个配置文件中单独调用自定义ant任务。可以找到有关如何编写自定义ant任务的链接here