Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure gradle plugin based on future tasks

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?

like image 243
Tim Avatar asked Oct 16 '25 17:10

Tim


1 Answers

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').

like image 176
Andrey Avatar answered Oct 18 '25 06:10

Andrey