Gradle 在 WSL 上构建无所事事
Gradle build doing nothing on WSL
我正在编写 Kotlin 程序,并使用 Gradle 作为构建系统,这是该语言的惯例。我通常在 Windows 上工作,但现在是在 Linux 上开始测试的时候了,因此为此使用 WSL。安装 Gradle,在 WSL 中克隆了我的代码副本...
(base) a@DESKTOP-4B7M920:~/ayane$ gradle -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------
Build time: 2012-12-21 00:00:00 UTC
Revision: none
Groovy: 2.4.16
Ant: Apache Ant(TM) version 1.10.5 compiled on March 28 2019
JVM: 11.0.7 (Ubuntu 11.0.7+10-post-Ubuntu-2ubuntu218.04)
到目前为止一切顺利,警告有时会发生,似乎并不预示着直接的麻烦。
这是我的构建文件,适用于 Windows:
(base) a@DESKTOP-4B7M920:~/ayane$ cat build.gradle.kts
plugins {
kotlin("jvm") version "1.3.72"
}
repositories {
jcenter()
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("org.junit.jupiter:junit-jupiter:5.6.2")
}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
开始了。
(base) a@DESKTOP-4B7M920:~/ayane$ gradle build
> Task :buildEnvironment
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
<-------------> 0% WAITING
呃?我能理解它是否因为某些先决条件或其他条件不可用而引发错误。但是没有错误,什么都没有?怎么回事?
您目前使用的是 Gradle (1.3.72) 的 Kotlin 插件的最新版本。但是,您使用的是非常旧的 Gradle (4.4.1) 版本。你可以从 Kotlin documentation:
中读到
The Kotlin Gradle plugin 1.3.72 works with Gradle 4.9 and later.
不幸的是,插件没有对此进行检查并给出更正确的错误消息,而不是默默地什么都不做。如果你愿意,我想你可以为 Jetbrains 创建一个问题。
正如在您的问题的评论中提到的,我也强烈建议使用 wrapper。它确保项目是使用您(构建作者)决定的特定声明版本 Gradle 构建的。否则,您将必须记录如何正确设置环境,包括要安装的 Gradle 版本。
同样适用于 Java:请务必清楚地记录需要或支持的版本。
至于在 WSL 中构建,我遇到的唯一问题是远程构建缓存无法正常工作。这是因为我已将 Git 配置为使用 POSIX 行结尾 (LF) 检出源文件,而缓存是在使用 CRLF 行结尾的 Windows 机器上填充的)。听起来您没有使用该功能,但除此之外,我在 WSL 中一切正常。
我正在编写 Kotlin 程序,并使用 Gradle 作为构建系统,这是该语言的惯例。我通常在 Windows 上工作,但现在是在 Linux 上开始测试的时候了,因此为此使用 WSL。安装 Gradle,在 WSL 中克隆了我的代码副本...
(base) a@DESKTOP-4B7M920:~/ayane$ gradle -version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/java/groovy-all.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
------------------------------------------------------------
Gradle 4.4.1
------------------------------------------------------------
Build time: 2012-12-21 00:00:00 UTC
Revision: none
Groovy: 2.4.16
Ant: Apache Ant(TM) version 1.10.5 compiled on March 28 2019
JVM: 11.0.7 (Ubuntu 11.0.7+10-post-Ubuntu-2ubuntu218.04)
到目前为止一切顺利,警告有时会发生,似乎并不预示着直接的麻烦。
这是我的构建文件,适用于 Windows:
(base) a@DESKTOP-4B7M920:~/ayane$ cat build.gradle.kts
plugins {
kotlin("jvm") version "1.3.72"
}
repositories {
jcenter()
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("org.junit.jupiter:junit-jupiter:5.6.2")
}
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
开始了。
(base) a@DESKTOP-4B7M920:~/ayane$ gradle build
> Task :buildEnvironment
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
<-------------> 0% WAITING
呃?我能理解它是否因为某些先决条件或其他条件不可用而引发错误。但是没有错误,什么都没有?怎么回事?
您目前使用的是 Gradle (1.3.72) 的 Kotlin 插件的最新版本。但是,您使用的是非常旧的 Gradle (4.4.1) 版本。你可以从 Kotlin documentation:
中读到The Kotlin Gradle plugin 1.3.72 works with Gradle 4.9 and later.
不幸的是,插件没有对此进行检查并给出更正确的错误消息,而不是默默地什么都不做。如果你愿意,我想你可以为 Jetbrains 创建一个问题。
正如在您的问题的评论中提到的,我也强烈建议使用 wrapper。它确保项目是使用您(构建作者)决定的特定声明版本 Gradle 构建的。否则,您将必须记录如何正确设置环境,包括要安装的 Gradle 版本。
同样适用于 Java:请务必清楚地记录需要或支持的版本。
至于在 WSL 中构建,我遇到的唯一问题是远程构建缓存无法正常工作。这是因为我已将 Git 配置为使用 POSIX 行结尾 (LF) 检出源文件,而缓存是在使用 CRLF 行结尾的 Windows 机器上填充的)。听起来您没有使用该功能,但除此之外,我在 WSL 中一切正常。