Got a nasty little issue - we depend on javafaker,...
# dependency-management
r
Got a nasty little issue - we depend on javafaker, which in turn has this maven dependency:
Copy code
<dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>1.26</version>
            <classifier>android</classifier>
        </dependency>
Note the
<classifier>android</classifier>
- goodness knows why it's there, but it is 🤨. Unfortunately upgrading
jackson-dataformat-yaml
, whether transitively or otherwise, brings in
org.yaml:snakeyaml:1.30
- and it seems that gradle (7.4.2) resolves that by creating a dependency on
snakeyaml-1.30-android.jar
- which doesn't exist. I can fix it as so:
implementation('com.github.javafaker:javafaker:1.0.2')  { exclude group: 'org.yaml' }
but ideally I'd just quietly drop the
android
classifier, rather than excluding the entire dependency, so that it would work if my other dependencies stop bringing in
snakeyaml
.
g
You can also look how this @Jendrik Johannes's plugin fixes similar thing with guava https://github.com/jjohannes/missing-metadata-guava
1
r
Thanks both, that's great
j
I had a similar issue with
guice-noap
referenced by
typesafeconfig-guice
. This is the rule that fixes the metadata of
typesafeconfig-guice
and you could do smth similar for
javafaker
:
Copy code
/**
 * Removes the 'no_aop' classifier from the Guice dependency, because it
 * no longer exists with Guice 5.0 to which we upgrade the dependency.
 */
@CacheableRule
abstract class TypesafeConfigGuiceRule : ComponentMetadataRule {
    companion object {
        const val TYPESAFE_CONFIG_GUICE_MODULE = "com.github.racc:typesafeconfig-guice"
    }

    override fun execute(context: ComponentMetadataContext) {
        context.details.allVariants {
            withDependencies {
                removeIf { it.group == "com.google.inject" }
                add("com.google.inject:guice")
            }
        }
    }
}
🙏 1
Copy code
// register rule:
dependencies.components {
    withModule<TypesafeConfigGuiceRule>(TypesafeConfigGuiceRule.TYPESAFE_CONFIG_GUICE_MODULE)
}
🙏 1
n
we solved it by substituting any request for the android variant with the “normal” one:
Copy code
// javafaker requests the android variant of snakeyaml, which might not always exist
configurations {
  configureEach {
    resolutionStrategy {
      eachDependency {
        if (requested.name == "snakeyaml") {
          artifactSelection {
            selectArtifact("jar", "jar", null)
          }
        }
      }
    }
  }
}
👍 4
j
☝️ That’s also a neat and compact solution for this. I might like it more than mine. 😄 Thanks for sharing @Niels Doucet