Gradle Release Plugin 无法禁用Build任务问题求助
Hey there, I’ve run into this exact headache with the Gradle Release Plugin before—just setting buildTasks = [] doesn’t always do the trick because the plugin has implicit task dependencies and default steps that still trigger build/compile tasks behind the scenes. Here’s how I fixed it for my Jenkins automation workflow:
1. Override Default Release Steps & Clear Build Tasks
The plugin runs a predefined sequence of steps for releases. To skip build-related work entirely, you need to explicitly define only the versioning, commit, and tagging steps you care about, while cutting out any build/compile triggers.
Add this to your build.gradle (or build.gradle.kts for Kotlin):
Groovy DSL:
release { // Empty out default build tasks to prevent implicit triggers buildTasks = [] // Skip check tasks (they often trigger compile tasks indirectly) skipChecks = true // Define only the release steps you need—no build/compile here steps = [ 'checkSnapshotDependencies', 'incrementVersion', 'commitReleaseVersion', 'tagRelease', 'incrementVersion', 'commitNewVersion' ] }
Kotlin DSL:
release { buildTasks.set(emptyList()) skipChecks.set(true) steps.set(listOf( "checkSnapshotDependencies", "incrementVersion", "commitReleaseVersion", "tagRelease", "incrementVersion", "commitNewVersion" )) }
2. Remove Implicit Task Dependencies (If Needed)
If the above still doesn’t stop build tasks from running, the release task might have hidden dependencies on build/compile tasks. Explicitly strip those out:
Groovy DSL:
tasks.named('release') { // Remove any dependencies that trigger build/compile/check dependsOn.removeAll { task -> task.name.contains('build') || task.name.contains('compile') || task.name == 'check' } }
Why Your Initial Setup Didn’t Work
The buildTasks property only controls which tasks run during the plugin’s "build phase," but the default step sequence includes tasks like check that indirectly trigger compilation. By defining your own slimmed-down steps and skipping checks, you break that chain entirely.
Since you have a separate Jenkins task for builds, this setup lets the release plugin handle only version bumping, commits, and tagging—no unnecessary compilation or building cluttering up your workflow.
内容的提问来源于stack exchange,提问作者sudhir

