I have gradle multi-project where one of the subproject is shared project which all other subprojects depends on. i.e., compile(project(":shared"))
I am disabling BootJar task by setting enabled = false. This was working in previous Gradle versions but not working after upgrading to 4.2-RC-1
BootJar in shared project still get executed when I run gradle build at multi-project root level.
example project to reproduce this issue : https://github.com/xmlking/reactive-apps
previous issue reference : https://github.com/gradle/kotlin-dsl/issues/393
shared subproject build.gradle.kts
import org.gradle.api.tasks.bundling.Jar
import org.springframework.boot.gradle.tasks.bundling.BootJar
// Prevents common subproject dependencies from being included in the common jar itself.
// Without this, each subproject that included common would include each shared dependency twice.
tasks {
withType<BootJar> {
enabled = false
classifier = "boot"
mainClass = "some.dummy.class"
}
withType<Jar> {
enabled = true
}
}
After changing the above code to this format, it worked as expected. shoud above syntax also work? is it a bug?
import org.gradle.api.tasks.bundling.Jar
import org.springframework.boot.gradle.tasks.bundling.BootJar
// Prevents common subproject dependencies from being included in the common jar itself.
// Without this, each subproject that included common would include each shared dependency twice.
val jar: Jar by tasks
val bootJar: BootJar by tasks
bootJar.enabled = false
jar.enabled = true
Thanks for the report @xmlking
I can reproduce in your project.
Build scans for build -x test from a clean working copy:
I can also reproduce with either:
withType - direct task access:shared - using withType - direct task accessI'd say it's a Gradle issue, not a Kotlin DSL one.
@xmlking could you please report to gradle/gradle instead?
Closing in favor of upstream https://github.com/gradle/gradle/issues/4073
@xmlking, it turns out this is the expected behavior.
Quoting @oehme:
BootJar extends Jar, so the second withType statement reactivates it. This is just expected behavior.
Accessing by name makes more sense here, since the user doesn't actually want to "activate all tasks that extend JAR", but "activate the jar task".
Most helpful comment
@xmlking, it turns out this is the expected behavior.
Quoting @oehme: