如何在 openApiGenerate 中禁用 OpenAPI2SpringBoot class 生成

How to disable OpenAPI2SpringBoot class generation in openApiGenerate

以下是我的build.gradle配置

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

因为,它生成 OpenAPI2SpringBoot class,因此我收到错误

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

如何避免生成 OpenAPI2SpringBoot class,因为我有单独的 main class?

你有两个选择。

要禁用 OpenAPI2SpringBoot.java,您必须将 interfaceOnly 指定为 true:

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

这可能会产生意想不到的副作用,因此另一种选择是按照 Spring Boot Gradle plugin docs:

中的说明配置主 class
tasks {
    bootJar {
        mainClassName = 'com.base.Application'
    }
}