https://kotlinlang.org logo
Title
s

stepango

04/24/2018, 7:59 AM
Hi everyone! I want to migrate huge app to Kotlin-dsl step by step to do this I'm planing to extract pieces of code to
kts
files and use it from groovy. How could i achieve that.
apply from: "file.gradle.kts"
is not working in this case. Is there any other way?
g

gildor

04/24/2018, 8:07 AM
What is exactly not working? Because simple apply from
kts
must work, maybe problem what is inside of your file.gradle.kts
c

Czar

04/24/2018, 8:16 AM
I find it easier to do the other way around: rename
build.gradle
to e.g.
old-build.gradle
create
build.gradle.kts
with following content:
import org.gradle.kotlin.dsl.*

plugins {
	`java`
	kotlin("jvm") version "1.2.31"
}

apply {
	from("old-build.gradle")
}
Then move parts of code from groovy to build.gradle.kts. This way you have your fully working groovy setup called on to from kotlin-dsl entry point.
👍 7
s

stepango

04/24/2018, 8:18 AM
@gildor so far it contains simple data class, getting
unable to resolve class
errors
g

gildor

04/24/2018, 8:21 AM
@stepango You see this error on side of Groovy (when use it) or Kotlin?
s

stepango

04/24/2018, 8:21 AM
Groovy
g

gildor

04/24/2018, 8:21 AM
correct
Solution from from Alexander should work, also it make it easier to migrate dynamic scripts then reverse solution (extract kotlin code to scripts)
s

stepango

04/24/2018, 8:24 AM
So there is no way to import
kts
in groovy?
g

gildor

04/24/2018, 8:24 AM
You can import
problem with class itself
s

stepango

04/24/2018, 8:25 AM
how?
g

gildor

04/24/2018, 8:25 AM
your class is actually have name something like
File_gradle$Foo
👍 1
s

stepango

04/24/2018, 8:25 AM
what i could import if no classes?
g

gildor

04/24/2018, 8:25 AM
it’s just a way how Gradle works with kts script plugins
class is there, with mangled name
For things like data classes and so on better to use buildSrc or plugins
1
Script plugins just not intended to use like that
c

Czar

04/24/2018, 8:28 AM
For me rule of thumb is, if you declare a class in a build file and want to use it in another build fire, move it to
buildSrc
.
👍 2
g

gildor

04/24/2018, 8:32 AM
what i could import if no classes?
tasks, plugin application and extension configuration, it’s a way to extract part of you build.gradle config