添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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:

  • 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" />

  • Add the element <withKotlin/> as a child of the <javac> element
  • 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?

    Thanks!