In the buildscript section of a project, which is in the configuration phase - before the task graph has been loaded, I need to somewhat guess if I need to execute a GradeBuild task or not based on if one of a set of tasks is going to be run...
Is there any way to do some guestimate of this given that I don't have access to the task graph yet?
Essentially, I need to check if the task "robospock" will be run, which can be run by the tasks "test" <- "check" <- "build", etc. or anything that dependsOn these tasks...
The relevant code is:
buildscript {
// Evaluate hasTask in some intelligent way?
if ( hasTask && !project.hasProperty( 'build_robospock_plugin_init' ) ) {
project.tasks.create( name: 'build_robospock_plugin', type: GradleBuild ) {
buildFile = rootProject.buildFile
tasks = ['gradle-plugin-robospock:publish']
startParameter.projectProperties = [build_robospock_plugin_init: true]
}.execute()
}
repositories {
jcenter()
maven {
url file( '../../maven-deploy' )
}
}
dependencies {
classpath 'se.centril.robospock:gradle-plugin-robospock:0.1.0'
}
}
apply plugin: 'robospock'
An idea is to analyze gradle.startParameter.taskRequests
and check for some common names... is there a better strategy? What task names should I look for in this case?
Are there any better ways?