首页 > 解决方案 > Kotlin Gradle 使用依赖项

问题描述

我正在尝试org.apache.commons.net.*使用 Gradle 和命令行在 Kotlin 中包含库。

在我的build.gradle.kts文件的依赖项中,我写道:

compile 'commons-net:commons-net:3.6'正如apache文档中所说,但它给了我一个奇怪的错误:

> Configure project :
e: D:\core\Confidential\Learn\Kotlin\build.gradle.kts:30:13: Too many characters
 in a character literal ''commons-net:commons-net:3.6''

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\core\Confidential\Learn\Kotlin\build.gradle.kts' line: 30

* What went wrong:
Script compilation error:

  Line 30:     compile('commons-net:commons-net:3.6')
                       ^ Too many characters in a character literal ''commons-ne
t:commons-net:3.6''

1 error

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

(我也试过compile 'commons-net:commons-net:3.6'and compile group: 'commons-net', name: 'commons-net', version: '3.6')。

我对 Kotlin 完全陌生,在开始在 IDEA 上进行 Android 开发之前,我正在尝试熟悉它。

谢谢。

标签: gradlekotlingradle-kotlin-dsl

解决方案


就像在 Java 中一样,'适用于字符文字,"也适用于字符串文字。

你想要"commons-net:commons-net:3.6"

并且compile()已弃用。使用implementation().


推荐阅读