Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.thebignet:swagger-codegen-gradle-plugin:1.7.4'
}
dependencies {
implementation("com.github.thebignet:swagger-codegen-gradle-plugin:1.7.4")
}
<dependency>
<groupId>com.github.thebignet</groupId>
<artifactId>swagger-codegen-gradle-plugin</artifactId>
<version>1.7.4</version>
</dependency>
libraryDependencies += "com.github.thebignet" % "swagger-codegen-gradle-plugin" % "1.7.4"
:dependencies [[com.github.thebignet/swagger-codegen-gradle-plugin "1.7.4"]]
A Gradle plugin to support the swagger code generation project
see the swagger-codegen-gradle-plugin-example for creating a Gradle task to generate code with Swagger Codegen.
see the swagger-codegen-gradle-plugin-example, or:
Here is an example of how to use the plugin in a build.gradle
file
plugins {
id 'org.detoeuf.swagger-codegen' version '1.7.4'
id 'java'
}
apply plugin: 'org.detoeuf.swagger-codegen'
repositories {
mavenCentral()
jcenter()
}
swagger {
inputSpec = 'http://petstore.swagger.io/v2/swagger.json'
outputDir = file('build/swagger')
lang = 'java'
additionalProperties = [
'invokerPackage' : 'io.swagger.petstore.client',
'modelPackage' : 'io.swagger.petstore.client.model',
'apiPackage' : 'io.swagger.petstore.client.api',
'dateLibrary' : 'java8'
]
importMappings = [
'Dog': 'io.swagger.petstore.client.model.Dog'
]
}
sourceSets {
swagger {
java {
srcDir file("${project.buildDir.path}/swagger/src/main/java")
}
}
}
classes.dependsOn('swagger')
ext {
spring_boot_version = '1.5.6.RELEASE'
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:$spring_boot_version"
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'
}
Launch with:
gradle swagger
the swagger {}
configuration is passed to CodegenConfigurator.java
Some Swagger codegen configurations will contain extra properties that are not part of the io.swagger.codegen.CodegenConfig interface. For example there is the sourceFolder
property that is only applicable if using jaxrs-spec as the value of the lang
property. In order to set such properties, we should use the dynamicProperty
method inside the swagger {}
configuration as shown below.
swagger {
lang = 'jaxrs-spec'
addDynamicProperty 'sourceFolder', 'src/swagger/java'
additionalProperties = [
...
]
systemProperties = [
...
]
}
… to be documented …
the old behaviour had a custom plugin for this swagger config as seen below
inputSpec
- :check:outputDir
- was: output
lang
- was: language
additionalProperties
- sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. See Customizing the generator for list of parameterssystemProperties
- see selective generationmodels
- have a look at the systemProperties sectionapis
- selective generation of apis. Leave blank to generate apis onlysupportingFiles
- selective generation of supporting files. Leave blank to generate supporting files onlyno substituion for:
cleanOutputDir
- now, configured by configuring the task directly:
tasks.getByName("swagger") {
cleanOutputDir = false
}