Skip to content

Gradle: rename mainClassName to mainClass in application block#7540

Merged
timtebeek merged 2 commits intomainfrom
tim/migrate-gradle9-fixes
May 1, 2026
Merged

Gradle: rename mainClassName to mainClass in application block#7540
timtebeek merged 2 commits intomainfrom
tim/migrate-gradle9-fixes

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

The mainClassName property on the Gradle application extension was deprecated in Gradle 6.4 and removed in Gradle 9.0. This adds org.openrewrite.gradle.gradle9.UseMainClassPropertyForApplication, which renames mainClassName to mainClass inside the application { ... } block (Groovy and Kotlin DSL), and wires it into MigrateToGradle9 alongside the existing UseMainClassProperty (which handles JavaExec.main).

The recipe uses a cursor-message guard so it only fires inside an application invocation, leaving unrelated identifiers (e.g. ext { mainClassName = ... }) untouched. Top-level mainClassName = "..." (the rare convention-property case) is intentionally out of scope — wrapping that into a synthesized application block is materially more complex and best handled separately if it surfaces in real codebases.

Test plan

  • ./gradlew :rewrite-gradle:test --tests "*UseMainClassPropertyForApplicationTest"
  • ./gradlew :rewrite-gradle:test --tests "*MigrateToGradle9Test"

The `mainClassName` property on the application extension was deprecated
in Gradle 6.4 and removed in Gradle 9.0. Add a recipe that renames it
inside the `application { ... }` block (Groovy and Kotlin DSL) and wire
it into `MigrateToGradle9`.
@timtebeek timtebeek merged commit e3261c6 into main May 1, 2026
1 check passed
@timtebeek timtebeek deleted the tim/migrate-gradle9-fixes branch May 1, 2026 14:28
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant