https://kotlinlang.org logo
Title
b

bjartek

03/14/2019, 7:27 AM
how do i express this in gradle script kotlin
compileTestGroovy.dependsOn compileTestKotlin
compileTestGroovy.classpath += files(compileTestKotlin.destinationDir)
testClasses.dependsOn compileTestGroovy
g

gildor

03/14/2019, 7:45 AM
compileTestGroovy
and testClasses are tasks, so you should use corresponding kotlin dsl api for that
e

efemoney

03/14/2019, 7:50 AM
The task might have an accessor already generated or not depending on how the plugin is applied and it will be generated as an extension of type
TaskProvider<T>
on
TaskContainer
so in your
build.gradle.kts
tasks {

  val compileTestKotlin by existing(KotlinCompile::class)

  compileTestGroovy.get().dependsOn(compileTestKotlin)
  compileTestGroovy.get().classpath += files(compileTestKotlin.get().destinationDir)
testClasses.get().dependsOn(compileTestGroovy)
}
Unfortunately the generated accessor for
compileTestKotlin
is generated with a wrong task type of `Any`and this will not work without you adding the first line and explicitly supplying the
KotlinCompile
type. If you want to do this the recommended Gradle way (ie with lazy configuration) use configuration blocks on the task providers
tasks {
  val compileTestKotlin by existing(KotlinCompile::class)

  compileTestGroovy {
    dependsOn(compileTestKotlin)
    classpath += files(compileTestKotlin.get().destinationDir)
  }

  testClasses {
    dependsOn(compileTestGroovy)
  }
}
b

bjartek

03/14/2019, 8:15 AM
Thanks, let me try that
g

gildor

03/14/2019, 8:31 AM
The task might have an accessor already generated or not depending on how the plugin is applied
Correct. And official docs (which I sent above) are really good and explain this thing
1
b

bjartek

03/14/2019, 9:38 AM
I got it to work, but it was not related to this, the groovy plugin was not applied because of an error in out gradle plugin.