Reputation: 8056
I have the following setup in my buildSrc
directory:
└── buildSrc
├── build.gradle.kts
├── settings.gradle.kts
└── src
└── main
└── kotlin
├── base-kotlin-project-convention.gradle.kts
└── spring-boot-dependencies-convention.gradle.kts
I would like to declare dependency management in spring-boot-dependencies-convention.gradle.kts
:
plugins {
id("io.spring.dependency-management")
}
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
and then use it in base-kotlin-project-convention.gradle.kts
like this:
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()
}
Unfortunately I receive the following error:
> 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
Is it possible to reuse different so-called precompiled script plugins in another precompiled script plugins?
Would be great, because when I will configure my module, I would like to use a single plugin:
plugins {
`base-kotlin-project-convention`
}
instead of 2 and more:
plugins {
`spring-boot-dependencies-convention`
`base-kotlin-project-convention`
}
Upvotes: 0
Views: 1571
Reputation: 8056
Found the solution in Gradle docs. id(...)
syntax should be used to reference one precompiled build plugin in another. The following change in base-kotlin-project-convention.gradle.kts
makes it work as expected:
plugins {
kotlin("jvm")
// `spring-boot-dependencies-convention`
id("spring-boot-dependencies-convention")
}
Upvotes: 3