在我的buildSrc目录中有以下设置:
└── buildSrc
├── build.gradle.kts
├── settings.gradle.kts
└── src
└── main
└── kotlin
├── base-kotlin-project-convention.gradle.kts
└── spring-boot-dependencies-convention.gradle.kts我想在spring-boot-dependencies-convention.gradle.kts中声明依赖关系管理
plugins {
id("io.spring.dependency-management")
}
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}然后在base-kotlin-project-convention.gradle.kts中像这样使用它:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm")
`spring-boot-dependencies-convention`
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("io.kotest:kotest-assertions-core-jvm:5.3.2")
testImplementation("org.mockito.kotlin:mockito-kotlin:4.0.0")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}
java.sourceCompatibility = JavaVersion.VERSION_17
tasks.withType<Test> {
useJUnitPlatform()
}不幸的是,我收到了以下错误:
> Task :buildSrc:compilePluginsBlocks FAILED
e: /Users/user/Documents/my-project/buildSrc/build/kotlin-dsl/plugins-blocks/extracted/base-kotlin-project-convention.gradle.kts:5:5: Unresolved reference: `spring-boot-dependencies-convention`
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':buildSrc:compilePluginsBlocks'.
> Script compilation error:
Line 5: `spring-boot-dependencies-convention`
^ Unresolved reference: `spring-boot-dependencies-convention`
1 error在另一个预编译脚本插件中可以重用不同的所谓预编译脚本插件吗?
很好,因为当我配置模块时,我想使用一个插件:
plugins {
`base-kotlin-project-convention`
}而不是两个或更多:
plugins {
`spring-boot-dependencies-convention`
`base-kotlin-project-convention`
}发布于 2022-08-07 12:51:31
在Gradle博士中找到了解决方案。应该使用id(...)语法来引用另一个预编译的构建插件。base-kotlin-project-convention.gradle.kts中的以下更改使其按预期工作:
plugins {
kotlin("jvm")
// `spring-boot-dependencies-convention`
id("spring-boot-dependencies-convention")
}https://stackoverflow.com/questions/73116391
复制相似问题