Question

By default, Maven standard directory layout has two Java source folders:

src/main/java
src/test/java

For my purposes, I need a third one src/junit/java which should be packaged into a JAR with the classifier junit.

If possible, the new source folder should have it's own classpath (compile + everything with scope junit).

My guess is that for this, I will have to modify at least the resource and compile plugins.

Or is there an easier way?

I have a workaround as explained here but for that, I have to put things like Mockito and JUnit on the compile classpath which violates my sense of purity.

For all people who doubt the wisdom of my approach: I have support code that help to write unit tests when you work with code from src/main/java. Since I'm using the same support code in the tests for the project itself, this code needs to be compiled after src/main/java and before src/test/java.

Specifically, my support code needs to import code from src/main/java and the tests need to be able to import the support code.

Was it helpful?

Solution

I've seen a couple of Maven setups, which bundle test code in an own Maven module. You could then create a simple main-module <- support-module <- test-module dependency chain with that. But then main-module would compile fine, if you build it on it's own without test-module. Ofc you could aggreate them together with a reactor-pom and just build the project via this pom.

Edit:

If you have problems with this setup regarding code coverage, you can use the Jacoco Maven plugin to aggregate the test coverage generated by test-module to main-module. See this for further information: http://www.petrikainulainen.net/programming/maven/creating-code-coverage-reports-for-unit-and-integration-tests-with-the-jacoco-maven-plugin/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top