I'm trying to convert this (groovy) to Kotlin KTS
# gradle
l
I'm trying to convert this (groovy) to Kotlin KTS
l
I followed exactly the example, and it didn't work
But I get
Copy code
Line 5: sourceSets {
          ^ Unresolved reference: sourceSets
p
works with gradle 5.1.1 at my machine
l
Did you put it in another file?
And then
apply(from = "other.file.gradle.kts")
?
p
no build.gradle.kts
l
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
you should create an issue with the whole stacktrace I guess
l
Create an issue where?
p
l
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
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
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
well the gradle docs linked in the comment somehow detail how applied scripts have to be written without accessors
Copy code
configure<SourceSetContainer> {
    named("main") {
        java.srcDir("src/core/java")
    }
}
😄
1
👍 1
👌 1
l
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
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
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
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
In this case, multiple sourceSets, configuring the
idea
plugin, all in another file (not the main build.gradle)
n
l
It still doesn't solve my issue, as I can't use it in another file
r
I have this block in my build file:
Copy code
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
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
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.