使用kotlin dsl在gradle构建脚本中配置swagger

时间:2017-12-21 12:30:05

标签: gradle groovy swagger gradle-kotlin-dsl

我试图在构建脚本中将我的简单项目从Groovy切换到Kotlin。 我正在使用这个插件: https://github.com/gigaSproule/swagger-gradle-plugin 我在构建脚本中有这个配置:

swagger{
  apiSource {
    springmvc = false
    locations = ['my.location']
    schemes = ['https']
    host = 'test.com:8080'
    info {
      title = 'My Service'
      version = 'v1'
    }
    swaggerDirectory = "$buildDir/swagger"
  }

在这种情况下,我应该在哪里提到? 我要做点什么吗?

    task( "swagger" ) {
      ...
    }

对我来说不太熟悉。 感谢。

1 个答案:

答案 0 :(得分:2)

如果有人仍在寻找此信息,您可以使用Gradle Kotlin DSL进行此操作:

import com.benjaminsproule.swagger.gradleplugin.model.*

plugins {
    id("com.benjaminsproule.swagger") version "1.0.0"
}

swagger {
    apiSource(closureOf<ApiSourceExtension> {
        springmvc = false
        schemes = mutableListOf("https")
        host = "test.com:8080"

        info(closureOf<InfoExtension> {
            title = "My Service"
            version = "v1"
            description = "My Service Description"
            termsOfService = "http://www.example.com/termsOfService"
            contact(closureOf<ContactExtension> {
                email = "email@internet.com"
                name = "A Developer"
                url = "http://www.internet.com"
            })
            license(closureOf<LicenseExtension> {
                url = "http://www.apache.org/licenses/LICENSE-2.0.html"
                name = "Apache 2.0"
            })
        })

        locations = mutableListOf("com.foo.fighting")
        swaggerDirectory = "$buildDir/swagger"
    })
}

我使用Gradle v4.6测试了它。