-
Notifications
You must be signed in to change notification settings - Fork 0
Maven Notes
Use <dependencyManagement> to define dependencies and use it by refering to it in <dependencies>.
Similarly, use <pluginManagement> to configure plugins.
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
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.
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-testgoal when theintegration-testphase is invoked and -
failsafe:verifygoal (to collect the test's results) when theverifyphase 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>
- exclusive :
(, ) - inclusive :
[, ]
Example: greater than equal to 3.8 but less than 4.0
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>[3.8,4.0)</version>
<scope>test</scope>
</dependency>
Example: less than equal to 3.8
<version>[,3.8]</version>
Example: exactly 3.8.2
<version>[3.8.2]</version>
Note, when defined like this <version>3.8.2</version> it is allow anything but prefer 3.8.2.