Mixed Java/Kotlin IDEA project - Ant build not working
I have created a mixed Java/Kotlin project in IDEA 2019.3.1 under OpenJDK 13.0.1. I generated a single-file ant build. Build > Build Project works fine within IDEA, whether using the bundled Ant (1.10.5) or my installed version (1.10.7). However, I would like to be able to build the project using my installed Ant from the command line, or possibly other IDEs. However, even after cleaning, attempting to build using Build > buildfilename fails, as does attempting to build from the command line. Errors like the following occur at spots in the Java code that reference Kotlin code:
[javac] C:\ProjectPath\src\com\somemodulepath\SomeJavaClass.java:16: error: cannot find symbol
[javac] import static com.somemodulepath.SomeKotlinFileKt.methodName;
[javac] ^
[javac] symbol: class SomeKotlinFileKt
[javac] location: package com.somemodulepath
[javac] C:\ProjectPath\src\com\somemodulepath\SomeJavaClass.java:16: error: static import only from classes and interfaces
[javac] import static com.somemodulepath.SomeKotlinFileKt.methodName;
[javac] ^
I have not added anything in Build File Properties under any of Properties, Execution > Ant command line, or Additional Classpath. I tried changing the settings in Build > Generate Ant Build; they had no effect.
Based on the info at https://kotlinlang.org/docs/tutorials/command-line.html, I tried adding the following lines in the appropriate places of the generated build.xml file:
<typedef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${path.variable.kotlin_bundled}/lib/kotlin-ant.jar" />
...
<withKotlin/>
Doing so resulted in the error:
<withKotlin> task does not yet support the fork mode
Can anyone provide a good way to create a working Ant build for a mixed Java/Kotlin IDEA project? Thanks!
Please sign in to leave a comment.
Please use https://discuss.kotlinlang.org/ for any questions related to Kotlin.
I'd recommend using Gradle or Maven instead of Ant.
OK, thanks for the advice.
In case anyone else runs into this issue, after finding https://youtrack.jetbrains.com/issue/KT-9292, I see that I misunderstood the nature of the "fork" check. After adding the two Kotlin-related lines mentioned in my previous post and then modifying the <javac> element to remove the fork="true" attribute, the build appears to be succeeding.