Gradle is a general purpose build tool. You can use it for any languages not just those that runs on the JVM. Its core model is based on tasks. The build essentially configures a set of tasks that gets wired together based on their dependencies. However, this does not mean that there is a lot of work to do. In Gradle, it is easy to build common types of project as common conventions and functionality are provided through plugins.
Add Spring Dependencies And Plugins
When applying the java plugin together with the org.springframework.boot plugin, a task for building an executable jar is automatically configured.
To manage dependencies in our Spring Boot project, we will apply the io.spring.dependency-management plugin, this allows us to control the versions of the dependencies it manages just by changing the properties.
Then, we add spring boot starter dependencies. Notice that we do so without including the version number. This means that we will use the same version of the dependency management plugin as Spring Boot uses.
Add OpenAPI Generator Plugin And Dependencies
The OpenAPI Generator Plugin will configure a openApiGenerate task which will generate spring controllers and model classes from an Open API specification written in json or yaml.
We can then configure the openApiGenerate task. You can read more details about the available options here.
Add Generated Source Files To Source Sets
Gradle will now recognize the generated output and package them together during build.
Generate Controller And Model Classes During Build
We add the following code which tells gradle that compileJava task depends on openApiGenerate task. Our source files will be generated during build time.
Example Usage
We can then extend the interface and implement our controller methods.