diff --git a/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/KotlinScriptTarget.kt b/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/KotlinScriptTarget.kt index 346d5c0cd..494b7ddb9 100644 --- a/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/KotlinScriptTarget.kt +++ b/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/KotlinScriptTarget.kt @@ -93,7 +93,7 @@ fun projectScriptTarget( KotlinScriptTarget( host = KotlinScriptHost(project, scriptSource, serviceRegistryOf(project), baseScope, scriptHandler), scriptTemplate = KotlinBuildScript::class, - buildscriptBlockTemplate = KotlinBuildscriptBlock::class.takeIf { topLevelScript }, + buildscriptBlockTemplate = KotlinBuildscriptBlock::class, pluginsBlockTemplate = KotlinPluginsBlock::class.takeIf { topLevelScript }, accessorsClassPath = accessorsClassPathProviderFor(project, topLevelScript), onPrepare = { diff --git a/provider/src/test/kotlin/org/gradle/kotlin/dsl/integration/GradleKotlinDslIntegrationTest.kt b/provider/src/test/kotlin/org/gradle/kotlin/dsl/integration/GradleKotlinDslIntegrationTest.kt index 4e8c90d63..196721211 100644 --- a/provider/src/test/kotlin/org/gradle/kotlin/dsl/integration/GradleKotlinDslIntegrationTest.kt +++ b/provider/src/test/kotlin/org/gradle/kotlin/dsl/integration/GradleKotlinDslIntegrationTest.kt @@ -64,6 +64,33 @@ class GradleKotlinDslIntegrationTest : AbstractIntegrationTest() { build("compute").output.contains("*42*")) } + @Test + fun `given a script plugin with a buildscript block, it will be used to compute its classpath`() { + + withClassJar("fixture.jar", DeepThought::class.java) + + withFile("other.gradle.kts", """ + buildscript { + dependencies { classpath(files("fixture.jar")) } + } + + task("compute") { + doLast { + val computer = ${DeepThought::class.qualifiedName}() + val answer = computer.compute() + println("*" + answer + "*") + } + } + """) + + withBuildScript(""" + apply(from = "other.gradle.kts") + """) + + assert( + build("compute").output.contains("*42*")) + } + @Test fun `given a buildSrc dir, it will be added to the compilation classpath`() {