Skip to content

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

Closed

Description

@HenningWaack

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using Gradle 9.x, the generated build.gradle file does not work. When running any task on this build.gradle file, the following error is reported:

FAILURE: Build failed with an exception.

* Where:
Build file '/tmp/openapi-generator/modules/openapi-generator-gradle-plugin/samples/local-spec/build/java-resttemplate-api-client/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.

The build.gradle.mustache template does use deprecated and with Gradle 9 invalid syntax:

 apply plugin: 'java'
    apply plugin: 'maven-publish'
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

It should be as follows, which is compatible with Gradle 7+:

java {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

Also some dependencies like Spring and Junit are not valid anymore.

openapi-generator version

Tested with latest main branch, i.e. v7.16.x

Steps to reproduce

Run gradlew buildJavaResttemplateSdk in sample OpenApi Generator project modules/openapi-generator-gradle-plugin/samples/local-spec

Suggest a fix

Update build.gradle.mustache as described above.

Activity

  1. wing328 commented on Oct 6, 2025

    @wing328
    Member

    Update build.gradle.mustache as described above.

    can you please file a PR with the suggested change when you've time? 🙏

  2. HenningWaack commented on Oct 7, 2025

    @HenningWaack
    ContributorAuthor

    @wing328 concerning the Java compatibility, is Java 17 as the target version in the generated build.gradle file ok?

    I see that the project itself uses Java 11. I guess creating Java 17 sources would break some integration test which uses Java 11?

    I saw a couple of templates already using Java17, so it should be fine to add this to all.

    The existing templates using Java17 also use the flag java17 to conditionally set which Java version to use, e.g. here in src/main/resources/Java/libraries/webclient/build.gradle.mustache:

        {{#java17}}
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
        {{/java17}}
        {{^java17}}
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
        {{/java17}}
    

    I would use this in a similar way in the other templates, too.

  3. wing328 commented on Oct 8, 2025

    @wing328
    Member

    I saw a couple of templates already using Java17, so it should be fine to add this to all.

    yes

    the project itself usually targets a lower version (even though already reached EOL) to keep more users happy

    for auto-generated java code, it's ok to default o jdk 17 to start with.

  4. TheMrMilchmann commented on Oct 14, 2025

    @TheMrMilchmann
    Contributor

    Note that there is also another problem with nullable properties that causes issues with Gradle 9. #22050 would solve this.

  5. added a commit that references this issue on Aug 9, 2026
    dc80646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions