title: Building a Kotlin + Java 9 project with Gradle
body: <p>I'm fairly new to Gradle (and Java 9, to be honest), and I'm trying to use Gradle to build a simple library project that is a mix of Java 9 and Kotlin. More in detail, there is an interface in Java and an implementation in Kotlin; I'd do everything in Kotlin, but the <code>modules-info.java</code> is java anyway, so I decided to do things this way.</p>
  
  <p>I'm building on IntelliJ Idea, with the 1.2.0 kotlin plugin and gradle 4.3.1 defined externally.</p>
  
  <p>Filesystem schema is:</p>
  
  <pre><code>+ src
    + main
      + java
        + some.package
          - Roundabout.java [an interface]
        - module-info.java
      + kotlin
        + some.package.impl
          - RoundaboutImpl.kt [implementing the interface]
  </code></pre>
  
  <p><code>module-info.java</code> is:</p>
  
  <pre><code>module some.package {
    requires kotlin.stdlib;
    exports some.package;
  }
  </code></pre>
  
  <p>and <code>build.gradle</code> is:</p>
  
  <pre><code>buildscript {
      ext.kotlin_version = '1.2.0'
  
      repositories {
          mavenCentral()
      }
      dependencies {
          classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      }
  }
  
  group 'some.package'
  version '1.0-PRE_ALPHA'
  
  apply plugin: 'java-library'
  apply plugin: 'kotlin'
  
  tasks.withType(JavaCompile) {
      options.encoding = 'UTF-8'
  }
  
  sourceCompatibility = 9
  
  compileJava {
      dependsOn(':compileKotlin')
      doFirst {
          options.compilerArgs = [
                  '--module-path', classpath.asPath,
          ]
          classpath = files()
      }
  }
  
  repositories {
      mavenCentral()
  }
  
  dependencies {
      compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: "$kotlin_version"
      testCompile group: 'junit', name: 'junit', version: '4.12'
  }
  
  compileKotlin {
      kotlinOptions.jvmTarget = "1.8"
  }
  
  compileTestKotlin {
      kotlinOptions.jvmTarget = "1.8"
  }
  </code></pre>
  
  <p>Notice that I had to specify a module path on the java compile task, or the compilation fails with:</p>
  
  <blockquote>
    <p>error: module not found: kotlin.stdlib
    requires kotlin.stdlib;</p>
  </blockquote>
  
  <p>Anyway, now this build fails with this error, and I can't figure out how to solve it:</p>
  
  <blockquote>
    <p>error: package some.package.impl does not exist</p>
    
    <p>import some.package.impl.RoundaboutImpl;</p>
    
    <p>error: cannot find symbol</p>
    
    <p>return new RoundaboutImpl&lt;>(queueSize, parallelism, worker, threadPool);</p>
  </blockquote>
  
  <p>I <em>think</em> that the Kotlin part of the compilation is going ok, then the java part fails because it doesn't "see" the kotlin side, so to speak.</p>
  
  <p>I think I should tell it somehow to to load the already compiled kotlin classes in the classpath; but (first) how do I do this in gradle? and (second) <em>is it even possible</em>? I think you can't mix module path and class path in Java 9.</p>
  
  <p>How can I solve this? I think it is a pretty common situation, as every java9-style module will be a mixed-language module (because of <code>module-info.java</code>), so I think I'm missing something really basic here.</p>
  
  <p>Thanks in advance!</p>