I’m using the OpenAPI generator to auto-generate Java classes in SpringBoot from an OpenAPI specification. As build tool, I’m using Gradle.
I managed to create the classes which can be found in the path build/generate-resources/src/main/java
, but somehow, despite adding this path as source set in build.gradle
, my IDE (Intellij) still doesn’t recognize them and doesn’t suggest them to me when I start typing the names of the generated classes.
I checked other posts and articles such as here and here, but can’t spot the error in my code:
plugins {
id "java"
id "org.springframework.boot" version "3.2.4"
id "io.spring.dependency-management" version "1.1.4"
id "org.openapi.generator" version "7.5.0"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java {
sourceCompatibility = "17"
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter-web"
testImplementation "org.springframework.boot:spring-boot-starter-test"
}
openApiGenerate {
generatorName.set("java")
inputSpec = "$rootDir/specs/example-api.yaml"
outputDir = "$buildDir/generate-resources"
apiPackage = "com.example.demo"
modelPackage = "com.example.demo.model"
configOptions = [
library : "resttemplate",
openApiNullable: "false",
useJakartaEe : "true"
]
}
sourceSets {
main {
java {
srcDir("$buildDir/generate-resources/src/main/java")
}
}
}
tasks.compileJava {
dependsOn(tasks.openApiGenerate)
}
tasks.named("test") {
useJUnitPlatform()
}