Skip to content

Instantly share code, notes, and snippets.

@michail-nikolaev
Last active April 18, 2022 01:48
Show Gist options
  • Save michail-nikolaev/3980346 to your computer and use it in GitHub Desktop.
Save michail-nikolaev/3980346 to your computer and use it in GitHub Desktop.
Gradle - dependency to test classes of another module
// use test classes from spring-common as dependency to tests of current module
testCompile files(this.project(':spring-common').sourceSets.test.output)
// use testCompile dependencies from spring-common as dependency to tests of current module
testCompile files(this.project(':spring-common').sourceSets.test.runtimeClasspath)
def isClassesDependency(module) {
(module instanceof org.gradle.plugins.ide.idea.model.ModuleLibrary) && module.classes.iterator()[0].url.toString().contains(rootProject.name)
}
idea {
module {
scopes.PROVIDED.plus += configurations.provided
iml.whenMerged { module ->
module.dependencies.removeAll(module.dependencies.grep{isClassesDependency(it)})
module.dependencies*.exported = true
}
}
}
// and somewhere to include test classes
testRuntime project(":spring-common")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment