为什么找不到spring Boot {}?
Why is springBoot {} not found?
我有一个看起来像这样的构建脚本:
plugins {
id("org.springframework.boot") version "2.2.2.RELEASE" apply false
id("io.spring.dependency-management") version "1.0.9.RELEASE" apply false
id("java")
}
repositories {
mavenCentral()
}
allprojects {
// ...
}
project("core") {
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management") // plugin to manage spring dependencies
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
springBoot {
mainClassName = "com.example.App"
}
}
但是,在构建时,gradle 抱怨
springBoot {
^ Unresolved reference: springBoot
如果我删除 plugins {}
块中 spring 插件上的 apply false
一切正常。
我不明白的是,为什么我在"core"子项目中调用了apply(plugin = )
for spring boot 也无法解决springBoot{}
?
我的理解是,在 plugins {}
中,我将插件导入到项目中但尚未应用。稍后在 core
子项目中,我应用插件并配置 spring 引导。
来自成绩文档https://docs.gradle.org/current/userguide/kotlin_dsl.html#type-safe-accessors
在这种情况下,构建脚本不能使用类型安全访问器,因为 apply() 调用发生在构建脚本的主体中。您必须改用其他技术,如下所示:
类型安全访问器不可用于以下贡献的模型元素:
通过 apply(plugin = "id") 方法应用的插件
项目构建脚本
脚本插件,通过apply(from = "script-plugin.gradle.kts")
通过跨项目配置应用的插件
您必须使用如下配置选项,
configure<SpringBootExtension> {
mainClassName = “ com.example.App”
}
我有一个看起来像这样的构建脚本:
plugins {
id("org.springframework.boot") version "2.2.2.RELEASE" apply false
id("io.spring.dependency-management") version "1.0.9.RELEASE" apply false
id("java")
}
repositories {
mavenCentral()
}
allprojects {
// ...
}
project("core") {
apply(plugin = "org.springframework.boot")
apply(plugin = "io.spring.dependency-management") // plugin to manage spring dependencies
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
springBoot {
mainClassName = "com.example.App"
}
}
但是,在构建时,gradle 抱怨
springBoot {
^ Unresolved reference: springBoot
如果我删除 plugins {}
块中 spring 插件上的 apply false
一切正常。
我不明白的是,为什么我在"core"子项目中调用了apply(plugin = )
for spring boot 也无法解决springBoot{}
?
我的理解是,在 plugins {}
中,我将插件导入到项目中但尚未应用。稍后在 core
子项目中,我应用插件并配置 spring 引导。
来自成绩文档https://docs.gradle.org/current/userguide/kotlin_dsl.html#type-safe-accessors
在这种情况下,构建脚本不能使用类型安全访问器,因为 apply() 调用发生在构建脚本的主体中。您必须改用其他技术,如下所示:
类型安全访问器不可用于以下贡献的模型元素:
通过 apply(plugin = "id") 方法应用的插件
项目构建脚本
脚本插件,通过apply(from = "script-plugin.gradle.kts")
通过跨项目配置应用的插件
您必须使用如下配置选项,
configure<SpringBootExtension> {
mainClassName = “ com.example.App”
}