3

我有一个插件,我需要根据任务是否要运行来切换属性。这是必需的,因为在 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.

有没有什么方法可以根据任务更早地(在插件配置期间)设置这个属性,或者有更好的方法来完成这个?

4

1 回答 1

4

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

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

于 2020-08-14T10:50:27.730 回答