Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Gradle plugin: incremental build does not work if outputDir is not in $buildDir #11356

Open
2 of 6 tasks
alafanechere opened this issue Jan 19, 2022 · 3 comments
Open
2 of 6 tasks

Comments

@alafanechere
Copy link

alafanechere commented Jan 19, 2022

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When I use the GenerateTask and want to target an outputDir which path is not in the $buildDir the client I'm generating is generated on each build and I don't benefit from incremental builds (UP-TO-DATE flag on task).
I'm wondering if this is something related to Gradle our this plugin specifically and if there's an existing workaround.

If I use the $buildDir in the outputDir path the incremental build works, and my client get generated only upon spec updates.

openapi-generator version

5.3.1

Steps to reproduce

No incremental builds with the following build.gradle

import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
    id "org.openapi.generator" version "5.3.1"
    id 'airbyte-python'
    id 'airbyte-docker'
}

airbytePython {
    moduleDirectory 'octavia_cli'
}


task generateApiClient(type: GenerateTask) {
    inputSpec =  "$rootDir.absolutePath/airbyte-api/src/main/openapi/config.yaml"
    outputDir = "$projectDir/airbyte_api_client"

    generatorName = "python"
    packageName = "airbyte_api_client"
}

Works as expected when using $buildDir in the outputDir path:

import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

plugins {
    id "org.openapi.generator" version "5.3.1"
    id 'airbyte-python'
    id 'airbyte-docker'
}

airbytePython {
    moduleDirectory 'octavia_cli'
}

task generateApiClient(type: GenerateTask) {
inputSpec = "$rootDir.absolutePath/airbyte-api/src/main/openapi/config.yaml"
outputDir = "$buildDir/airbyte_api_client"

generatorName = "python"
packageName = "airbyte_api_client"

}

Related issues/PRs

@HenningWaack PR's #6716 introduced support for incremental build.

@nbrugger-tgm
Copy link

Hi I dug a bit deeper as i am experiencing the same issue but in my case it was my own fault.

To investigate the bug please run you gradle command with --info it will show you why the task is re-run.

If you get an output message such as "From property outputDir file "xyz" was removed" you can use the following code to find whats going wrong

Set<File> bev;
tasks.openApiGenerate.doFirst {
    println "Before : " + it.outputs.files.asFileTree.files.size()
    bev = it.outputs.files.asFileTree.files
}
tasks.openApiGenerate.doLast { it ->
    println "After : " + it.outputs.files.asFileTree.files.size()
    var newOut = new HashSet<>(it.outputs.files.asFileTree.files);
    newOut.removeAll(bev);
    println "Diff (ADDED) : " + newOut
    bev.removeAll(it.outputs.files.asFileTree.files)
    println "Diff (REMOVED) : " + bev
}

This just compares the diff between the output dir before and after the task

@gibbonsite
Copy link

gibbonsite commented Dec 15, 2024

Hi, I faced the same issue some time ago -- when I introduce dependency on the task GenerateTask, it consistently is marked as out of date, but no file has changed.

I digged into the problem.

I use version 6.6.0 of org.openapi.generator gradle plugin.
When I decompiled class GenerateTask.class in my IDE I noticed there wasn't annotation @OutputDirectory placed on outputDir field. But it's supposed to be there, see code.

I also checked similar case with inputSpec field -- there wasn't @InputFile annotation on this field in decompiled version of the class.

Why lack of @OutputDirectory is important? Without them, gradle always marks task as out of date.

Please, consider my findings above and fix the problem.

@HenningWaack
Copy link
Contributor

Hi, I could not reproduce the issue using the latest version of writing and using the sample project modules/openapi-generator-gradle-plugin/samples/local-spec. Please try again with latest version of generator and up-to-date version of Gradle and Java.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants