0

我是 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>

由于每个配置文件都有这些任务(这里显示的不止这些),我想使用通用代码。你们有没有人经历过这样的事情?

谢谢。

4

1 回答 1

1

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

于 2014-11-03T09:31:00.007 回答