I know that you can just create a separate .gradle file and add it to the build.gradle with apply from:
But I now have a task based on the openapi-generator which needs an import:
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask;
tasks.register('openApiGenerateJavaServer', GenerateTask) {
generatorName = 'spring'
}
If I have this task in the build.gradle
of my project it works, but when I try to apply it from a different file I get an error:
unable to resolve class
org.openapitools.generator.gradle.plugin.tasks.GenerateTask @ line 1, column 1. import org.openapitools.generator.gradle.plugin.tasks.GenerateTask;
I can't use the default openApiGenerate
task as I need multiple generators in this project (server, client and angular-ts)
Is there a solution for this?
I know that you can just create a separate .gradle file and add it to the build.gradle with apply from:
But I now have a task based on the openapi-generator which needs an import:
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask;
tasks.register('openApiGenerateJavaServer', GenerateTask) {
generatorName = 'spring'
}
If I have this task in the build.gradle
of my project it works, but when I try to apply it from a different file I get an error:
unable to resolve class
org.openapitools.generator.gradle.plugin.tasks.GenerateTask @ line 1, column 1. import org.openapitools.generator.gradle.plugin.tasks.GenerateTask;
I can't use the default openApiGenerate
task as I need multiple generators in this project (server, client and angular-ts)
Is there a solution for this?
Share Improve this question asked Feb 5 at 9:02 ThomasThomas 7,0905 gold badges36 silver badges75 bronze badges1 Answer
Reset to default 1You can write a precompiled script plugin instead of using a standalone .gradle
file. Then, as this file is itself compiled, it can have a compilation classpath and pick up the dependency you need.
Most straightforwardly this compilation is carried out in the buildSrc
project. To do this you can:
Write a build file for your new compilation at
buildSrc/build.gradle
:plugins { id 'groovy' } repositories { gradlePluginPortal() // To find the dependency } dependencies { // Here we add the OpenAPI generator plugin as a dependency implementation 'org.openapi.generator:org.openapi.generator.gradle.plugin:7.11.0' }
Write your precompiled script plugin at (say)
buildSrc/src/main/groovy/myPlugin.groovy
. This is your existing.gradle
file that requires the external dependency.Then apply your new plugin using the
plugins
block in your main project'sbuild.gradle
fileplugins { id 'myPlugin' }
Remove the version number from where you apply the OpenAPI generator plugin in your main build file(s). This is because the OpenAPI generator plugin JAR was put on the classpath of the main build in step 1 and Gradle has checks to avoid different versions of the same code being placed on the build classpath.