I need some help with a Gradle build file. I have some subprojects which depend on tasks in the top folder. I just need to take a test
task and split it into two separate test tasks. Currently the file system structure looks like (tab indicates files inside a directory):
top-level-project-folder
A.gradle
B.gradle
C-subproject-folder
C.gradle
D-subproject-folder
D.gradle
Contents of A.gradle (before refactor):
subprojects {
tasks.test.dependsOn {
bTask
}
}
apply from: 'B.gradle'
Contents of C.gradle (before refactor):
test {
...
}
After the refactor, C.gradle needs to look like:
test {
...
}
task runDifferentTests(type : Test) {
...
}
The tricky part is that C.gradle
's test
task currently depends on bTask
. However, after the refactor, C.gradle
's test
task should not depend on bTask
, but the new runDifferentTests
task should depend on bTask
. (Currently, D.gradle
's test
task is marked as depending on bTask
, but it does not actually depend on it -- I'd like to remove that dependency. The only task in the two subprojects which depends on bTask
is the new runDifferentTests
task.)
I've tried some different things but can't seem to find a working solution.
In a multi-project gradle build, you have a rootProject and the subprojects. The combination of both is allprojects. The rootProject is where the build is starting from. A common pattern is a rootProject has no code and the subprojects are java projects.
Gradle allows you to define one or more default tasks that are executed if no other tasks are specified. defaultTasks 'clean', 'run' tasks. register('clean') { doLast { println 'Default Cleaning! ' } } tasks.
rootDir. The root directory of this project. The root directory is the project directory of the root project.
Each project is made up of different tasks and a task is a piece of work which a build performs. The task might be compiling some classes, storing class files into separate target folder, creating JAR, generating Javadoc, or publishing some achieves to the repositories.
Just remove the declaration in subprojects
and declare your dependency directly in the subproject, in C.gradle
:
runDifferentTests.dependsOn rootProject.bTask
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