14.2 为 EAP 配置你的构建

原文链接: https://kotlinlang.org/docs/configure-build-for-eap.html

14.2 为 EAP 配置你的构建

目前没有可用的预览版本。

要把构建配置为使用 Kotlin 的 EAP 版本,你需要:

  • 指定 Kotlin 的 EAP 版本。可用的 EAP 版本列在这里。
  • 把依赖的版本改为 EAP 版本。Kotlin 的 EAP 版本可能无法与上一正式版本的库配合工作。

下面的步骤介绍如何在 Gradle 和 Maven 中配置你的构建:

在 Gradle 中配置

本节介绍如何:

调整 Kotlin 版本

在 build.gradle(.kts) 的 plugins 块中,把 KOTLIN-EAP-VERSION 改为实际的 EAP 版本,例如 2.4.20-RC3。可用的 EAP 版本列在这里。

或者,你也可以在 settings.gradle(.kts) 的 pluginManagement 块中指定 EAP 版本——详情请参阅 Gradle 文档。

下面是 Multiplatform 项目的一个例子。

Kotlin

1
2
3
4
5
6
7
8
plugins {
    java
    kotlin("multiplatform") version "KOTLIN-EAP-VERSION"
}

repositories {
    mavenCentral()
}

Groovy

1
2
3
4
5
6
7
8
plugins {
    id 'java'
    id 'org.jetbrains.kotlin.multiplatform' version 'KOTLIN-EAP-VERSION'
}

repositories {
    mavenCentral()
}

调整依赖中的版本

如果你在项目中使用了 kotlinx 库,这些库的版本可能与 Kotlin 的 EAP 版本不兼容。

要解决这个问题,你需要在依赖中指定兼容的库版本。兼容库的列表见 EAP 构建详情。

注意: 大多数情况下,我们只针对某个版本的第一个 EAP 版本创建库,而这些库可以与该版本的后续 EAP 版本配合使用。如果后续 EAP 版本中存在不兼容的变更,我们会发布该库的新版本。

下面是一个例子。

对于 kotlinx.coroutines 库,请添加与 2.4.20-RC3 兼容的版本号——1.11.0。

Kotlin

1
2
3
dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0")
}

Groovy

1
2
3
dependencies {
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.11.0"
}

在 Maven 中配置

在示例 Maven 项目定义中,把 KOTLIN-EAP-VERSION 替换为实际版本,例如 2.4.20-RC3。可用的 EAP 版本列在这里。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<project ...>
    <properties>
        <kotlin.version>KOTLIN-EAP-VERSION</kotlin.version>
    </properties>

    <repositories>
        <repository>
           <id>mavenCentral</id>
           <url>https://repo1.maven.org/maven2/</url>
        </repository>
    </repositories>

    <pluginRepositories>
       <pluginRepository>
          <id>mavenCentral</id>
          <url>https://repo1.maven.org/maven2/</url>
       </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                ...
            </plugin>
        </plugins>
    </build>
</project>

如果遇到问题