[Java] Fix generated build.gradle incompatible with Gradle 9 - #24649
Merged
wing328 merged 1 commit intoAug 9, 2026
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Gradle 9 removed the implicit
Project.sourceCompatibility/targetCompatibilityconvenience properties (previously provided via Groovy convention mapping) as well asJavaExec.main. The Java clientbuild.gradle.mustachetemplates still used both directly, so every generated Gradle project failed to even configure under Gradle 9:This matches the reproduction and suggested fix in #22084, where @wing328 asked for a PR implementing exactly this template update.
Fix
sourceCompatibility/targetCompatibilityin ajava { }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.executetask'smain = System.getProperty('mainClass')(JavaExec.mainwas removed in Gradle 9, replaced bymainClass). Renamed it tomainClassin the same set of libraries (webclient,resttemplate, andrestclientalready usedmainClassand were unaffected).Verification done
openapi-generator-clifrom 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 theuseJackson3/java17/useJakartaEe/useVertx5conditional branches.Could not set unknown property 'sourceCompatibility'), then confirmedcompileJavanow 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 pinnedjackson_versionthat 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../bin/generate-samples.shand confirmed the resultingsamples/**/build.gradlediffs 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 replacingJavaExec.mainwithmainClass. Projects now configure and build on Gradle 9 without errors (fixes #22084).sourceCompatibility/targetCompatibilityin ajava {}extension across all Java client templates (works on Gradle 4–9).JavaExec.maintomainClassinexecutetasks where needed; templates already usingmainClasswere unchanged.Written for commit 981a41e. Summary will update on new commits.