Gradle Swagger CodeGen DefaultGenerator CodegenConfigurator添加Lombok

问题描述 投票:0回答:1

我有个招摇和下面的build.gradle文件

buildscript {
    ext {
        springBootVersion = '2.1.8.RELEASE'
    }
    repositories {
        maven {
            url "https://mavenrepo.schwab.com/nexus/content/groups/public"
        }
        maven {
            url "https://mavenrepo.schwab.com/nexus/content/repositories/releases/"
        }
    }
    dependencies {
        classpath("io.swagger:swagger-codegen:2.4.7")
        classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7"
    }
}

apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

repositories {
    maven {
        url "https://mavenrepo.schwab.com/nexus/content/groups/public"
    }
}


import io.swagger.codegen.DefaultGenerator
import io.swagger.codegen.config.CodegenConfigurator

def swaggerInput = "${rootDir}/api/POMOrchestrator.v1.json"
def swaggerOutputDir = file('application/')


task generateApi {
    inputs.file(swaggerInput)
    outputs.dir(swaggerOutputDir)
    doLast {
        def config = new CodegenConfigurator()
        config.setInputSpec(swaggerInput)
        config.setOutputDir(swaggerOutputDir.path)
        config.setIgnoreFileOverride(swaggerOutputDir.path)
        config.setLang('spring')
        config.setAdditionalProperties([
                'invokerPackage': 'com.schwab.brokerage.party.onborading',
                'modelPackage'  : 'com.schwab.brokerage.party.onborading.models.swagger',
                'apiPackage'    : 'com.schwab.brokerage.party.onborading.api.inbound.rest.controller',
                'dateLibrary'   : 'java8',
                'useTags'       : 'true',  // Use tags for the naming
                'interfaceOnly' : 'true'   // Generating the Controller API interface and the models only

        ])
        config.setImportMappings([
                'hello': 'com.schwab.cat.onbording.model.Hello'
        ])
        new DefaultGenerator().opts(config.toClientOptInput()).generate()
    }
}

clean.doFirst {
    delete(swaggerOutputDir)
}

configurations {
    swagger
}

sourceSets {
    swagger {
        compileClasspath = configurations.swaggerCompile
        java {
            srcDir file("${project.buildDir.path}/swagger/src/main/java")
        }
    }
    main {
        compileClasspath += swagger.output
        runtimeClasspath += swagger.output
    }
    test {
        compileClasspath += swagger.output
        runtimeClasspath += swagger.output
    }
}

compileSwaggerJava.dependsOn generateApi
classes.dependsOn swaggerClasses
compileJava.dependsOn compileSwaggerJava

ext {
    springBootVersion = '2.1.8.RELEASE'

    swaggerVersion = '2.7.0'
    springCloudServicesVersion = '2.1.2.RELEASE'
    springCloudVersion = 'Greenwich.RC1'
    cucumberVersion = '2.3.1'

    jackson_version = '2.4.2'
    jersey_version = '1.18'
    jodatime_version = '2.3'
    junit_version = '4.8.1'
}

dependencies {
    swaggerCompile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
    swaggerCompile 'io.swagger:swagger-annotations:1.5.16'
    swaggerCompile 'com.squareup.okhttp:okhttp:2.7.5'
    swaggerCompile 'com.squareup.okhttp:logging-interceptor:2.7.5'
    swaggerCompile 'com.google.code.gson:gson:2.8.1'

    compile sourceSets.swagger.output

    compile "com.sun.jersey:jersey-client:$jersey_version"
    compile "com.sun.jersey.contribs:jersey-multipart:$jersey_version"
    compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
    compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
    compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
    compile "joda-time:joda-time:$jodatime_version"
    compile 'io.swagger:swagger-codegen:2.2.3'

    testCompile "junit:junit:$junit_version"

    runtime 'com.squareup.okhttp:okhttp:2.7.5'
    runtime 'com.squareup.okhttp:logging-interceptor:2.7.5'
    runtime 'com.google.code.gson:gson:2.8.1'
}

这在创建没有lombok批注的模型时做得很好,对于我来说,能够在顶部添加@Data和@Builder确实很有帮助。有没有办法告诉代码生成器添加这些(也许是设置)?

java gradle lombok swagger-codegen codegen
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.