Filtering artifacts by capabilities/attributes

Hi! I hope my question is not too weird, I would like to create a Gradle plugin that is capable of finding Jar dependencies on a project that are built for it (my plugin) to handle.

I noticed that, in the Android build plugin, for example, they have a way to find android libraries’ resources dir by using artifactView and ArtifactView.ViewConfiguration to filter artifacts with a specific variant attribute, like the ones defined here: https://docs.gradle.org/current/userguide/variant_attributes.html

Something like this is what I’m looking for, I want to be able of creating a Java library, that can somehow get found by my custom plugin either by its attributes or by something else, maybe by declaring its capabilities: https://docs.gradle.org/current/userguide/component_capabilities.html But I’m not sure exactly how to “tag” a Java library of mine with something that makes it findable later by my plugin.

Thanks in advance,
Cesar.

You could do something similar to how springs @EnableAutoConfiguration annotation and SpringFactoriesLoader works by looking for META-INF/spring.factories in all the jars on the classpath

See ClassLoader.getResources(path)

Gradle does something similar for plugin ids. It looks for properties files under META-INF/gradle-plugins in all the jars on the buildscript classpath

Thank you for this! for a moment I thought of adding custom headers into the manifest but I wasn’t sure it was a good practice, although I didn’t think of adding my own properties file, I like that the better because I might need to add a lot of stuff there.

Thanks again,
Cesar.