mor mazar
mor mazar

Reputation: 1

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

Upvotes: 0

Views: 260

Answers (1)

chan07
chan07

Reputation: 11

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. You can then call the custom ant task alone in each of your profiles. Link on how to write custom ant task can be found here

Upvotes: 1

Related Questions