There are many reasons why you may want to make a pom file available as an artifact. One reason is the aggregate project. An aggregate project must have the pom
packaging type. Another reason could be a pom, which can be imported as a dependency. Whatever the reason, Maven provides support to build a pom project.
simple-pom-project
).packaging
type:<groupId>com.packt.cookbook</groupId> <artifactId>simple-pom-project</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <description>Simple pom project</description>
mvn clean package
Note that only the clean
goal is run.
mvn clean install
The following are the default bindings for the pom
packaging type:
package: site:attach-descriptor
: This attaches a descriptor to the site report, if applicableinstall: install:install
: This installs the project in the local repositorydeploy: deploy:deploy
: This deploys the project to the remote repositoryAs we can see, Maven does not run any other goals for the pom
packaging type. However, if it sees module
elements, it invokes the specified Maven goals on all the defined modules.
Also, various configurations, including pluginManagement
and dependencyManagement
, get inherited by all of the child projects.
What if you had a reason to compile some source files or run some tests even though the packaging type is pom
? This may not be a usual scenario, but it can be done by explicitly invoking the relevant plugin goals in the following way:
simple-pom-project
).mvn clean compiler:compile compiler:testCompile surefire:test jar:jar
We now explicitly invoke the following goals:
compiler:compile
: This compiles the source filescompiler:testCompile
: This compiles test filessurefire:test
: This runs testsjar:jar
: This creates a JAR artifactMaven does not prevent us from doing this.
3.137.188.201