How to disable OpenAPI2SpringBoot class generation in openApiGenerate

Viewed 1205

Following is my build.gradle configuration

plugins {
    id 'java'
    id 'maven-publish'
    id 'org.springframework.boot' version '2.3.9.RELEASE'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id "org.openapi.generator" version "5.1.0"
}

openApiGenerate {
 generatorName = "spring"
 inputSpec = "${project.rootDir}/spec/swagger.json".toString()
 outputDir = "${project.buildDir}/generate-sources".toString()
 invokerPackage = "com.base"
 apiPackage = "com.base.controllers"
 modelPackage = "com.base.models"
 generateModelTests = false
 generateApiTests = false
 configOptions = [
 dateLibrary: "java8"
 ]
 }
sourceSets {
 main {
 java {
 srcDir(files("${openApiGenerate.outputDir.get()}/src/main"))
   }
  }
 }
 compileJava.dependsOn tasks.openApiGenerate

As, it generates OpenAPI2SpringBoot class, due to that I am getting error

Execution failed for task ':bootJar'.
> Unable to find a single main class from the following candidates [com.base.OpenAPI2SpringBoot, com.base.Application]

How can I avoid generation of OpenAPI2SpringBoot class as I have my separate main class?

1 Answers

You have two options.

To disable OpenAPI2SpringBoot.java, you must specify interfaceOnly as true:

openApiGenerate {
    configOptions = [
        interfaceOnly: "true"
    ]
}

This may have unintended side effects, so the other option is to configure the main class as explained in the Spring Boot Gradle plugin docs:

tasks {
    bootJar {
        mainClassName = 'com.base.Application'
    }
}
Related