title: How do you compile Java+Kotlin project using Maven?
body: <p>I'm trying to compile maven project which has Kotlin classes referencing Java classes. Here's a part of my parent POM:</p>
  
  <pre><code>...
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
      &lt;artifactId&gt;kotlin-stdlib&lt;/artifactId&gt;
      &lt;version&gt;${kotlin.version}&lt;/version&gt;
  &lt;/dependency&gt;
  
  ...
  
  &lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
      &lt;version&gt;${compiler-plugin-version}&lt;/version&gt;
      &lt;configuration&gt;
          &lt;source&gt;${java-version}&lt;/source&gt;
          &lt;target&gt;${java-version}&lt;/target&gt;
          &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  
  &lt;plugin&gt;
      &lt;artifactId&gt;kotlin-maven-plugin&lt;/artifactId&gt;
      &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
      &lt;version&gt;${kotlin.plugin.version}&lt;/version&gt;
  
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;compile&lt;/id&gt;
              &lt;phase&gt;process-sources&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;compile&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
  
          &lt;execution&gt;
              &lt;id&gt;test-compile&lt;/id&gt;
              &lt;phase&gt;process-test-sources&lt;/phase&gt;
              &lt;goals&gt;
                  &lt;goal&gt;test-compile&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  
      &lt;configuration&gt;
          &lt;scanForAnnotations&gt;false&lt;/scanForAnnotations&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>And related parts of the child POM:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
      &lt;artifactId&gt;kotlin-stdlib&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  ...
  
  &lt;plugin&gt;
      &lt;artifactId&gt;kotlin-maven-plugin&lt;/artifactId&gt;
      &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
      &lt;configuration&gt;
          &lt;sourceDirs&gt;
              &lt;source&gt;${project.basedir}/src/main/kotlin&lt;/source&gt;
          &lt;/sourceDirs&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>And the Kotlin class:</p>
  
  <pre><code>Stateless
  open class DummyServiceImpl : DummyService {
  
      PersistenceContext(unitName = Consts.UNIT_NAME)
      private val em: EntityManager? = null
  
      override fun get(id: Long?): Dummy {
          return em!!.find&lt;Dummy&gt;(javaClass&lt;Dummy&gt;(), id)
      }
  
      override fun sayHi(): String {
          return "Dummy service says \"Hi!\"."
      }
  }
  </code></pre>
  
  <p><code>DummyService</code> and <code>Consts</code> classes are Java classes residing in the same module as <code>DummyServiceImpl</code>.
  So when I compile the module containing <code>DummyServiceImpl</code> with Maven it goes like this:</p>
  
  <pre><code>[error] C:\somepath\service\DummyServiceImpl.kt: (14, 31) Unresolved reference: DummyService
  [error] C:\somepath\service\DummyServiceImpl.kt: (16, 35) Unresolved reference: Consts
  </code></pre>
  
  <p>If I switch Kotlin plugin execution <code>phase</code> to <code>compile</code> then it predictably fails if there're references from Java to Kotlin classes:</p>
  
  <pre><code>[ERROR] /C:/somepath/service/impl/DummyServiceClientImpl.java:[5,27] cannot find symbol
  [ERROR] symbol:   class DummyServiceImpl
  </code></pre>
  
  <p>So, what's to be done about this? Note that building with IDEA's <code>make</code> goes perfectly fine.</p>