The following setup:
rootpom
|- parentpom
| |- projectApom
| |- projectBpom
| |- other projects poms
|- other projects poms
Each project in the hierarchy is bound by using <module> tag on its parent pom as well the parent being specified by the <parent> tag.
ProjectA and ProjectB both specify the assembly plugin using the fragment:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<mainClass>ClassToExecute</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
Now I go to the directory of the rootpom and execute:
mvn --projects parent/projectB compile assembly:single
The problem is now that projectB depends on A (and some others) so using this command assembly:single
will be applied to all the projects.
So the question goes how can I compile multiple projects (dependencies) and only assemble a single one (the last)?
Simple: don't use assembly:single
on the command line but bind an execution of the maven-assembly-plugin
to a particular phase for the project you want.
If you only want to assemble only project B then in B's POM, you would have:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>ClassToExecute</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
This way, running mvn --projects parent/projectB clean package
will package only B.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.