1

How to run a Gradle task in a separate .gradle file before executing the assembleDebug task?

I have build.gradle (Project: gradle)

    buildscript {
//something
}

allprojects{
    //something
}

tasks.whenTaskAdded { task ->
    if (task.name == 'assembleDebug') {
        task.dependsOn mytask
    }
}

And mytask.gradle including

task mytask << {
    println "mytask run!"
}

I have an exception: Could not get unknown property 'mytask' for root project 'gradle' of type org.gradle.api.Project.

  • 1
    Do you include your "mytask.gradle" script in your main "build.gradle" script? ( in "build.gradle" : `apply from : "./mytask.gradle"` ) – M.Ricciuti Feb 08 '19 at 14:06
  • 1
    In your **build.gradle** include this line **apply from: 'gradle/mytask.gradle'** see [this](https://stackoverflow.com/questions/2265283/how-can-i-import-one-gradle-script-into-another) – Jon Goodwin Feb 08 '19 at 14:07
  • @M.Ricciuti thank u, it works for me. – Roman Aymaletdinov Feb 08 '19 at 15:23

0 Answers0