Can I define an artifact transform to run on only ...
# community-support
k
Can I define an artifact transform to run on only a single artifact? Here's what I've tried so far:
Copy code
val filtered = Attribute.of("filtered", Boolean::class.javaObjectType)
configurations.runtimeClasspath {
    // require artifacts be filtered
    attributes.attribute(filtered, true)
}
dependencies {
    attributesSchema {
        attribute(filtered)
    }
    // mark everything as "filtered true" by default, so the transformer doens't normally run
    artifactTypes.getByName("jar") {
        attributes.attribute(filtered, true)
    }
    registerTransform(FilterNativeLibraries::class) {
        from.attribute(filtered, false)
        to.attribute(filtered, true)
    }
    // ..other dependencies
    implementation("org.duckdb:duckdb_jdbc:1.0.0")
    components {
        // mark a single variable of a single module as "filtered false" so the transformer does run on it
        withModule("org.duckdb:duckdb_jdbc") {
            withVariant("runtime") {
                attributes.attribute(filtered, false)
            }
        }
    }
}
And that does seem to do what I want in terms of the
runtime
variant does appear to have the
filtered: false
attribute on it:
Copy code
Incompatible because this component declares a component, as well as attribute 'filtered' with value 'false' and the consumer needed a component, as well as attribute 'filtered' with value 'true'
So I would expect the transformer I defined to run on it, but it's not executing for some reason. I've also tried a different approach, where I define the attribute requirement only on a single configuration which
runtimeClasspath
depends on, but that doesn't seem to work either because transformation is only applied on configurations when they are resolved, and only the root configuration is actually resolved, so that requirement on the
filtered
configuration doesn't seem to do anything.
v
I have no idea, maybe the component metadata rule is effective after the transform would have run. 🤷‍♂️ If you don't get it right that way, another option would be to do the filtering in the transform. For each dependency you do not want to transform, you can simply define the input artifact as output artifact, then it is an identity transform without real overhead.
k
Yeah I suppose doing a noop transform would work. It seems like I'm doing all the right things in terms of what the Gradle docs say, so I wonder if this is actually a bug in gradle's artifact transform chain selection
--debug also doesn't say anything at all about variant selection or transform chain building
I concur with this comment from 2021 saying the docs do not make this behavior clear https://github.com/gradle/gradle/issues/8386#issuecomment-756707676