247 lines
7.4 KiB
Plaintext
247 lines
7.4 KiB
Plaintext
{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. {{*<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 | |
|
|
| {align:center}{{*module*}}{align} | Kotlin [module|http://confluence.jetbrains.net/display/Kotlin/Modules+and+Compilation] to compile | {{"src"}} or {{"module"}} needs to be specified | |
|
|
| {align:center}{{*output*}}{align} | Destination directory | If {{"src"}} is used - {{"output"}} or {{"jar"}} needs to be specified | |
|
|
| {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} | |
|
|
| {align:center}{{*classpathref*}}{align} | Compilation class path reference | {align:center}{{false}}{align} | |
|
|
| {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
|
|
|
|
"kotlin-maven-plugin" compiles Kotlin sources and modules.
|
|
Note: only Maven 3 is supported for now.
|
|
|
|
{note}The old [{{"kotlin-maven-plugin"}}|http://evgeny-goldin.com/wiki/Kotlin-maven-plugin] is no longer supported.{note}
|
|
|
|
h3. Repositories
|
|
|
|
Kotlin maven artifacts are published on http://repository.jetbrains.com.
|
|
|
|
Add references to it in your pom or settings file:
|
|
|
|
{code}
|
|
|
|
<repositories>
|
|
<repository>
|
|
<id>jetbrains-release</id>
|
|
<url>http://repository.jetbrains.com/releases</url>
|
|
<releases> <enabled>true</enabled> </releases>
|
|
<snapshots> <enabled>false</enabled> </snapshots>
|
|
</repository>
|
|
<repository>
|
|
<id>jetbrains-snapshots</id>
|
|
<url>http://repository.jetbrains.com/snapshots</url>
|
|
<releases> <enabled>false</enabled> </releases>
|
|
<snapshots> <enabled>true</enabled> </snapshots>
|
|
</repository>
|
|
</repositories>
|
|
|
|
<pluginRepositories>
|
|
<pluginRepository>
|
|
<id>jetbrains-release</id>
|
|
<url>http://repository.jetbrains.com/releases</url>
|
|
<releases> <enabled>true</enabled> </releases>
|
|
<snapshots> <enabled>false</enabled> </snapshots>
|
|
</pluginRepository>
|
|
<pluginRepository>
|
|
<id>jetbrains-snapshots</id>
|
|
<url>http://repository.jetbrains.com/snapshots</url>
|
|
<releases> <enabled>false</enabled> </releases>
|
|
<snapshots> <enabled>true</enabled> </snapshots>
|
|
</pluginRepository>
|
|
</pluginRepositories>
|
|
{code}
|
|
|
|
h3. 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 |
|
|
|
|
h3. Dependencies
|
|
|
|
Kotlin has an extensive standard library, use it in your program:
|
|
|
|
{code}
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
<groupId>org.jetbrains.kotlin</groupId>
|
|
<artifactId>kotlin-stdlib</artifactId>
|
|
<version>${kotlin.version}</version>
|
|
</dependency>
|
|
</dependencies>
|
|
{code}
|
|
|
|
h3. Compile Kotlin sources
|
|
|
|
Specify source directories in <build> tag:
|
|
|
|
{code}
|
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
|
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
|
{code}
|
|
|
|
Reference kotlin-maven-plugin to compile sources:
|
|
|
|
{code}
|
|
|
|
<plugin>
|
|
<artifactId>kotlin-maven-plugin</artifactId>
|
|
<groupId>org.jetbrains.kotlin</groupId>
|
|
<version>${kotlin.version}</version>
|
|
<executions>
|
|
<execution>
|
|
<id>compile</id>
|
|
<phase>compile</phase>
|
|
<goals> <goal>compile</goal> </goals>
|
|
</execution>
|
|
<execution>
|
|
<id>test-compile</id>
|
|
<phase>test-compile</phase>
|
|
<goals> <goal>test-compile</goal> </goals>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
{code}
|
|
|
|
h3. 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):
|
|
|
|
{code}
|
|
<plugin>
|
|
<artifactId>kotlin-maven-plugin</artifactId>
|
|
<groupId>org.jetbrains.kotlin</groupId>
|
|
<version>0.1-SNAPSHOT</version>
|
|
<executions>
|
|
<execution>
|
|
<id>compile</id>
|
|
<phase>process-sources</phase>
|
|
<goals> <goal>compile</goal> </goals>
|
|
</execution>
|
|
<execution>
|
|
<id>test-compile</id>
|
|
<phase>process-test-sources</phase>
|
|
<goals> <goal>test-compile</goal> </goals>
|
|
</execution>
|
|
</executions>
|
|
</plugin>
|
|
{code}
|
|
|
|
h3. Example
|
|
|
|
Download a simple hello world application [here|^maven-hello-world-examples.zip].
|
|
|
|
h1. Gradle
|
|
|
|
_Coming soon._
|
|
|
|
h1. Griffon
|
|
|
|
See [{{"griffon-kotlin-plugin"}}|https://github.com/griffon/griffon-kotlin-plugin]. |