Laurence Gonsalves
Laurence Gonsalves

Reputation: 143294

"Could not find property on task set", but task appears in output of "gradlew -q tasks --all"

In my Android Studio/gradle build, I'm trying to create a task that generateDebugAssets will depend on. If I run:

./gradlew -q tasks --all

I get:

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Android tasks
-------------
app:androidDependencies - Displays the Android dependencies of the project.
app:signingReport - Displays the signing info for each variant.
app:sourceSets - Prints out all the source sets defined in this project.

Build tasks
-----------
app:assemble - Assembles all variants of all applications and secondary packages. [app:assembleDebug, app:assembleR
elease]
...
app:generateDebugAndroidTestResources
    app:generateDebugAndroidTestSources
    app:generateDebugAssets
    app:generateDebugBuildConfig
    app:generateDebugResValues

Note generateDebugAssets appears in this list.

If I then add the following to app/build.gradle:

task fooTask() {
}
tasks.generateDebugAssets.dependsOn fooTask

gradlew dies with "Could not find property 'generateDebugAssets' on task set."

How do I make generateDebugAssets depend on my new task?

Upvotes: 0

Views: 1226

Answers (2)

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143294

I found this discussion, where Jake Ouellette ran into a similar problem trying to make compile* depend on his custom task.

In that same discussion, René Groeschke says "The problem is that the tasks are created in the "project.afterEvaluate" hook." and provides a solution something like this (edited to match the question here):

task fooTask() {
}

tasks.whenTaskAdded{ t ->
      if(t.name.equals("generateDebugAssets")){
          t.dependsOn fooTask
      }
}

This ensures that the dependency is created after the generateDebugAssets task exists.

Upvotes: 1

newhouse
newhouse

Reputation: 946

Try this:

task fooTask(dependsOn: 'generateDebugAssets') {

}

Upvotes: 0

Related Questions