주요 아이디어는 buildScript에서, Gradle을이 같은 것을 사용할 수 있도록하기위한 클래스 패스에 자신감-받는다는 - 플러그인과 자바 클래스를 추가하는 것입니다
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath files(project(':swagger-maven-example').configurations['runtime'].files)
classpath files(project(':swagger-maven-example').sourceSets['main'].output.classesDir)
}
}
을 어디에서 첫 번째 줄 종속성은 하위 프로젝트에서 swagger libs를 가져오고 두 번째 줄은 스와거 주석을 포함해야하는 클래스를 가져옵니다.
이 후에는 간단한 자바 클래스로 Gradle을에 받는다는 플러그인을 호출 할 수 있습니다
// a trick to have all needed classes in the classpath
def customClass = new GroovyClassLoader()
buildscript.configurations.classpath.each {
// println it.toURI().toURL()
customClass.addURL(it.toURI().toURL())
}
final ApiDocumentMojo mavenTask = Class.forName('com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo',true, customClass).newInstance(
apiSources: [
new ApiSource(
springmvc: false,
locations: ['com/github/kongchen/swagger/sample/wordnik/resource'],
schemes: ['http', 'https'],
host: 'petstore.swagger.wordnik.com',
basePath: '/api',
info: new Info(
title: 'Swagger Maven Plugin Sample',
version: 'v1',
description: 'This is a sample for swagger-maven-plugin',
termsOfService: 'http://www.github.com/kongchen/swagger-maven-plugin',
contact: new Contact(
email: '[email protected]',
name: 'Kong Chen',
url: 'http://kongch.com'
),
license: new License(
url: 'http://www.apache.org/licenses/LICENSE-2.0.html',
name: 'Apache 2.0'
)
),
outputPath: file("${buildDir}/swagger/document.html").path,
swaggerDirectory: file("${buildDir}/swagger/swagger-ui").path,
templatePath: file("${project(':swagger-maven-example').projectDir}/templates/strapdown.html.hbs")
)
]
)
// maven plugin
mavenTask.execute()
Here이 예를 찾을 수 있습니다.
아직 조사 중입니다. – tbsalling
https://github.com/gigaSproule/swagger-gradle-plugin 이 플러그인을 사용해 보셨습니까? 그것은 당신이 요구하는 것을 정확하게 수행한다고 주장합니다. –
swagger-gradle-plugin 사용시 다음 오류가 발생합니다. com.fasterxml.jackson.databind.JsonMappingException : [소스 : 알 수 없음]에서 입력의 끝으로 인해 매핑 할 내용이 없습니다. 줄 : 1, 열 : 0] – lex