Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven : Build all dependencies but run tests on specific modules

Tags:

maven

maven-3

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.

like image 365
user170008 Avatar asked Sep 16 '14 00:09

user170008


People also ask

How do I run a specific Maven test?

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.

Does Maven build run tests?

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.

What is Maven The difference between Maven clean and test?

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.

Can two Maven modules depend on each other?

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.


1 Answers

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

like image 66
Olli Puljula Avatar answered Nov 15 '22 07:11

Olli Puljula