Universally define a classifier in gradle for a jar

We’re using gradle 6.3. We’ve had a long standing issue with using jar files that are available via a classifier. These jar files include a JNI shared library and some supporting shared libraries that are extracted during runtime to run. The shared libraries work on either macOS and Linux. One has the mac classifier and another has a linux specifier. We actually have about 6 of these kinds of jars that provide a JNI interface.

While this wasn’t a big issue when we used Maven a long time ago, it remains a struggle to maintain in the gradle world. I’ve heard that gradle can use build variants, but I’m really struggling to see how it works. So far, it seems like we have to explicitly define the classifier with the version.

I’ve summarized the current state of things below.

project.extra.set(“constraintsMap”, mapOf(
“com.company.product:jni-code” to “1.1”,
“com.ibm.icu:icu4j” to “67.1”

String osName = System.getProperty(“os.name”).toLowerCase();
ext.isMacOs = osName.startsWith(“mac”)
ext.isLinux = !isMacOs
if (isMacOs) {
ext.nativelibclassifier = ‘mac’
else {
ext.nativelibclassifier = ‘linux’
dependencies {
implementation project(’:com.company.product:backend’)
implementation group: ‘com.ibm.icu’, name: ‘icu4j’
implementation group: ‘com.company.product’, name: ‘jni-code’, version: rootProject.componentsMap[‘com.company.product’], classifier: nativelibclassifier

Is there a way to avoid requiring all of the code that depends on this module to basically copy that last dependency and explicitly define the version. The classifier doesn’t seem to be transitive, and we have a lot of modules (hundreds), and we don’t want to copy this same line. We just want to configure the version and classifier in one location. When we run “gradle test”, ideally we would like the right classifier to be determined at runtime, but hard coding the dependency at build time is also acceptable.

How can we configure all of the modules to use the same version and classifier for a dependency and have the dependency to be transitive?