Using Ant
- kotlin2js: Kotlin compiler targeting JavaScript;
- withKotlin: Task to compile Kotlin files when using the standard javac Ant task.
These tasks are defined in the kotlin-ant.jar library which is located in the lib folder for the Kotlin Compiler Ant version 1.8.2+ is required.
Targeting JVM with Kotlin-only source
When the project consists of exclusively Kotlin source code, the easiest way to compile the project is to use the kotlinc task:
If a project consists of multiple source roots, use src as elements to define paths:
<project name="Ant Task Test" default="build">
<typedef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="build">
<kotlinc output="hello.jar">
<src path="root1"/>
<src path="root2"/>
</kotlinc>
</target>
</project>
Targeting JVM with Kotlin and Java source
If a project consists of both Kotlin and Java source code, while it is possible to use kotlinc, to avoid repetition of task parameters, it is recommended to use withKotlin task:
Targeting JavaScript with Prefix, PostFix and sourcemap options
<project name="Ant Task Test" default="build">
<taskdef resource="org/jetbrains/kotlin/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="build">
</target>
</project>
The metaInfo
option is useful, if you want to distribute the result of translation as a Kotlin/JavaScript library. If metaInfo
was set to true
, then during compilation additional JS file with binary metadata will be created. This file should be distributed together with the result of translation:
References
Complete list of elements and attributes are listed below:
<kotlinc src="${test.data}/hello.kt" output="${temp}/hello.jar">
<compilerarg value="-Xno-inline"/>
<compilerarg line="-Xno-call-assertions -Xno-param-assertions"/>
<compilerarg value="-Xno-optimize"/>
</kotlinc>
The full list of arguments that can be used is shown when you run .