Skip to content

Maven Notes

illyfrancis edited this page Nov 14, 2013 · 8 revisions

Dependency management

Use <dependencyManagement> to define dependencies and use it by refering to it in <dependencies>.

Plugin management

Similarly, use <pluginManagement> to configure plugins.

Multi module

Refer to Instance Apache Maven Starter.

In sub-module, to refer to parent POM configure it as

<parent>
  <groupId>...</groupId>
  <artifactId>...
  <versionId>...
  <relativePath>../../pom.xml</relativePath>
</parent>

Aparently the default value of <relativePath> is ../pom.xml. The above example assumes the project structure of

some-multi-modules-project
  |- pom.xml (POM aggregator)
  |- some-modules
       |- first-module
       |    |- pom.xml
       |- second-module
       |    |- pom.xml
       |- third-module
            `- pom.xml

Surefire:test

The mvn test phase is bound to the sourefire:test goal.

To run only one specific test MyUnitTest.java,

mvn test -Dtest=MyUnitTest

To execute a phase that implicitly invokes surefire:test, e.g. install phase, you can skip tests by

mvn install -DskipTests=true

Using -Dmaven.test.skip=true instead, you'd also skip the test class compilation.

Integration testing

Unlike test it is not bound by default in Maven. But goal failsafe:integration-test of can be used to run all tests with name ends with IT. Surefire plugin will automatically skip these tests.

To configure the plugin so that:

  • failsafe:integration-test goal when the integration-test phase is invoked and
  • failsafe:verify goal (to collect the test's results) when the verify phase is invoked

Configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.14.1</version>
  <executions>
    <execution>
      <id>integration-test</id>
      <phase>integration-test</phase>
      <goals>
        <goal>integration-test</goal>
      </goals>
    </execution>
    <execution>
      <id>verify</id>
      <phase>verify</phase>
      <goals>
        <goal>verify</goal>
      </goals>
    </execution>
  <executions>
<plugin>

Clone this wiki locally