# Incremental build support for a task

**URL:** <https://discuss.gradle.org/t/incremental-build-support-for-a-task/37425>\
**Category:** Help/Discuss\
**Created:** [August 28, 2020, 1:27pm UTC](https://discuss.gradle.org/t/incremental-build-support-for-a-task/37425 "2020-08-28T13:27:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xendar](https://avatars.discourse-cdn.com/v4/letter/x/94ad74/32.png) [@Xendar](https://discuss.gradle.org/u/Xendar)\
**Post date:** [August 28, 2020, 1:27pm UTC](https://discuss.gradle.org/t/incremental-build-support-for-a-task/37425/1 "2020-08-28T13:27:28Z")

</div>

I am using some task ([Swagger codegen Gradle plugin](https://github.com/int128/gradle-swagger-generator-plugin) & [OpenAPI Style Validator](https://github.com/OpenAPITools/openapi-style-validator)) in my Gradle build that do not support it seems the incremental build feature.

Googling a bit (and checking the Gradle doc) I understood that it seems possible to extend the tasks in order to add some properties, so I gave it a try, but unfortunately it does not seem to work.  
Here’s the `build.gradle` extension I added:

```gradle
swaggerSources {
    jaxrsServer {
        inputFile = file('path/to/spec.yaml')
        code {
            language = 'jaxrs'
            library = 'jersey2'
            outputDir = file('build/generated/sources/swagger')
            templateDir = file('path/to/templates')
        }
    }
    jaxrsClient {
        inputFile = file('path/to/spec.yaml')
        code {
            language = 'java'
            library = 'jersey2'
            outputDir = file('build/generated/sources/swagger')
        }
    }
}

tasks.withType(GenerateSwaggerCode) {
    inputs.file('path/to/spec.yaml')
    outputs.dir('build/generated/sources/swagger')
}

[...]

openAPIStyleValidator {
    inputFile = "$projectDir/path/to/spec.yaml"
    validateInfoLicense = false
}

tasks.withType(org.openapitools.openapistylevalidator.gradle.OpenAPIStyleValidatorTask) {
    inputs.file("$projectDir/path/to/spec.yaml")
}

```

And the (truncated) build output:

```gradle
> Task :module:openAPIStyleValidator
Validating spec: /.../path/to/spec.yaml
[...]
> Task :module:resolveSwaggerTemplate NO-SOURCE
> Task :module:generateSwaggerCodeJaxrsClient
> Task :module:generateSwaggerCodeJaxrsServer
> Task :module:generateSwaggerCode NO-SOURCE
> Task :module:compileJava

```

Is the task extension wrong? Is there any other way to achieve this?

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [August 28, 2020, 2:25pm UTC](https://discuss.gradle.org/t/incremental-build-support-for-a-task/37425/2 "2020-08-28T14:25:34Z")

</div>

> [@Xendar](#):
>
> I am using some task ([Swagger codegen Gradle plugin](https://github.com/int128/gradle-swagger-generator-plugin) & [OpenAPI Style Validator](https://github.com/OpenAPITools/openapi-style-validator)) in my Gradle build that do not support it seems the incremental build feature.

This Swagger plugin does support incremental builds without your additions to `GenerateSwaggerCode`.

However, you will likely have problems with the configuration in your example given that the destination is the same for both `generateSwaggerCodeJaxrsClient` and `generateSwaggerCodeJaxrsServer` task. This is generally not preferred, but even worse in this case because there’s logic in the plugin to delete the `outputDir` by default if the task runs.

Therefore, `generateSwaggerCodeJaxrsClient` deletes the directory and executes, then `generateSwaggerCodeJaxrsServer` deletes the directory and executes. You should be able to remove

```groovy
tasks.withType(GenerateSwaggerCode) {
    inputs.file('path/to/spec.yaml')
    outputs.dir('build/generated/sources/swagger')
}

```

and run just one task at a time ( `generateSwaggerCodeJaxrsClient` or `generateSwaggerCodeJaxrsServer`) to see the incremental behavior. You’ll need to change your actual configuration to use this for real though.

---

<div class="post-metadata">

**Author:** ![Xendar](https://avatars.discourse-cdn.com/v4/letter/x/94ad74/32.png) [@Xendar](https://discuss.gradle.org/u/Xendar)\
**Post date:** [August 28, 2020, 2:41pm UTC](https://discuss.gradle.org/t/incremental-build-support-for-a-task/37425/3 "2020-08-28T14:41:53Z")

</div>

Oh gosh, it seems obvious now!  
I had to do this kind of setup with Maven initially, and didn’t really change that as I’m migrating to Open API Generator.  
I’ll adapt this way!
