Created
July 4, 2017 11:17
-
-
Save steam0/4fa11ad0660d33192ec01cd84050f226 to your computer and use it in GitHub Desktop.
Gradle plugin workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Swagger (https://www.jcore.com/2017/05/22/automatically-generating-api-using-swagger-and-gradle/)*/ | |
import io.swagger.codegen.config.CodegenConfigurator | |
import io.swagger.codegen.DefaultGenerator | |
def swaggerTargetFolder = 'build/generated-sources' | |
def generateFilesFromSwagger(swaggerSourceFile, packageName, swaggerTargetFolder) { | |
def config = new CodegenConfigurator() | |
config.setInputSpec("$swaggerSourceFile") | |
config.setOutputDir("$projectDir") | |
config.setLang('spring') | |
config.setAdditionalProperties([ | |
'interfaceOnly' : 'true', | |
'apiPackage' : packageName, | |
'modelPackage' : packageName, | |
'sourceFolder' : swaggerTargetFolder, | |
'dateLibrary' : 'java8' | |
]) | |
new DefaultGenerator().opts(config.toClientOptInput()).generate() | |
} | |
task swagger2java { | |
doLast { | |
// Order | |
generateFilesFromSwagger("file:///$projectDir/src/main/resources/swagger-spec/order.json", 'org.entur.order', swaggerTargetFolder) | |
// Payment | |
generateFilesFromSwagger("file:///$projectDir/src/main/resources/swagger-spec/payment.json", 'org.entur.payment', swaggerTargetFolder) | |
// Offers | |
// generateFilesFromSwagger("file:///$projectDir/src/main/resources/swagger-spec/offers.json", 'org.entur.offers', swaggerTargetFolder) | |
} | |
} | |
// Supporting gradle clean | |
clean.doFirst { | |
delete("${projectDir}/$swaggerTargetFolder") | |
} | |
swagger2java.dependsOn wsdl2java // NB! wsdl2java cleans generated sources directory, must happen before swagger gen | |
compileJava.dependsOn swagger2java |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for posting this configuration, it is what I wanted to achieve. However, it is creating he following error when I run Gradle build:
What I am missing here and why it doesn't recognize 'clean' ?