Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force version of dependency in gradle plugin

Is it possible to force gradle to use a different dependency in a plugin?

I want to run the openapi-generator 5.1.1 plugin, but I want it to use swagger-parser 2.0.26. The reason for this is the issue mentioned below. In that issue, the user "selliera" mentions he was able to run the plugin with that dependency (ok, he mentions 2.0.20, but the unreleased fix uses 2.0.26).

https://github.com/OpenAPITools/openapi-generator/issues/8266

I have tried using a strict version:

dependencies {
    implementation("io.swagger.parser.v3:swagger-parser") {
        version {
            strictly "2.0.26"
        }
    }
}

And using

configurations.all {
    resolutionStrategy {
        eachDependency { DependencyResolveDetails details ->
            if (details.requested.group == 'io.swagger.parser.v3' && details.requested.name =='swagger-parser') {
                details.useVersion("2.0.26")
            }
        }
    }
}

But neither seems to have any effect.

Here's a simple gradle script to demonstrate the issue. If you place the contents of the petstore spec in the petstore.yml file specified in the script below and run openApiGenerate, it works fine. If you change the url in the petstore spec to a relative one (like in the linked issue), the generator fails. Using the new version of swagger-parser is supposed to fix this.

plugins {
    id 'java'
    id 'org.openapi.generator' version '5.1.1'
}

repositories {
    mavenCentral()
}

openApiGenerate {
    generatorName = 'spring'
    inputSpec = "$rootDir/src/main/resources/petstore.yml"
}
like image 650
Rick Avatar asked Oct 19 '25 14:10

Rick


1 Answers

Works for me (gradle 5.6.4):

  • To force a dependency version of a plugin, add this to the top of your build.gradle script (before the plugins {} block):
buildscript {
    configurations.all {
        resolutionStrategy {
            force 'io.swagger.parser.v3:swagger-parser:2.0.26'
        }
    }
}
  • Just for clarification, if you add a similar configuration outside of the buildscript {} block, it will force a dependency version of your application instead:
configurations.all {
    resolutionStrategy {
        force 'io.swagger.parser.v3:swagger-parser:2.0.26'
    }
}

PS: By now swagger-parser 2.0.26 is a default for openapi-generator 5.4.0

PPS: I know, it's an old question, but still top in Google

like image 122
Blackor Avatar answered Oct 22 '25 04:10

Blackor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!