Skip to content

为抢先体验计划 (EAP

[//]: # (title: 为抢先体验计划 (EAP) 配置构建)

最新 Kotlin EAP 版本:2.3.20-Beta1

探索 Kotlin EAP 发布详情

要将构建配置为使用 Kotlin 的抢先体验计划 (EAP) 版本,您需要:

  • 指定 Kotlin 的 EAP 版本。此处列出了可用的 EAP 版本
  • 将依赖项的版本更改为 EAP 版本。 Kotlin 的 EAP 版本可能无法与之前发布的版本的库配合使用。

以下步骤说明了如何在 Gradle 和 Maven 中配置您的构建:

在 Gradle 中配置

本节说明如何:

调整 Kotlin 版本

build.gradle(.kts)plugins 代码块中,将 KOTLIN-EAP-VERSION 更改为实际的 EAP 版本,例如 2.3.20-Beta1此处列出了可用的 EAP 版本

或者,您也可以在 settings.gradle(.kts)pluginManagement 代码块中指定 EAP 版本——详见 Gradle 文档

以下是多平台项目的一个示例。

kotlin
plugins {
    java
    kotlin("multiplatform") version "KOTLIN-EAP-VERSION"
}

repositories {
    mavenCentral()
}
groovy
plugins {
    id 'java'
    id 'org.jetbrains.kotlin.multiplatform' version 'KOTLIN-EAP-VERSION'
}

repositories {
    mavenCentral()
}

调整依赖项中的版本

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

要解决此问题,您需要在依赖项中指定兼容库的版本。有关兼容库的列表,请参阅 EAP 构建详情

在大多数情况下,我们仅针对特定发布版本的第一个 EAP 版本创建库,这些库可与该版本的后续 EAP 版本配合使用。

如果后续 EAP 版本中存在不兼容的变更,我们将发布库的新版本。

以下是一个示例。

对于 kotlinx.coroutines 库,请添加与 2.3.20-Beta1 兼容的版本号——1.10.2

kotlin
dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
}
groovy
dependencies {
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2"
}

在 Maven 中配置

在 Maven 项目定义示例中,将 KOTLIN-EAP-VERSION 替换为实际版本,例如 2.3.20-Beta1此处列出了可用的 EAP 版本

xml
<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>

如果遇到任何问题