Skip to content

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

@HenningWaack

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.

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