title: Gradle Kotlin DSL multi project build with Java Modules
body: <p>I'm creating a new project (using IntelliJ IDEA) that will be using:</p>
  <ul>
  <li>Gradle as the build system</li>
  <li>Kotlin DSL for build scripts</li>
  <li>Java 9 modules for &quot;organisation&quot;</li>
  <li>Kotlin as the primary language</li>
  </ul>
  <p>I'm having problems setting up Gradle to properly build my project. Most examples I've found are for Groovy and not Kotlin DSL, and most only cover some of the features I want, but not all.</p>
  <p>Right now I have two modules, <em>core</em> and <em>lib</em>, where the <em>core</em> module requires the <em>lib</em> module. My gradle build scripts are:</p>
  <p><strong>build.gradle.kts</strong></p>
  <pre><code>plugins {
      base
      kotlin(&quot;jvm&quot;) version &quot;1.3.41&quot; apply false
  }
  
  subprojects {
      afterEvaluate {
          tasks.withType&lt;JavaCompile&gt; {
              inputs.property(&quot;moduleName&quot;, extra[&quot;moduleName&quot;])
              options.compilerArgs.addAll(arrayOf(&quot;--module-path&quot;, classpath.asPath))
              classpath = files()
          }
      }
  
      repositories {
          mavenCentral()
          jcenter()
      }
  }
  </code></pre>
  <p><strong>core/build.gradle.kts</strong></p>
  <pre><code>extra.set(&quot;moduleName&quot;, &quot;myproject.core&quot;)
  
  plugins {
      kotlin(&quot;jvm&quot;)
  }
  
  dependencies {
      compile(kotlin(&quot;stdlib&quot;))
      compile(project(&quot;:networking&quot;))
  }
  </code></pre>
  <p><strong>lib/build.gradle.kts</strong></p>
  <pre><code>extra.set(&quot;moduleName&quot;, &quot;myproject.lib&quot;)
  
  plugins {
      kotlin(&quot;jvm&quot;)
  }
  
  dependencies {
      compile(kotlin(&quot;stdlib&quot;))
  }
  </code></pre>
  <p>Doing this, configuration fails with:</p>
  <blockquote>
  <p>A problem occurred configuring project ':core'.</p>
  <p>Cannot get property 'moduleName' on extra properties extension as it does not exist</p>
  </blockquote>
  <p>If I remove the <code>inputs.property()</code> line the configuration succeeds, but the <em>core</em> compilation fails (<em>lib</em> compiles successfully) with :</p>
  <blockquote>
  <p>Task :core:compileKotlin</p>
  <p>e: Module myproject.lib cannot be found in the module graph</p>
  </blockquote>
  <p>I assume the issue is is my root <code>build.gradle.kts</code>, but I cannot figure out how to make it work. Googling around, Kotlin DSL for Gradle is somewhat new and not as widely used, and documentation is pretty scarce.</p>
  <p>Any advice would be appreciated!</p>