Skip to end of metadata
Go to start of metadata

Ant

Defining <kotlinc> task using local Kotlin setup

<kotlinc> attributes

Name
Description
Required
Default Value
src
Kotlin source file or directory to compile "src" or "module" needs to be specified  
module
Kotlin module to compile "src" or "module" needs to be specified  
output
Destination directory If "src" is used - "output" or "jar" needs to be specified  
jar
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
"moduleName.jar"
classpath
Compilation class path
false
 
classpathref
Compilation class path reference
false
 
stdlib
Path to "kotlin-runtime.jar"
false
""
includeRuntime
If "jar" is used - whether Kotlin runtime library is included
false
true

<kotlinc> accepts a nested <classpath> element, similarly to <javac>.

Examples

"Smoke.kts":

"Smoke.kt":

Classpath examples

Maven

"kotlin-maven-plugin" compiles Kotlin sources and modules.
Note: only Maven 3 is supported for now.

The old "kotlin-maven-plugin" is no longer supported.

Repositories

Kotlin maven artifacts are published on http://repository.jetbrains.com.

Add references to it in your pom or settings file:

Versions

Define Kotlin version in kotlin.version. Possible values are:

  • X.Y-SNAPSHOT - snapshot versions for X.Y release, updated with every successful build on our continuous integration server.
    Highly unstable, recommended for testing new compiler features.
    Currently, all builds are published as 0.1-SNAPSHOT.
  • X.Y.Z - release or milestone version X.Y.Z, updated manually, stable.

Here's the table of versions corresponding to milestone codes:

Milestone Version
M1 0.1.2090
M2 0.1.2580
M3 0.1.3395
M3.1 0.4.68
M4 0.4.297
M5 0.5.1
M5.1 0.5.162
M5.2 0.5.429

Dependencies

Kotlin has an extensive standard library, use it in your program:

Compile Kotlin sources

Specify source directories in <build> tag:

Reference kotlin-maven-plugin to compile sources:

Compile mixed Kotlin/Java sources

To compile mixed code applications Kotlin compiler should be invoked before Java compiler.
In maven terms that means kotlin-maven-plugin should be run before maven-compiler-plugin.

It could be done by moving Kotlin compilation to previous phase, process-sources (feel free to suggest a better solution if you have one):

Example

Download a simple hello world application here.

Gradle

"kotlin-gradle-plugin" (available since Kotlin M5.2) compiles Kotlin sources and modules.

Repositories and versions are similar to kotlin-maven-plugin.

Kotlin-only module

Examples

Download examples here (kotlin-only and mixed java/kotlin projects included)

Griffon

See "griffon-kotlin-plugin".

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Feb 08, 2013

    Can a single module have both Java/Kotlin files in it?  We would like to start using Kotlin but have a large Java base we cannot transform all to Kotlin.  It would be ideal to just start writing new code with Kotlin allowing Java to reference the Kotlin and Kotlin to reference Java.  We build our application with Ant.  

    1. Feb 09, 2013

      Yes, this is certainly possible.
      When building such a sourcebase with ANT, call a kotlinc first (it can read java source files too) and then javac, adding kotlinc output as additional classpath entry.

  2. Mar 06, 2013

    What about building JavaScript, particularly with Ant?  I'm most interested in Kotlin as a shared code base between JVM code (Java/Scala) and JavaScript.

    1. Mar 07, 2013

      Currently the capability of sharing the same code across two platforms is limited (because only small parts of the standard library are available on JS so far), but this will be improved.

    2. Apr 08, 2013

      Ant task for JavaScript is not implemented yet. Watch/vote for http://youtrack.jetbrains.com/issue/KT-3436

  3. Apr 06, 2013

    About the new (as of M5.2) gradle plugin: it seems the tests are not executed at all.

    I downloaded the provided kotlin-examples-master.zip and ran {{./gradlew clean test}} but there is no test report generated.
    Adding a fail() does not result in a build failure.

    Am I missing something?

    1. Apr 08, 2013

      Indeed, we have an issue, sorry for that.

      The workaround is to add a single line:

      The issue itself is described here: http://youtrack.jetbrains.com/issue/KT-3490 please watch/vote for it

  4. Apr 08, 2013

    How do I specify a directory containing KAnnotator-generated Annotations using the gradle plugin?
    Thx

    1. Apr 08, 2013

      You can find an example in hello-world project