kotlin使用协程的准备工作
本人使用idea + maven构建项目,使用kotlin + 协程 + 编译项目只需编写一下配置文件即可:
启用协程
<!-- 开启kotlin的协程功能 -->
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>0.22.2</version>
</dependency>
</denpendencies>
启用maven的kotlin的编译插件
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<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>
<configuration>
<jvmTarget>1.8</jvmTarget>
<experimentalCoroutines>enable</experimentalCoroutines>
</configuration>
</plugin>
</plugins>
</build>
完成以上工作即可使用在idea上使用kotlin编写和运行kotlin项目了.
网友评论