I don't like that I repeat every repository dependency (let us say, junit
), for the main project and for subprojects. Is there a possibility to make the subproject to use the dependencies of the main project. Or is there another way to escape that repetition?
Unlike the accepted answer it's better to use the following:
allprojects {
plugins.withType(JavaPlugin) {
dependencies {
testCompile 'junit:junit:4.12'
}
}
}
The changes will be applied immediately if java
plugin already exists or will watch for it to be added and apply later.
Updated
At the moment I use better way to control configuration for plugin - pluginManager
. The effect is the same as for plugins.withType
, but you don't have to know plugin's class name:
Example for org.springframework.boot
plugin:
apply plugin: 'org.springframework.boot'
allprojects {
pluginManager.withPlugin('org.springframework.boot') {
springBoot {
buildInfo()
layout 'DIR'
}
}
}
root/build.gradle
allprojects {
if (plugins.hasPlugin('java')) {
dependencies {
testCompile 'junit:junit:4.12'
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With