根据将来的任务配置Gradle插件 [英] Configure gradle plugin based on future tasks
问题描述
我有一个插件,需要根据任务是否要运行来切换属性.之所以需要这样做,是因为在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添加的以下属性:
-
当您从IDE运行Gradle任务时,IDE会设置
-
idea.active
属性;
当IDE 从Gradle构建脚本重新加载项目.
例如: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:
idea.active
property that IDE sets when you run Gradle tasks from IDE;idea.sync.active
property which is added by IDE when IDE reloads project from Gradle build scripts.
For example: System.getProperty('idea.active')
.
这篇关于根据将来的任务配置Gradle插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!