restdocs-api-spec icon indicating copy to clipboard operation
restdocs-api-spec copied to clipboard

Gradle Task Names Are Overloaded

Open romeara opened this issue 3 years ago • 4 comments

Currently, the extension and task names added for the various specs (openapi3, etc) use the same names. This prevents using simple configuration syntax to do things like setting the generation task to dependOn (or being depended on) by other tasks, as Gradle first finds the extension and attempts to do task operations on it, which results in an error.

Currently, I am working around this with syntax such as:

tasks.all { task ->
   if (task.name == 'openapi3') {
      task.dependsOn <other task>
   } 
} 

It would be helpful if the tasks were defined prior to the afterEvaluate step with unique names, following the pattern of other plug-ins, to allow better native interaction with them.

I recognize that changing the task name outright would represent a breaking change - I would propose creating the tasks with new unique names, but also creating empty tasks with the current names which "dependOn" the newly-named tasks as a potential way to address this prior to a major revision release, to avoid breaking anyone's existing use of the plug-in

romeara avatar Mar 10 '21 20:03 romeara

A little recap to make sure I understand the issue. In https://github.com/ePages-de/restdocs-api-spec/blob/master/restdocs-api-spec-gradle-plugin/src/main/kotlin/com/epages/restdocs/apispec/gradle/RestdocsApiSpecPlugin.kt :

  • We define 3 extensions with the names openapi, openapi3 and postman
  • We define 3 tasks with the names openapi, openapi3 and postman, but this happens too late for dependOn to be used at the "root scope" of a build.gradle file. E.g. inside a custom task definition it works for our internal projects (cropped):
tasks.register('publishEverything') {
    description = '...'

    dependsOn 'asciidoctor', 'openapi', 'postman'

    doLast { 
//...
}}

However, if I understand the reported issue correctly, this is not possible atm:

someTask.dependsOn(':openapi')

I'm not a gradle expert, but I'd be fine with a breaking change (finally 1.x?) if it results in more idiomatic gradle tasks.

ozscheyge avatar Mar 11 '21 20:03 ozscheyge

Yes, that about sums it up, though it's not just "when" for the tasks that causes the issue, but that they also share a name with the extensions.

You could do something like add generateOpenApi or similar as the task, and still define an openapi task which is empty but dependsOn generateOpenApi as a compatibility adapter to give people time to migrate before removing the old task names in a 1.x, if that route would be desirable

romeara avatar Mar 11 '21 21:03 romeara

Any progress on this?

I am using the generated openapi.json file to generate Swagger UI, but I cannot use the dependsOn because of this exact problem.

Arc-E-Tect avatar Jun 09 '22 21:06 Arc-E-Tect

Any progress on this?

No one is working on this issue, afaik.

ozscheyge avatar Jun 10 '22 07:06 ozscheyge