Howto handle clash of tasks for two gradle plugins?
Asked Answered
B

1

6

I use gradle with the two plugins com.jfrog.artifactory and io.swagger.core.v3.swagger-gradle-plugin .

Now I want to configure as described here https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-gradle-plugin the generation of code. But it seems that the resolve task has already been defined from artifactory. How do I adress the method of swagger-plugin directly?

This is in my build.gradle:

resolve {
   outputFileName = 'bananas'
   outputFileName = 'PetStoreAPI'
   outputFormat = 'JSON'
   prettyPrint = 'TRUE'
   classpath = sourceSets.main.runtimeClasspath
   resourcePackages = ['io.test']
   outputDir = file('test')
}

and this is the error message: Could not set unknown property 'outputFileName' for object of type org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig.

Broadway answered 26/6, 2020 at 5:47 Comment(0)
J
9

There is indeed a clash between Artifactory resolve extension and Swagger plugin resolve tasks (of type import io.swagger.v3.plugins.gradle.tasks.ResolveTask)

One way to solve this is to reference the swagger tasks explicitly using fully-qualified name, as follows:

io.swagger.v3.plugins.gradle.tasks.ResolveTask swaggerResolve = tasks.getByName("resolve")
swaggerResolve.configure {
    outputFileName = 'PetStoreAPI'
    outputFormat = 'JSON'
    prettyPrint = 'TRUE'
    classpath = sourceSets.main.runtimeClasspath
    resourcePackages = ['io.test']
    outputDir = file('test')
}

EDIT Simpler solution , see Lukas's comment

tasks.resolve { 
   outputFileName = 'PetStoreAPI'
   // ....
}
Jamarjamb answered 26/6, 2020 at 7:20 Comment(2)
The (kinda ugly) import is not necessary. You can just use tasks.resolve { } to configure the task and resolve { } to configure the extension.Tooley
@LukasKörfer you're right, with Groovy DSL you can use this "shorcut" . With Kotlin DSL you would still need to reference ResolveTask using its fully-qualified name (or let me know if we can avoid this, I'm interested ;) ). I'll update my answer with your comment, tks.Jamarjamb

© 2022 - 2024 — McMap. All rights reserved.