'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.
Solution 1:[1]
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
Solution 2:[2]
If you know which variables you have in the dataframe in advance: use simple logic like ifelse() or dplyr::case_when() to choose between them.
If not: use functional programming. Under is an example:
library(dplyr)
f <- function(data, variable_col) {
data[[variable_col]] %>%
purrr::imap_dbl(~ data[[.y, .x]])
}
toy_data$value <- f(toy_data, "variable")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | jpiversen |
