我正在使用 gradle 8.0.2 为多模块项目编写构建脚本,在 libs.versions.toml 文件中声明一些依赖项,我的构建脚本如下
buildscript {
repositories {
gradlePluginPortal()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
}
}
plugins{
`kotlin-dsl`
}
group = "xxx"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_19
subprojects {
apply(plugin = "java")
apply(plugin = "checkstyle")
apply(plugin = "maven-publish")
apply(plugin = "com.github.johnrengelman.shadow")
// common deps + repos
repositories {
mavenCentral()
}
dependencies {
api(libs.jsr305)
testImplementation(libs.bundles.junit)
compileOnly(libs.lombok)
annotationProcessor(libs.lombok)
testCompileOnly(libs.lombok)
testAnnotationProcessor(libs.lombok)
}
java {
withSourcesJar()
}
tasks.named<Test>("test") {
useJUnitPlatform()
}
tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}
tasks.withType<Javadoc>() {
options.encoding = "UTF-8"
}
}
Run Code Online (Sandbox Code Playgroud)
我想在每个子项目中应用这些公共依赖项,这些依赖项在 libs.versions.toml 中定义,并且我可以保证 libs.versions.toml 编写没有问题,但我无法让它在子项目中工作
错误:
Extension with name 'libs' does not exist. Currently registered extension names: [ext, base, defaultArtifacts, sourceSets, reporting, javaToolchains, java, testing, checkstyle, publishing, shadow]
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.UnknownDomainObjectException: Extension with name 'libs' does not exist. Currently registered extension names: [ext, base, defaultArtifacts, sourceSets, reporting, javaToolchains, java, testing, checkstyle, publishing, shadow]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
828 次 |
| 最近记录: |