如何执行应用顺序的gradle插件? [英] How to enforce gradle plugins applying order?

查看:126
本文介绍了如何执行应用顺序的gradle插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们公司,我们编写了自定义gradle插件,它在应用程序插件出现时正在做一些事情。但是,当我们的插件之后的应用程序插件包含在build.gradle中时,我们的插件不会发现应用程序插件并且不会执行操作。

In our company we wrote custom gradle plugin which is doing some stuff when application plugin is present. But when application plugin is included in build.gradle after our plugin, our plugin doesn't discover application plugin and actions are not executed.

有没有什么办法可以让gradle强制插件申请命令?或任何其他解决方案?

Is there any way in gradle to enforce plugin applying order? Or any other solution?

我们插件的小节选:

Small excerpt from our plugin:

void apply(Project project) {
        if (project.plugins.hasPlugin(ApplicationPlugin) {
             //some stuff, doesn't work if "application" appears after this plugin
        }
}


推荐答案

这个帖子在Gradle论坛上 withType(Class) withId(String)是延迟评估的,仅适用于引用的插件。 / p>

According to this thread on the Gradle forums, withType(Class) and withId(String) are lazily evaluated and only applied when the referenced plugin is applied.

void apply(Project project) {
    project.plugins.withType(ApplicationPlugin) {
        //some stuff, doesn't work if "application" appears after this plugin
    }
}

这篇关于如何执行应用顺序的gradle插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆