Ответ 1
Вам нужно использовать profiles, вот пример pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>FooBar</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<profiles>
<profile>
<id>Foo</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>foo/id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<!-- configuration>...</configuration -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>Bar</id>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>Bar</id>
<phase>package</phase>
<goals><goal>single</goal></goals>
<!-- configuration>...</configuration -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
И вы должны вызвать maven следующим образом:
mvn package -P Foo // Only Foo
mvn package -P Bar // Only Bar
mvn package -P Foo,Bar // All (Foo and Bar)