IntelliJ IDEA - fixes to Ant builds for Kotlin

I had some trouble generating working Ant builds for a mixed Java/Kotlin project using IDEA. I wanted to post about it here in case anyone else ran into the issue, and request that the Kotlin IDEA integration be updated to apply the fix automatically. (I initially posted this issue to the IntelliJ IDEA Users community, but was instructed to come here instead of because the issue is Kotlin-related.)

I had created an Ant build file using Build > Generate Ant Build. Although the project built successfully in IDEA using Build > Build Project, trying to use the Ant build would fail with the error “static import only from classes and interface” in locations where Java code was attempting to import from a Kotlin file.

The solution that I found was to make three changes to the generated Ant build file:

  1. Add the following element prior to the <javac> element:

<typedef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${path.variable.kotlin_bundled}/lib/kotlin-ant.jar" />

  1. Add the element <withKotlin/> as a child of the <javac> element
  2. Remove the attribute fork=“true” from the <javac> element (necessary because withKotlin does not support that option; see KT-9292)

So far, the modified build file appears to be working, both with the bundled copy of Ant and with a standalone Ant installation.

Would it be possible to add a feature to the Kotlin IDEA integration to make these changes automatically as a part of Build > Generate Ant Build with mixed Java/Kotlin projects?


Hi, thanks for sharing! Is there a simple way to reproduce the problem? The feature request for IDEA plugin should be filed in the issue tracker: It would be best if you created an issue there with a sample project and steps to reproduce.

1 Like