https://kotlinlang.org logo
Title
l

LeoColman

01/23/2019, 2:35 PM
I'm trying to convert this (groovy) to Kotlin KTS
l

LeoColman

01/23/2019, 3:12 PM
I followed exactly the example, and it didn't work
But I get
Line 5: sourceSets {
          ^ Unresolved reference: sourceSets
p

Peter

01/23/2019, 3:17 PM
works with gradle 5.1.1 at my machine
l

LeoColman

01/23/2019, 3:17 PM
Did you put it in another file?
And then
apply(from = "other.file.gradle.kts")
?
p

Peter

01/23/2019, 3:18 PM
no build.gradle.kts
l

LeoColman

01/23/2019, 3:18 PM
How would you put it in another file?
I don't want my build.gradle.kts bloated with every single piece of code
In groovy it's valid syntax, in KTS it's not working x=
p

Peter

01/23/2019, 3:28 PM
you should create an issue with the whole stacktrace I guess
l

LeoColman

01/23/2019, 3:37 PM
Create an issue where?
p

Peter

01/23/2019, 3:38 PM
l

LeoColman

01/23/2019, 3:40 PM
I love Kotlin, and I really am eager to Kotlin DSL... But gradle released it as "Production Ready" and I couldn't literally do a single project in Kotlin DSL yet
Every time I try there's a different error. Even for trivial things, like SourceSet.... How is this production ready? x=
p

Peter

01/23/2019, 3:42 PM
I know the pain. Anyway this issue here seems to be due to the same problem: https://github.com/gradle/kotlin-dsl/issues/1287
l

LeoColman

01/23/2019, 3:45 PM
This is amazingly infuriating
I have to write 3x more code to do the same thing
I'll have to copy and paste code from the lib for this to work? This is a big no-no
This is very, very frustrating
p

Peter

01/23/2019, 3:48 PM
well the gradle docs linked in the comment somehow detail how applied scripts have to be written without accessors
configure<SourceSetContainer> {
    named("main") {
        java.srcDir("src/core/java")
    }
}
😄
1
👍 1
:yes: 1
l

LeoColman

01/23/2019, 3:49 PM
Thanks!
Altough this solves the issue, the verbosity is still pretty bad 😕
But thanks!
I ended giving up after another error showed up.
This is impossible 😕
r

rook

01/23/2019, 5:08 PM
Verbosity is a side-effect of using a more concrete type system. It took me a day to convert my build files for a relatively simple android project.
l

LeoColman

01/23/2019, 5:11 PM
Verbosity is bad, but manageable when it's intuitive. In this case, I don't think it's very intuitive at all
Maybe I'm just not used to it
r

rook

01/23/2019, 6:08 PM
I didn’t find it burdensome at all when I switched over. I think it added a single extra line to my file. I’m curious where you find it to be a burden.
l

LeoColman

01/23/2019, 6:14 PM
In this case, multiple sourceSets, configuring the
idea
plugin, all in another file (not the main build.gradle)
n

napperley

01/24/2019, 12:10 AM
l

LeoColman

01/24/2019, 12:20 PM
It still doesn't solve my issue, as I can't use it in another file
r

rook

01/24/2019, 4:39 PM
I have this block in my build file:
sourceSets {
            getByName("main").java.srcDirs("src/main/kotlin")
            getByName("test").java.srcDirs("src/test/kotlin")
            getByName("mock").java.srcDirs("src/mock/kotlin")
            getByName("prod").java.srcDirs("src/prod/kotlin")
        }
l

LeoColman

01/24/2019, 9:10 PM
Yeah, that's the issue for me. I don't want to do this in my build file
I want it in a separate file
It's possible with groovy
Impossible with Kotlin
r

rook

01/24/2019, 10:00 PM
You can do it in a separate file. Just create a
buildSrc
directory. You can create custom logic in Kotlin files there to resolve whatever you need.