Reputation: 43
I implement my custom code generation for https://github.com/OpenAPITools/openapi-generator
but i have no idea how to add this to gradle plugin. I need to add it to classpath while gradle perform openapi tasks
For maven i can easily add my custom implementation com.my.generator:customgenerator:1.0-SNAPSHOT in plugin dependency block,
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin-version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<templateDirectory>myTemplateDir</templateDirectory>
<apiPackage>${default.package}.handler</apiPackage>
<modelPackage>${default.package}.model</modelPackage>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.my.generator</groupId>
<artifactId>customgenerator</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
but in gradle i have no idea how to do it
Upvotes: 4
Views: 2361
Reputation: 248
The solution is simple if you know how Gradle plugins work. Here are steps how to do it:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.openapitools:openapi-generator:4.3.0"
classpath "some.custom.openapi:generator:0.0.1"
}
}
org.openapitools.codegen.CodegenConfig
with contentsome.custom.openapi.CustomJavaCodegen
(Here must be the name of the custom generator class) and place it to folder src/main/resources/META-INF/services/
.
getName
with your generator name, which you will use in the configuration of openApiGenerator in the Gradle file.I get this working with these steps. If I forget something to write it here, comment, and I will try to fill missing information.
Upvotes: 1