简体   繁体   English

如何最小化Maven POM.XML文件

[英]How can I minimize Maven POM.XML file

I am new to Maven and I'm trying to make some improvements on an existing project. 我是Maven的新手,我正在尝试对现有项目进行一些改进。 I am sure there's an efficient way to build a profile with parameters or somehow reduce the lines size of the tasks. 我敢肯定,有一种有效的方法可以用参数构建概要文件,或者以某种方式减小任务的行数。

The current profiles are built like this one: 当前的配置文件是这样构建的:

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

Since every profile has these tasks (and there are more than shown here) I though of using a generic code. 由于每个配置文件都具有这些任务(并且这里显示的内容不止如此),因此我使用了通用代码。 Did any of you have experienced something like that? 你们有没有经历过类似的事情?

Thanks. 谢谢。

You can do that by writing your own custom Ant task(passing the profile ID also as an argument) and externalising the path to a property file. 您可以通过编写自己的自定义Ant任务(也将概要文件ID作为参数传递)并外部化属性文件的路径来实现。 You can then call the custom ant task alone in each of your profiles. 然后,您可以在每个配置文件中单独调用自定义ant任务。 Link on how to write custom ant task can be found here 有关如何编写自定义ant任务的链接,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM