I use package to have Maven generate the target JAR-file, and the dependency:build-classpath to generate the cp.txt listing all of the dependency JARs, that I don't want bundled into the target JAR:
mvn package dependency:build-classpath
Is there a way to make the classpath building happen together with the packaging automatically -- without me explicitly requesting both on command-line?
The command below executes the
build-classpathgoal of the mavendependencyplugin:But when with the command below you actually instruct maven to pass from all the phases, up to
packagephase, on the default lifecycle (to whichpackagephase belongs). When maven passes from these phases it executes all the attached plugin goals:However, maven does not by default attach the
dependency:build-classpathgoal to any phase (though it does with some other goals depending on type of packaging). You need to explicitly do this, just by declaring the plugin goal to thepom.xml(also providing the corresponding configuration):Maven will then attach the above goal to the
generate-sourcesphase (which is the goal's default phase) and when that phase comes, thedependency:build-classpathplugin goal will execute.Conclusion:
Q: How to automatically process multiple "goals"?
A: You declare these goals to
pom.xml(and optionally override the default each goal attaches to, e.g. in case you want to change their order of execution) and when maven passes from that phase, as part of maven lifecycle, they will automatically execute.