根据将来的任务配置Gradle插件 [英] Configure gradle plugin based on future tasks

查看:100
本文介绍了根据将来的任务配置Gradle插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件,需要根据任务是否要运行来切换属性.之所以需要这样做,是因为在ide(intellij)中运行时,需要禁用此标志,而如果运行特定的运行时任务,则需要启用此标志.

我尝试过

gradle.taskGraph.whenReady { if (it.hasTask(tasks.runtime)) {
    javafx.configuration = "compileOnly"
    } 
}

但这给我一个错误

Cannot change dependencies of dependency configuration ':implementation' after it has been included in dependency resolution.

是否有任何方法可以根据任务更早地(在插件配置期间)设置此属性,或者有一种更好的方法来完成此操作?

解决方案

在构建脚本中,您可以评估IDE添加的以下属性:

例如:System.getProperty('idea.active').

I have a plugin where I need to toggle a property base on whether a task is going to run or not. This is needed because when running in ide (intellij) this flag needs to be disabled whereas if the specific runtime task is run this flag needs to be enabled.

I've tried

gradle.taskGraph.whenReady { if (it.hasTask(tasks.runtime)) {
    javafx.configuration = "compileOnly"
    } 
}

but this gives me a error

Cannot change dependencies of dependency configuration ':implementation' after it has been included in dependency resolution.

Is there any way to set this property earlier (during plugin configuration) based on tasks or a better way to complete this?

解决方案

In build script you can evaluate following properties which IDE adds:

For example: System.getProperty('idea.active').

这篇关于根据将来的任务配置Gradle插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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