Configure gradle plugin based on future tasks - gradle

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

Related

How can I set a project as trusted when using the gradle :runIde task during IntelliJ Plugin Development

the documentation shows that I can configure this via the gui here: https://www.jetbrains.com/help/idea/project-security.html
Each time I have gradle perform :runIde it launches a new IDE instance and I have to reconfirm the trusted project directory.
Is there a gradle flag or setting somewhere in the plugin project to set this once for all?
I am using a kotlin build.gradle.kts file
*I have configured the trusted root in my 'Parent' IntelliJ IDEA that launches the task, but it seems, is sometimes not carried over. Alternatively I would like this to be available when operating from the CLI aswell.
*I am using the :clean command alongside the :runIde command, would this affect the settings being erased?

Change default option of Intellij IDEA gradle plugin

Everytime I check out and open a project in Intellij I need to change the gradle plugin setting "Use Gradle from" from the default "'gradle-wrapper.properties' file" to "'wrapper' task in Gradle build script"
Is there a way in Intellij 2020 to make the shown option the default?
Reason I am asking: Generated gradle-wrapper files are not in our VCS, but the build.gradle is, and it has the wrapper task configured with the desired version. So when I check out a project, Intellij does not find gradle.properties (and neither can download gradle from web, as that is blocked). I then have to change the option "Use Gradle From" manually each time.
Another solution I tried is to automatically run a script when opening a module, which would run gradle wrapper with a fixed gradle version for the module, hence generating the missing wrapper files. But I find no possibility in Intellij to trigger that upon import..
It is not possible to change this setting for all projects. Please vote for this request: IDEA-215792.

How to set org.gradle.native system property when using the wrapper

I would like to set the org.gradle.native JVM system property to false to disable gradle native integration on our CI system where the OS version does not support it. I have no control over the OS. We use the gradle wrapper which invokes the gradle daemon to do the build.
The relevant gradle code that reads the property is here. Note that it's a static initialiser - it happens early - this may or may not be relevant. I have tried, without success:
./gradlew -Dorg.gradle.native=false
./gradlew -Dorg.gradle.jvmargs='-Dorg.gradle.native=false'
and also adding to $GRADLE_USER_HOME/gradle.properties:
systemProp.org.gradle.native=false

Gradle: Making JavaExec tasks incremental whilst debugging

I am working on a gradle project where I have a JavaExec task which runs as part of the build. When running the task normally it is incremental, i.e when the inputs/outputs haven't changed the task is skipped. As the project is built with gradle, when I run my application it builds the required modules before launching.
This works fine when using the standard 'Run' (I am using IntelliJ as my IDE), however if I launch it using 'Debug' (with the same run configuration), the JavaExec task always rebuilds, as the randomly assigned 'address' property in the jvmArgs has changed, despite no other changes to the inputs/outputs.
This turns the usual ~5s launch time (when all tasks are up-to-date) into 1min+, as it reruns the task.
Is there any way to force the address of the jvm that the child process uses, in order to retain the benefit of the incremental builds?
I have tried:
debugOptions closure, eg:
debugOptions {
enabled = true
port = 12995
server = true
suspend = false
}
Explicitly settings the jvmArgs, eg:
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=12995'

Task with name "classes" not found, even tough I can run it

I am trying to create a gradle plugin. I want it to run after all java class-files were created. Therefore, I call task.dependsOn("classes").
During configuration phase, Gradle says Task with path 'classes' not found in root project. even tough I can just run the task via gradlew classes
How can that be? How can I create the dependency I need?
According to documentation:
Classes from buildSrc are no longer visible to settings scripts
Previously, the buildSrc project was built before applying the
project’s settings script and its classes were visible within the
script. Now, buildSrc is built after the settings script and its
classes are not visible to it. The buildSrc classes remain visible to
project build scripts and script plugins.

Resources