Gradle configuration Spring multi-project test
For projects with multiple Gradle projects, if the main project is executing unit test, other sub-projects will be executed together, and some advanced settings are required.
First refer to another article, use eclipse to configure two SpringBoot projects: lab-springboot, library1.
Gradle references the level project
First, modify the build.gradle of library1 and add these codes at the bottom of the file:
configurations {
// Gradle DSL
// The names of the configurations which this configuration extends from.
testOutput.extendsFrom (testImplementation)
}
task jarTest (type: Jar, dependsOn: testClasses) {
from sourceSets.test.output
classifier = 'test'
// The classifier distinguishes different artifacts build from the same project.
}
artifacts {
testOutput jarTest
}
Then modify the build.gradle of lab-springboot and add these codes at the bottom of the file. Note that there may be other codes in the dependencies:
dependencies {
implementation project(':library1')
testImplementation project(path: ':library1', configuration: 'testOutput')
}
test {
useJUnitPlatform()
}
After the configuration is complete, enter the lab-springboot directory, and you can enter the command:
gradle test -i
It can be observed that in addition to the unit test of lab-springboot, the unit test of library1 is also executed.
Comments
Post a Comment