I have a simple gradle multi-project setup with 3 sub-projects.
The project outline
- Project Root (Solution)
- Project A
- Project B
- Common
All the sub projects are java-library’s.
-
Project A
depends onCommon
andProject B
-
Project B
also depends onCommon
Project A and B use org.apache.logging.log4j
for logging and this works fine during unit testing in Project B
. But when I try to unit test Project A
the unit test fails, the moment some class in Project B
tries to log something.
The error I’m getting:
Also, I’m not sure if this is normal, but I can use test classes of Project B
in Project A
and I can use dependencies implemented (not using api configuration) of Project B
in Project A
.
I’ve tried some different dependency configurations such as ‘api’, ‘runtimeOnly’, ‘compileOnly’, … I also tried googling the issue but I find it hard to describe the issue i’m having and had no luck googling.
Environment
Gradle 6.3
JDK 11.0.9
OS Windows 10
IDE Eclipse 2020-09 (4.17.0)
Gradle setup
The build.gradle
file in the root directory (solution directory)
subprojects {
apply plugin: 'java-library'
repositories { jcenter() }
java.sourceCompatibility = JavaVersion.VERSION_11
}
The settings.gradle
file in the root directory (solution directory)
rootProject.name = 'SomeSolution'
include "Common", "NetKit", "BetterBus"
The build.gradle
file in the project directory of Common
dependencies {
testImplementation 'junit:junit:4.12'
}
The build.gradle
file in the project directory of Project B
dependencies {
implementation project(":Common")
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'
implementation 'org.apache.commons:commons-lang3:3.11'
implementation 'com.google.guava:guava:29.0-jre'
implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.3'
implementation 'org.apache.logging.log4j:log4j-core:2.13.3'
implementation 'net.jodah:typetools:0.6.2'
implementation 'org.objectweb.asm:com.springsource.org.objectweb.asm:3.2.0'
testImplementation 'junit:junit:4.12'
}
The build.gradle
file in the project directory of Project A
dependencies {
implementation project(":Common")
implementation project(":ProjectB")
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'
implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.13.3'
implementation 'org.apache.logging.log4j:log4j-core:2.13.3'
api 'io.netty:netty-all:4.1.54.Final'
implementation 'it.unimi.dsi:fastutil:8.4.4'
testImplementation 'junit:junit:4.12'
}
I also posted this question on StackOverflow but I don’t seem to get any replies / answers.