I have a dependency that is using ‘enforcedPlatfor...
# community-support
s
I have a dependency that is using ‘enforcedPlatform’. It is downgrading some of my dependencies. Can I make the dependency follow ‘platform’ instead of ‘enforcedplatform’ of its BOM
v
I'd say report a bug. You can probably use a component metadata rule, or if all goes wrong a resolution strategy to enforce what you want. But imho a library that is using
enforcedPlatform
is buggy.
enforcedPlatform
should not be used in most cases but is only a biiig-hammer last solution and should never be used in anything published. You even have to enforce that Gradle publishes such a metadata as it fails if you try to by default.
👍 1
💯 1
n
yeah, there's a big warning in the docs about it: see right above this section https://docs.gradle.org/current/userguide/platforms.html#sub:platforms-vs-catalog
v
I gave it a quick show, you can indeed use a dependency metadata rule to fix this up. For example like this:
Copy code
dependencies {
    components {
        withModule("misbehaving:dependency") {
            allVariants {
                withDependencies {
                    forEach {
                        if ((it.group == "group-of-platform") && (it.name == "name-of-platform")) {
                            it.version {
                                require(requiredVersion)
                            }
                            it.attributes {
                                attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.REGULAR_PLATFORM))
                            }
                        }
                    }
                }
            }
        }
    }
}
This downgrades the strict version for the platform to a required version (for example if version alignment is used properly like for log4j, and downgrades the platform content from enforced to regular platform.
👀 1