【问题标题】:How do I execute a Gradle plugin task before another one?如何在另一个之前执行 Gradle 插件任务?
【发布时间】:2014-06-11 15:02:00
【问题描述】:

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

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

我想要类似的东西:

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。

【问题讨论】:

    标签: gradle dependencies task build.gradle


    【解决方案1】:

    首先,您有任何名为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
    

    【讨论】:

    • 不,恐怕这行不通 - 有没有办法将插件定义的任务作为另一个插件定义的任务的依赖项注入?
    【解决方案2】:

    我这样做的方式是将我的任务指定为插件相关任务的依赖项。缺少的语法链接是使用“任务”作为引用项目中任务的一种方式。

    答案不是我的,这里解释得很好:tasks._applied_plugin_task_name_here.dependsOn(myTask)

    【讨论】:

      猜你喜欢
      • 2019-05-13
      • 1970-01-01
      • 2015-10-06
      • 2015-03-21
      • 2013-09-03
      • 1970-01-01
      • 2019-04-09
      • 2014-05-15
      • 2010-11-30
      相关资源
      最近更新 更多