我从Gradle 5.0升级(从4.10.2开始)遇到错误,并将代码隔离到以下代码段:
dependencyManagement {
dependencies {
compileOnly "org.projectlombok:lombok:1.18.2"
testCompileOnly "org.projectlombok:lombok:1.18.2"
annotationProcessor "org.projectlombok:lombok:1.18.2"
testAnnotationProcessor "org.projectlombok:lombok:1.18.2"
dependency "com.google.guava:guava:$guavaVersion"
dependency "mysql:mysql-connector-java:$mysqlversion"
dependency "com.google.inject:guice:${guiceVersion}"
dependency "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.1.RELEASE"
}
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
mavenBom "com.amazonaws:aws-java-sdk-bom:${awsVersion}"
}
}
没有龙目岛行,代码可以正常工作。
dependencyManagement {
dependencies {
dependency "com.google.guava:guava:$guavaVersion"
dependency "mysql:mysql-connector-java:$mysqlversion"
dependency "com.google.inject:guice:${guiceVersion}"
dependency "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.1.RELEASE"
}
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
mavenBom "com.amazonaws:aws-java-sdk-bom:${awsVersion}"
}
}
错误为class java.lang.String cannot be cast to class groovy.lang.Closure (java.lang.String is in module java.base of loader 'bootstrap'; groovy.lang.Closure is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @675d3402)
由于Gradle 5注释处理的更改,我正在更改lombok的声明方式。
答案 0 :(得分:0)
在dependencies
下的dependencyManagement
块中,不应有任何具体的依赖项声明,例如。 compileOnly
,testCompileOnly
等。只允许使用dependency
,因为您可以在其中定义具有适当版本的所有-well-依赖项,以供以后在子项目中使用。