Hello, is there anyone who got everything set up a...
# gradle
p
Hello, is there anyone who got everything set up already (including IDEA support) to build a project with Gradle Script Kotlin? I got a few questions regarding the IDEA support, that's why I'm asking. My problem is actually that IDEA doesn't recognise that the project I'm working on (no matter which one) is a Gradle Script Kotlin based one. It doesn't offer me all of the new features they mentioned in the blog post, but instead "offers" me to add Kotlin support to my project, which actually fails if I press Okay because it can't find build.gradle (which isn't present when using GSK). There is nothing wrong with the code, I can build everything from the command line without any problems, but I can't get the syntax highlighting and stuff to work. I tried it with both IDEA CE/UE and various versions of the Kotlin Plugin.
c
pddstudio: can you list the versions you're using? IDEA, gradle, kotlin. I do have everything set up and working like a charm.
p
@Czar sure. IDEA CE 2017.1.4 IDEA UE 2017.2 EAP Kotlin Plugin 1.1.2-release-IJ2017.1-5 Gradle (Wrapper): gradle-kotlin-dsl-4.1-20170617185729+0000-all Gradle (System Wide): Gradle 4.0
IDEA UE Kotlin Plugin: 1.1.2-release-IJ2017.2-5
c
That is strange. with gradle 4.0+ everything should work without any special config. What is the name of your build script? Should be
build.gradle.kts
Another thing, does the project actually work from IDEA? Because the offer to add kotlin support is a known issue which is just annoying, but not harmful.
p
I can build and run the project without any problems from the command line. I can also run the sample's main method directly from within IDEA (so compilation and the other stuff is working)
IDEA somehow behaves strange. When I open the project and immediately click on the build.gradle.kts I can see the syntax highlighting as expected, but once the project initialisation is done everything gets red and is "unresolvable"
c
I've just re-read your initial post. So syntax highlight, auto-complete, etc. does not work. Ok, have you refreshed the gradle project? Let's try this: a. close IntelliJ b. delete all intellij and gralde cache files and folders from the project folder (.idea/,.iml,.ipr, .gradle/, gradle/*) c. create gradle wrapper:
gradle wrapper
c. open intellij d. import the project into IntelliJ by pointing it to build.gradle.kts and using default wrapper option.
p
I just recorded a small video for demonstration. It's uploading now, in meanwhile I'll try your attempt (I already did this almost 1:1 except of creating the wrapper via gradle)
@Czar When I try to create the wrapper via
gradle wrapper
it throws an exception:
Copy code
/Users/pddstudio/dev/kotlin/gradle-script-kotlin/samples/multi-kotlin-project-config-injection/build.gradle.kts:4:30: Expression 'kotlin' cannot be invoked as a function. The function 'invoke()' is not found.
/Users/pddstudio/dev/kotlin/gradle-script-kotlin/samples/multi-kotlin-project-config-injection/build.gradle.kts:4:30: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
                                                                                           public val <T : Any> Class<???>.kotlin: KClass<???> defined in kotlin.jvm
c
what's on line 4 in build.gradle.kts?
Btw, when I select "Open" and then point to the kts file directly instead of the root folder, it opens a new project with only the build.gradle.kts file in it lol.
c
your gradle is 4.0, master repo on github uses the latest and greatest snapshot, that's VERY unstable way to use kotlin-dsl, unless you're developing it, don't torture yourself. Check this out instead: https://github.com/gradle/kotlin-dsl/blob/v0.9.0/samples/multi-kotlin-project-config-injection/build.gradle.kts
in 4.0 it's
kotlinModule
, instead of
kotlin
p
Okay, I changed this and now I fails due to line 10 here: https://github.com/gradle/kotlin-dsl/blob/master/samples/multi-kotlin-project-config-injection/cli/build.gradle.kts#L10 "Unresolved reference: mainClassName"
c
No idea, I've never used application plugin
but try to check out 0.9.0 tag instead of master and check there.
kotlin-dsl 0.9.0 is the version bundled with gradle 4.0, so concerning samples, it's better to check out that version instead of master.
p
@Czar Finally! Thanks for pointing out. After checking out the 0.9.0 tag and following the steps you mentioned above I was able to successfully import the project into intellij.
I also adjusted my own project to match with the sample
build.gradle.kts
- and it worked as well.
@Czar One last thing, are there any changelogs, userguides or getting-started documents especially for GSK (beside the samples in the repository) ?
c
I do not think so, I've gathered everything I have by reading through code, looking at samples and logically translating groovy to kotlin and reading kotlin-dsl release notes 🙂
p
Okay, thanks. I was going to do the same thing as you did, maybe it just needs more attention until people start blogging about it 🙂
z
p
@zeljko Thanks for this Link, looks interesting.