{toc:style=disc|indent=20px}
h1. Ant


h2. Defining {{*<kotlinc>*}} task using local Kotlin setup

One way to define Ant's {{*<kotlinc>*}} task is by using your local Kotlin setup and {{*KOTLIN_HOME*}} environment variable:

{code:xml}
<property environment="env"/>
<taskdef resource    = "org/jetbrains/jet/buildtools/ant/antlib.xml">
    <classpath>
        <fileset dir = "${env.KOTLIN_HOME}/lib" includes = "*.jar"/>
    </classpath>
</taskdef>
{code}


Alternatively, you can copy all jar files from Kotlin distribution to Ant's {{"lib"}} folder.


h2. Defining {{*<kotlinc>*}} task using Ivy

Another way to define Ant's {{*<kotlinc>*}} task is by using Ivy:

{{"ivyconf.xml"}}:

{code:xml}
<ivysettings>
    <property name='ivy.checksums' value=''/>
    <caches defaultCache="${user.home}/.ivy/cache"/>
    <settings defaultResolver="sonatype-repo"/>
    <statuses>
        <status name='integration' integration='true'/>
    </statuses>
    <resolvers>
        <url name="sonatype-repo" m2compatible="true">
            <artifact pattern="https://oss.sonatype.org/content/repositories/central/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]"/>
        </url>
        <url name='jetbrains-repo'   alwaysCheckExactRevision='yes' checkmodified='true'>
            <ivy      pattern='http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/teamcity-ivy.xml'/>
            <artifact pattern='http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/[artifact](.[ext])'/>
        </url>
    </resolvers>
    <modules>
        <module organisation='org' name='bt343' matcher='regexp' resolver='jetbrains-repo'/>
        <module organisation='org' name='bt344' matcher='regexp' resolver='jetbrains-repo'/>
    </modules>
</ivysettings>
{code}

{{"ivy.xml"}}:

{code:xml}
<ivy-module version="1.3">
    <info organisation="com.jetbrains" module="kotlin"/>
    <dependencies>
        <!-- Kotlin build: http://teamcity.jetbrains.com/viewType.html?buildTypeId=bt344 -->
        <!--               http://teamcity.jetbrains.com/guestAuth/repository/download/bt344/latest.lastSuccessful/teamcity-ivy.xml -->
        <dependency org="org" name="bt344" rev="latest.lastSuccessful">
            <include ext="jar" matcher="exactOrRegexp"/>
        </dependency>
        <!-- IDEA build: http://teamcity.jetbrains.com/viewType.html?buildTypeId=bt343 -->
        <!--             http://teamcity.jetbrains.com/guestAuth/repository/download/bt343/latest.lastSuccessful/teamcity-ivy.xml -->
        <dependency org="org" name="bt343" rev="latest.lastSuccessful">
            <include name="core/.*" ext="jar" matcher="exactOrRegexp"/>
        </dependency>
        <dependency org="asm" name="asm-util" rev="3.3.1"/>
    </dependencies>
</ivy-module>
{code}

{{"build.xml"}}:

{code:xml}
<!-- Copy Ivy jar and all its dependencies to Ant's "lib": http://www.apache.org/dist/ant/ivy/2.2.0/apache-ivy-2.2.0-bin-with-deps.zip -->
<taskdef uri="antlib:org.apache.ivy.ant" resource="org/apache/ivy/ant/antlib.xml"/>
<ivy:configure file="${basedir}/ivyconf.xml"/>
<ivy:resolve   file="${basedir}/ivy.xml"/>
<ivy:cachepath pathid="kotlin.classpath" organisation="org" revision="latest.lastSuccessful"/>

<taskdef resource = "org/jetbrains/jet/buildtools/ant/antlib.xml">
    <classpath>
        <path refid="kotlin.classpath"/>
    </classpath>
</taskdef>
{code}

h2. {{*<kotlinc>*}} attributes


|| {align:center}Name{align} || {align:center}Description{align} || {align:center}Required{align} || {align:center}Default Value{align} ||
| {align:center}{{*src*}}{align} | Kotlin source file or directory to compile | {{"src"}} or {{"module"}} needs to be specified |  &nbsp; |
| {align:center}{{*module*}}{align} | Kotlin [module|http://confluence.jetbrains.net/display/Kotlin/Modules+and+Compilation] to compile | {{"src"}} or {{"module"}} needs to be specified |  &nbsp; |
| {align:center}{{*output*}}{align} | Destination directory | If {{"src"}} is used - {{"output"}} or {{"jar"}} needs to be specified |  &nbsp; |
| {align:center}{{*jar*}}{align} | Destination jar file | If {{"src"}} is used - {{"output"}} or {{"jar"}} needs to be specified
If {{"module"}} is used - only {{"jar"}} can be specified or it can be omitted | {align:center}{{"moduleName.jar"}}{align} |
| {align:center}{{*classpath*}}{align} | Compilation class path | {align:center}{{false}}{align} | &nbsp; |
| {align:center}{{*classpathref*}}{align} | Compilation class path reference | {align:center}{{false}}{align} | &nbsp; |
| {align:center}{{*stdlib*}}{align} | Path to {{"kotlin-runtime.jar"}} | {align:center}{{false}}{align} |  {align:center}{{""}}{align} |
| {align:center}{{*includeRuntime*}}{align} | If {{"jar"}} is used - whether Kotlin runtime library is included | {align:center}{{false}}{align} | {align:center}{{true}}{align} |


{{<kotlinc>}} accepts a nested {{<classpath>}} element, similarly to [{{<javac>}}|http://evgeny-goldin.org/javadoc/ant/Tasks/javac.html].


h2. Examples


{code:xml}
<kotlinc src = "test/longer-examples/Bottles.kt" output = "dist"/>
<kotlinc src = "test/longer-examples"            output = "dist"/>

<kotlinc src = "test/longer-examples/Bottles.kt" jar = "dist.jar"/>
<kotlinc src = "test/longer-examples"            jar = "dist.jar"/>

<kotlinc module = "test/modules/smoke/Smoke.kts" jar =  "dist.jar"/>
<kotlinc module = "test/modules/smoke/Smoke.kts"/>   => "smoke.jar"
{code}

{{"Smoke.kts"}}:

{code}
import kotlin.modules.*

fun project() {
    module("smoke") {
        sources += "Smoke.kt"
    }
}
{code}
{{"Smoke.kt"}}:

{code}
package Smoke

fun main(args: Array<String>) {
    print("${args[0]}|${args[1]}|${args[2]}")
}
{code}


h3. Classpath examples


{code:xml}
<path id="junit-jar">
    <fileset file="lib/junit.jar"/>
</path>

<kotlinc src = "src/unit-tests" jar = "tests.jar" classpath    = "lib/junit.jar"/>

<kotlinc src = "src/unit-tests" jar = "tests.jar" classpathref = "junit-jar"/>

<kotlinc src = "src/unit-tests" jar = "tests.jar">
    <classpath>
        <path refid="junit-jar"/>
    </classpath>
</kotlinc>

<kotlinc src = "src/unit-tests" jar = "tests.jar">
    <classpath>
        <fileset file="lib/junit.jar"/>
    </classpath>
</kotlinc>
{code}


h1. Maven

See [{{"kotlin-maven-plugin"}}|http://evgeny-goldin.com/wiki/Kotlin-maven-plugin].

h1. Gradle