Building a pom project

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.

How to do it...

  1. Open a simple pom project (simple-pom-project).
  2. Observe the 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>
  3. Build the project:
    mvn clean package
    

    Note that only the clean goal is run.

  4. Run the following command:
        mvn clean install 
    
  5. Observe the output:
    How to do it...

How it works...

The following are the default bindings for the pom packaging type:

  • package: site:attach-descriptor: This attaches a descriptor to the site report, if applicable
  • install: install:install: This installs the project in the local repository
  • deploy: deploy:deploy: This deploys the project to the remote repository

As 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.

There's more...

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:

  1. Open the simple pom project (simple-pom-project).
  2. Run the following command:
    mvn clean compiler:compile compiler:testCompile surefire:test jar:jar
    
  3. Observe the output:
    There's more...

We now explicitly invoke the following goals:

  • compiler:compile: This compiles the source files
  • compiler:testCompile: This compiles test files
  • surefire:test: This runs tests
  • jar:jar: This creates a JAR artifact

Maven does not prevent us from doing this.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.188.201