# Kotlin, Groovy and Java Compilation

**URL:** https://discuss.gradle.org/t/kotlin-groovy-and-java-compilation/14903
**Category:** Help/Discuss
**Created:** [March 3, 2016, 3:27am UTC](https://discuss.gradle.org/t/kotlin-groovy-and-java-compilation/14903 "2016-03-03T03:27:36Z")
**Posts on this page:** 1
**Showing post:** 10

<div class="post-metadata">

### Author: ![Danny\_Thomas1](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@Danny\_Thomas1](https://discuss.gradle.org/u/Danny_Thomas1)
#### Post date: [June 11, 2016, 12:23am UTC](https://discuss.gradle.org/t/kotlin-groovy-and-java-compilation/14903/10 "2016-06-11T00:23:50Z")

</div>

Looks like what you need is:

```
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
compileKotlin.dependsOn compileGroovy
compileKotlin.classpath += files(compileGroovy.destinationDir)
classes.dependsOn compileKotlin

```

- `taskDependencies.values` contains a `String` for the task name
- You need an explicit dependency for the `classes` task, so it still runs before tests etc, because `compileKotlin` doesn’t output to the standard classes dir, it uses a post hook to copy from the `kotlin-classes` directory
- Likewise, for Kotlin to compile against Groovy, you need to make the files output by the `compileGroovy` task visible, without using the sourceset `output`, as that’ll cause a circular dependency for `classes`

It means that interop can only go one way, Kotlin -\> Groovy, so you need to use reflection at the seams, or move your key wiring classes to Kotlin.

Incidentally, this is a handy extension for Groovy `Closure` interop:

```
fun <T> T.groovyClosure(function: () -> Unit) = object : Closure<Unit>(this) {
    @Suppress("unused")
    fun doCall() {
        function()
    }
}
```

---

_[View the full topic](https://discuss.gradle.org/t/kotlin-groovy-and-java-compilation/14903)._
