Below is my project strucuture:
Master
|
|--A
|--B
|--C
C depends on A,B and Master. I want to first compile Master, A, B and then C but run tests which are present only in the C module.
I want a command that can be used in Jenkins as well.
I went through http://www.jayway.com/2013/06/09/working-efficiently-with-maven-modules/ but using
mvn -pl :C -am clean install
builds and runs tests in all the modules : Master, A and B.
The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”. As the output shows, only the test class we've passed to the test parameter is executed.
In the Maven project, you can create and run tests the same way you do in any other project using the default IntelliJ IDEA test runner.
mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project.
Because modules within a multi-module build can depend on each other, it is important that the reactor sorts all the projects in a way that guarantees any project is built before it is required. The following relationships are honoured when sorting projects: a project dependency on another module in the build.
It's not possible to run different goals for sub modules with a single command.
Let's assume you have a following structure:
Parent
|
|---ModuleA
|---ModuleB (Depends on ModuleC)
|---ModuleC
Now if you run mvn clean install -pl :ModuleB
-am from the root pom (Parent), you can see that it builds Parent, ModuleC and ModuleB.
Either reorganize your codebase differently or run something like this: mvn clean install -pl :ModuleB -Dmaven.test.skip=true && mvn test -pl :ModuleB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With