通过 Kotlin.version 定义你想要的 Kotlin 版本。可以有以下的值
配置快照仓库
使用 kotlin 版本的快照,需要在 pom 中这样定义:
kotlin 有一些扩展标准库可以使用。在 pom 文件中使用如下的依赖:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependencies>
只编译 kotlin 源码
编译源码需要在源码文件夹打一个标签:
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<phase>test-compile</phase>
<goals> <goal>test-compile</goal> </goals>
</execution>
</plugin>
为了编译混合代码的应用,Kotlin 编译器应该在 java 编译器之前先工作。在 maven 中意味着 kotlin-maven-plug 应该在 maven-compiler-plugin 之前。
使用扩展的注解
kotlin 使用扩展的注解解析 java 库的信息。为了明确这些注解,你需要像下面这样:
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>0.1-SNAPSHOT</version>
<configuration>
<annotationPaths>
<annotationPath>path to annotations root</annotationPath>
</configuration>
你可以在 Github 仓库参考