Access task generated by new component model to add "dependsOn"

How can I access a task that is generated by the new component model?


plugins {
  id 'cpp'
  model {
  components {
         'native'(NativeLibrarySpec) {
  task test << {
  println "hello"
// doesn't work: Could not find property 'nativeSharedLibrary' on root project 'test'
nativeSharedLibrary.dependsOn test

I found a workaround by delaying the creation of the ‘depends-on’ link:

tasks.matching{'compileNativeSharedLibrary') }
  .whenTaskAdded { it.dependsOn('test') }

However, this solution is kind of ugly. Isn’t there a cleaner way to do it?

1 Like

You’ll have to put that configuration inside the ‘model { }’ block. Take a look at the release notes for Gradle 2.2 for details.

model {

tasks.compileNativeSharedLibrary {

dependsOn test



Thank you (it works with taskS).

Is there somewhere general documentation about the whole ‘model { } block’ thing? I can’t find an entry point like the ‘Project’ class in the old model.

Next problem: as I need to configure multiple tasks I tried to put everything inside the ‘tasks’ block. However, inside the tasks block the task name does not exist:

model {
  // this works
  tasks.compileNativeSharedLibraryNativeCpp { dependsOn generateHeader }
  tasks {
    // this doesn't: Task with name 'compileNativeSharedLibraryNativeCpp' not found in root project
    getByName 'compileNativeSharedLibraryNativeCpp', { dependsOn generateHeader }
      // this _does_ work for top-level task
    getByName 'nativeSharedLibrary', { dependsOn generateHeader }

Simon, these particularities are due to the fact that the native build support is using the new Gradle configuration model. Details and better documentation is forthcoming on this front.

Thanks, I’m looking forward to it :slight_smile: Keep up the good work!