Configure gradle plugin based on future tasks

Viewed 297

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?

1 Answers

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

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

Related