刚刚更新到Gradle 5.0,现在我得到了pop-up hints:
buildscript {
ext.kotlin_version = '1.3.10'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // 'classpath' in 'org.gradle.api.artifacts.dsl.DependencyHandler' cannot be applied to '(groovy.lang.GString)'
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
classpath "org.junit.platform:junit-platform-gradle-plugin:1.2.0"
}
}
plugins {
id 'maven'
id "org.jetbrains.kotlin.jvm" version "1.3.10"
id "com.github.johnrengelman.shadow" version "2.0.4"
}
ext.moduleName = 'com.github.kotlin_graphics.kotlin_unsigned'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // 'implementation' in 'org.gradle.api.artifacts.dsl.DependencyHandler' cannot be applied to '(groovy.lang.GString)'
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.1.10'
}
repositories {
mavenCentral()
maven { url = "https://dl.bintray.com/kotlin/kotlin-eap" }
maven { url = "https://jitpack.io" }
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
jar {
inputs.property("moduleName", moduleName)
manifest { // here
attributes('Automatic-Module-Name': moduleName)
}
}
test {
useJUnitPlatform()
}
为什么?那我该怎么解决?
答案 0 :(得分:0)
您没有实际的实际问题要担心。根据更新的问题和屏幕截图,您会弹出不正确的IDE静态分析提示。您没有来自Gradle的任何错误或警告消息。您的文本编辑器中有些东西会引起误解。
这种情况有时发生在您所显示的代码(例如您的build.gradle
是Groovy代码)无法完全解释为知道正确的类型的时候。在这种情况下,没有错。这是一条红鲱鱼,应该忽略。
您可以放心地忽略此IDE消息,有时会在build.gradle
文件上收到其他误导性消息。如果您想在编写构建文件时获得正确的IDE帮助,请切换到Gradle构建文件的完全类型安全的Kotlin版本。对于您收到的消息,Groovy版本在IDE中绝不是完美的。
在空目录上测试build.gradle
:
$ ./gradlew build
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 0s
7 actionable tasks: 2 executed, 5 up-to-date
并直接从GitHub存储库中对其进行测试:(注意:警告中有一些危险的类路径问题,应予以解决)
$ ./gradlew clean build
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/Users/xyz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.50/9fab8887f91c8e17cce1a7522f45dc25976e57b9/kotlin-reflect-1.2.50.jar (version 1.2)
/Users/xyz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.31/95d6a67e8787280a82a2059e54e4db7ac6cfe74/kotlin-stdlib-jdk7-1.2.31.jar (version 1.2)
/Users/xyz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.10/b178c1501609c6e4ee8be635513cb023a466457d/kotlin-stdlib-1.3.10.jar (version 1.3)
/Users/xyz/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.10/1b19d99229dcedad7caf50534dce38fe82845269/kotlin-stdlib-common-1.3.10.jar (version 1.3)
w: Consider providing an explicit dependency on kotlin-reflect 1.3 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
> Task :test FAILED
unsigned.Ubyte test > ubyte FAILED
org.opentest4j.AssertionFailedError at ubyte.kt:35
unsigned.Uint test > uint FAILED
org.opentest4j.AssertionFailedError at uint.kt:32
unsigned.Ulong test > ulong FAILED
org.opentest4j.AssertionFailedError at ulong.kt:29
unsigned.Ushort test > ushort FAILED
org.opentest4j.AssertionFailedError at ushort.kt:30
6 tests completed, 4 failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/xyz/.../kotlin-unsigned/build/reports/tests/test/index.html
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 5s
10 actionable tasks: 10 executed
请注意,Gradle 不报告任何消息或错误。只有您的IDE。
答案 1 :(得分:0)
您需要将警告模式更改为全部或全部,以避免提示。
将org.gradle.warning.mode=all
或org.gradle.warning.mode=none
添加到您的gradle.properties
答案 2 :(得分:-1)