从Spring Boot 1.5.8迁移到2.1.5,得到错误消息:
无法为类型org.gradle.api.Project的项目':api'设置未知属性'sourceCompatibility'。
如果我在那行注释,则会收到错误消息:
无法为类型org.gradle.api.Project的项目':api'设置未知属性'targetCompatibility'。
如果我在那行注释,则会收到错误消息:
在类型为org.gradle.api.Project的项目':api'上找不到参数[build_4wobgm6qykoy29e0in3cntga8 $ _run_closure2 @ 1fc9b06d]的方法jar()。
所以这里有些不对劲。我有两个build.gradle
文件,一个在我的根目录中,一个在api
中:
/build.gradle
plugins {
id 'idea'
id 'java'
id 'com.jfrog.bintray' version '1.8.4'
}
apply from: "$rootDir/gradle/git-version.gradle"
version getVersionFromGit()
group 'com.my_org.my_proj'
apply from: "$rootDir/gradle/bintray-vars.gradle"
subprojects {
repositories {
jcenter()
mavenCentral()
}
}
wrapper {
gradleVersion = '4.8.1'
}
/api/build.gradle
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.7.RELEASE'
}
group = rootProject.group
version = rootProject.version
repositories {
maven { url 'https://dl.bintray.com/my-org/spring-utils' }
}
apply from: "$rootDir/gradle/checkstyle.gradle"
sourceCompatibility = 1.8
targetCompatibility = 1.8
jar {
archiveName = 'api.jar'
baseName = project.name
version = project.version
}
test {
doFirst {
environment "BUILD_NUMBER", "1"
}
}
dependencies {
def springBoot = '2.1.5.RELEASE'
runtime group: 'org.springframework.boot', name: 'spring-boot-properties-migrator', version: springBoot
compile group: 'org.flywaydb', name: 'flyway-core', version: '5.2.4'
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.4.3.Final'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: springBoot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-freemarker', version: springBoot
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBoot
testCompile group: 'org.flywaydb.flyway-test-extensions', name: 'flyway-spring-test', version: '4.2.0.2'
}
我在这里显然缺少什么。当然,我一直在关注migration guide和Google搜索。有建议吗?
答案 0 :(得分:2)
您尚未将java
插件应用于您的api
子项目,因此缺少添加到项目中的sourceCompatibility
和targetCompatibility
属性它定义的jar
任务。
在id java
顶部的plugins
块中添加api/build.gradle
应该可以解决问题。