This message was deleted.
# community-support
s
This message was deleted.
t
Using
gradle.taskGraph.whenReady
and throw if it
hasTask("idea")
? (not sure it's compatible with configuration cache though)
t
Interesting thought,
hasTask(String)
takes an "_absolute path of the task"._ I tried with "idea" and the FQN, but no luck. I'm not sure how to actually invoke the
hasTask(Task)
API as it takes an instance of a task 🤔
I got the intended result through this snippet of code, though it's not very elegant 🙄
Copy code
if (idea.module != null) {
  tasks.named("ideaModule") {
    enabled = false
  }
}

if (idea.project != null) {
  setOf("ideaProject", "ideaWorkspace").forEach { taskName ->
    tasks.named(taskName) {
      enabled = false
    }
  }
}

if (idea.project != null) {
  tasks.named("idea") {
    doFirst {
      throw RuntimeException("To import in IntelliJ IDEA, follow the instructions in $ideaInstructionsUri")
    }
  }
}
t
hasTask(":idea")
?
🙌 1
This worked for me:
Copy code
gradle.taskGraph.whenReady {
    if (hasTask(":idea")) throw RuntimeException("To import in IntelliJ IDEA, follow the instructions in ...")
}
both in
settings.gradle.kts
or
build.gradle.kts
t
Using
hasTask(":idea")
worked for me:
Copy code
gradle.taskGraph.whenReady {
  if (hasTask(":idea")) {
    throw RuntimeException("To import in IntelliJ IDEA, follow the instructions in $ideaInstructionsUri")
  }
}
console output:
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
Failed to notify task execution graph listener.
> To import in IntelliJ IDEA, follow the instructions in ...
Which version of Gradle are you using?
t
Oops, sorry, yes, it has to be
:idea
, not
idea
(bad copy/paste from various tests in snippet above, edited/fixed now)
Tested with 7.5.1
t
Thanks for the assist @Thomas Broyer 🙌 I suppose I now have good reason for a dive into the configuration cache docs 😄