gradle - 我如何在执行另一个任务之前执行Gradle插件任务?

标签 gradle dependencies task build.gradle

我正在使用native-artifacts插件,该插件定义了许多任务,这些任务提取在其他位置(并存储在Nexus / Maven中)构建的依赖项的Nar依赖项。我需要确保在构建二进制文件之前调用了这些任务,否则找不到这些Nars包含的 header 。

我的问题是,如何将系统/插件定义的任务定义为其中一项任务的依存关系?

我想要类似的东西:

binaries.all {binary ->
      dependencies {
        // this next line is now the same as the plugin-defined task I want to have called before
        // before the build takes place
        compile "extractNarDeps${binary.name.capitalize()}"
      }
    }

可悲的是,这没有建立。请问我该如何实现?我有一个名为unitTests的组件,它是一个C++组件,用于创建unitTestsExecutable。我想在调用compileUnitTests之前调用extractNarDepsxxx。

最佳答案

首先,您是否有任何名为binaries的列表?如果是,那么您可以在build.gradle文件中尝试以下类似操作,因为依赖项将在定义的任务之前执行:

dependencies {
    binaries.each {binary ->
        // this next line is now the same as the plugin-defined task I want to have called before
        // before the build takes place
        compile "extractNarDeps${binary.name.capitalize()}"
    }
}

// Your defined task here

关于gradle - 我如何在执行另一个任务之前执行Gradle插件任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24071270/

相关文章:

dependencies - playframework 应用程序的 powermock 依赖项

android - Android Studio 中的多个项目

c# - 任务的协变和逆变

java - GAE : Know if a specific task is on the queue

android - 如何在Android的主项目中包含库项目中使用的aar文件

groovy - Gradle任务永远不会是最新的

android - Checkstyle 自定义检查与 gradle (android studio)

android - 如何在 android studio 中获取最新版本的库?

java - 如何在线程结束时执行函数?

android - 无法使用 “google-play-services”编译我的Android应用