0

I would like to execute commands that will allow to build WAR files depending on execution id

My original WAR file is generated with a lot of submodules. If I need to test and build for testing only my module, I would like to build a "lighter" WAR by excluding a few jars since the build takes a lot of time. Instead would like to build a lighter WAR given some flags / commands.

As seen in the code below, I intend to skip a few dependencies/ JARs if executed with a command.

I believe you could run something similar to

mvn deploy <prefix>:<goal>:<execution-id>

as seen in Run a single Maven plugin execution? or Maven maven-exec-plugin multiple execution configurations but I have no luck so far.

Below is my pom configuration

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>exclude-few-deps</id>
                    <goals><goal>war</goal></goals>
                    <phase>package</phase>
                    <configuration>
                        <failOnMissingWebXml>true</failOnMissingWebXml>
                        <webXml>src/main/resources/web.xml</webXml>
                        <packagingExcludes>
                            WEB-INF/lib/student-*.jar,
                            WEB-INF/lib/library-*.jar
                        </packagingExcludes>
                    </configuration>
                </execution>
                <execution>
                    <id>default-cli</id>
                    <goals><goal>war</goal></goals>
                    <phase>package</phase>
                    <configuration>
                        <failOnMissingWebXml>true</failOnMissingWebXml>
                        <webXml>src/main/resources/web.xml</webXml>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I am unsure which command should I execute to select the execution with id

mvn war:war:@exclude-few-deps

or

mvn clean package:@exclude-few-deps

I also tried to play around with maven profiles but seems like I am unable to get this working.

Any help is appreciated.

Dexter
  • 1,621
  • 3
  • 18
  • 38
  • 1
    Creating different war with different dependencies you have to create different modules which is simpler than using profiles and execution id which also avoid packageExcludes etc. Furthermore create the resulting war within a simple `mvn clean package`.... – khmarbaise Dec 17 '17 at 07:35
  • You might get better solutions/answers if you told what you need to achieve with this exclusion process so why you do this? What khmarbaise commented might be the correct solution but without knowing your problem better it is hard to tell. – pirho Dec 17 '17 at 09:26
  • @khmarbaise and pirho, I have updated the question to add my reason for my need as per your suggestion. – Dexter Dec 17 '17 at 19:25

0 Answers0