如何申请插件只有一种口味的gradle中? [英] How to apply plugin to only one flavor in gradle?

查看:264
本文介绍了如何申请插件只有一种口味的gradle中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多味,多积累类型的Andr​​oid项目,我想整合插件NewRelic的。但是,我要申请只为客户之一,因此只对一个产品的味道。结果
使用NewRelic的仪器,如果我申请有插件插件会产生多种口味code,这是不允许我们。

I have a multi-flavored, multi-build-typed android project and I want to integrate the NewRelic plugin. But I have to apply it only for one of the customers, thus only for one product flavor.
NewRelic uses instrumentation and the plugin would generate code in other flavors if I applied the plugin there, and that is not permitted for us.

所以我的问题是:我如何使用应用插件:?什么中的文件的gradle命令只应用于我的口味之一

So my question is: How can I use the apply plugin: something command in the gradle file to be applied to only one of my flavors?

推荐答案

我找到了解决办法,但它是不是最好为止。
所以,我不知道了,这就是我想要做的最初可能。
该文件的gradle评估和右边味道选择和构建类型是在编译的gradle的不同阶段,所以我所做的是:

I found a solution, but it is not the best so far. So I'm not sure anymore, that what I wanted to do initially is possible. The gradle file evaluation and the choosing of the right flavor and build type is in different phases of the gradle build, so what I've done is:

我用命令行构建参数。当paramerer是真实的,我申请的插件,当它不是即使在那里,我也应用它(对IDE版本)。
我用詹金斯,所以我可以写在构建作业参数。

I use a build parameter from the command line. When that paramerer is true, I apply the plugin, when it is not even there, I also apply it (for IDE build). I use Jenkins, so I could write that parameter in the build job.

的build.gradle文件:

build.gradle file:

// First we have to attach a task to the project, which will be running first
gradle.projectsEvaluated {
    preBuild.dependsOn(applyNewRelicByProperty)
}

// Then check on the parameter, which comes from the command line
task applyNewRelicByProperty {
    if(!project.hasProperty('compileNewRelic')) {
        // NewRelic on: 'compileNewRelic' property not set, so running from IDE.
        apply plugin: 'newrelic'
    } else if(project.hasProperty('compileNewRelic') && project.getProperties().get('compileNewRelic').equals('true')) {
        // NewRelic on: 'compileNewRelic' property is set and it is 'true'.
        apply plugin: 'newrelic'
    } else {
        // NewRelic off
        println("No NewRelic")
    }
}

和你有这个运行构建的gradle:

And you have to run the gradle build by this:

assembleYourApp -PcompileNewRelic=true

这篇关于如何申请插件只有一种口味的gradle中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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