This message was deleted.
# community-support
s
This message was deleted.
1
n
should I set up my folder containing the init scripts as a kotlin sourceset and add the gradle api as a compileOnly dependency?
v
Put the file(s) to
<GRADLE_USER_HOME>/init.d/
, then sync any Gradle project. When IJ syncs a Gradle project, Gradle is telling it all scripts that were used, including init scripts. Then open that init script in IJ in that location and you can edit it with IntelliSense properly available.
n
That sounds like a reasonable workaround, but I was hoping for a more permanent solution. I'm also concerned that this might lead to duplicate definitions if the project already uses our in-house gradle distribution.
v
You could maybe add some [in pseudocode}
if (!rootProject.name == "init-script-editor") return
and maybe in the shipped one the opposite.
I'm not sure whether you can use
-I
somehow during IntelliJ sync. If you can, that should also work. Or you should probably only keep the files in that directory while you are editing them and then open sync the project where you want to edit them, where you can make sure to not use the custom distribution.
Besides that, the custom distribution is also unpacked within the
GRADLE_USER_HOME
, so you could also open the init script from there. I'm just not sure whether it would be a good idea to edit them there, as then you work with the modified custom distribution instead of the actual one.
You can maybe also add the init script as "standalone script file", but I'm not fully sure whether that works properly for Gradle init scripts.
But yeah, you should also be able to create a plugin project with
kotlin-dsl
plugin applied where you put the init scripts to
src/main/kotlin
, that should also work to get proper IntelliSense I think
n
I tried with standalone script file, that unfortunately didn't work. I'll see if I can make it work using kotlin-dsl. Thanks for all the suggestions, much appreciated.
👌 1
I think kotlin-dsl gets the context wrong 🤔 It transforms my init scripts into
org.gradle.kotlin.dsl.support.delegates.GradleDelegate
objects, which I don't think is correct here? e.g. before I had to write
gradle.beforeSettings
, but now
gradle
is my delegate, so it wants me to drop that
v
One moment, let me quickly try in my play project
Seems perfectly fine to me. An init script has
Gradle
as delegate, just as an init-script plugin would be a
Plugin<Gradle>
.
Gradle
also has a
getGradle()
method just like
Project
has
Project.getProject()
.
n
hold on, it seems to work now. Must've been an indexing issue with IntelliJ 🙂
awesome, thanks again
v
So whether you do
gradle.beforeSettings { ... }
or directly
beforeSettings { ... }
in an init script should behave exactly the same.
1