Skip to content

[Java] Fix generated build.gradle incompatible with Gradle 9 - #24649

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/gradle9-build-compat
Aug 9, 2026
Merged

[Java] Fix generated build.gradle incompatible with Gradle 9#24649
wing328 merged 1 commit into
OpenAPITools:masterfrom
seonwooj0810:fix/gradle9-build-compat

Conversation

@seonwooj0810

@seonwooj0810 seonwooj0810 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Description

Gradle 9 removed the implicit Project.sourceCompatibility / targetCompatibility convenience properties (previously provided via Groovy convention mapping) as well as JavaExec.main. The Java client build.gradle.mustache templates still used both directly, so every generated Gradle project failed to even configure under Gradle 9:

FAILURE: Build failed with an exception.

* Where:
Build file '.../build.gradle' line: 81

* What went wrong:
A problem occurred evaluating root project 'client'.
> Could not set unknown property 'sourceCompatibility' for root project 'client' of type org.gradle.api.Project.

This matches the reproduction and suggested fix in #22084, where @wing328 asked for a PR implementing exactly this template update.

Fix

  • Wrapped sourceCompatibility / targetCompatibility in a java { } extension block (valid on Gradle 4+ through 9) instead of assigning them as top-level project properties, across all Java client libraries: default, apache-httpclient, feign, google-api-client, jersey2, jersey3, native, okhttp-gson, rest-assured, resteasy, retrofit2, vertx.
  • While verifying a full Gradle 9 build of each library, found a second, closely related Gradle 9 removal in the same templates: the execute task's main = System.getProperty('mainClass') (JavaExec.main was removed in Gradle 9, replaced by mainClass). Renamed it to mainClass in the same set of libraries (webclient, resttemplate, and restclient already used mainClass and were unaffected).

Verification done

  • Rebuilt openapi-generator-cli from source and generated a sample client for every affected library (resttemplate, webclient, okhttp-gson, jersey3, native, feign, retrofit2, apache-httpclient, rest-assured, google-api-client, resteasy, jersey2, restclient, vertx), including the useJackson3/java17/useJakartaEe/useVertx5 conditional branches.
  • Reproduced the exact reported failure against a real Gradle 9.0.0 distribution on the unfixed template (Could not set unknown property 'sourceCompatibility'), then confirmed compileJava now succeeds with the fix on 11/13 libraries out of the box. The remaining 2 (resteasy, vertx) fail only on an unrelated, pre-existing dependency resolution problem (a pinned jackson_version that doesn't correspond to a published artifact) — unrelated to this fix and reproducible identically before/after this change.
  • ./mvnw -pl modules/openapi-generator -am test -Dtest=JavaClientCodegenTest -Dsurefire.failIfNoSpecifiedTests=false → 265 tests, 0 failures/errors.
  • Regenerated all 88 affected sample configs via ./bin/generate-samples.sh and confirmed the resulting samples/**/build.gradle diffs contain exactly this change (no unrelated drift).

Fixes #22084


Summary by cubic

Make generated Java clients compatible with Gradle 9 by moving Java version settings into the java {} block and replacing JavaExec.main with mainClass. Projects now configure and build on Gradle 9 without errors (fixes #22084).

  • Bug Fixes
    • Wrapped sourceCompatibility/targetCompatibility in a java {} extension across all Java client templates (works on Gradle 4–9).
    • Renamed JavaExec.main to mainClass in execute tasks where needed; templates already using mainClass were unchanged.

Written for commit 981a41e. Summary will update on new commits.

Review in cubic

Gradle 9 removed the implicit Project.sourceCompatibility /
targetCompatibility convenience properties and JavaExec.main; both were
still used directly (outside the java {} extension and as `main =`) in
the Java client build.gradle.mustache templates, so every generated
project failed to even configure under Gradle 9 with e.g.:

  Could not set unknown property 'sourceCompatibility' for root
  project '...' of type org.gradle.api.Project.

Wrap sourceCompatibility/targetCompatibility in a `java { }` block and
rename JavaExec's `main` to `mainClass` across all affected libraries
(default, apache-httpclient, feign, google-api-client, jersey2,
jersey3, native, okhttp-gson, rest-assured, resteasy, retrofit2,
vertx). webclient/resttemplate/restclient already used `mainClass` and
only needed the sourceCompatibility fix.

Fixes OpenAPITools#22084

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 103 files

Re-trigger cubic

@wing328
wing328 merged commit dc80646 into OpenAPITools:master Aug 9, 2026
153 of 154 checks passed
@wing328 wing328 added this to the 7.25.0 milestone Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [Java] Generated build.gradle incompatible with Gradle v9.x and Java 17+

2 participants