Hi,
I have noticed that Gradle’s compileClasspath
configuration does not resolve as other configurations do. In my case, I had added some project
dependencies to the compileOnly
configuration and observed that compileClasspath
only contained the projects’ “API elements”. Which was fine, of course. However, when I added the exact same project
dependencies (and nothing else) to a configuration I had created myself, Gradle resolved all of their “runtime elements” instead.
After digging into the JavaPlugin
code, I discovered that I could add the following attributes to my configuration:
attribute(CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, LIBRARY))
attribute(USAGE_ATTRIBUTE, project.getObjects().named(Usage.class, JAVA_API))
which performed the Gradle Magic that I needed.
The Category
and Usage
classes don’t appear to be “internal” to Gradle, but is this really the cleanest way to create a configuration that resolves like compileClasspath
please? I had never even heard of these classes before now, and feel like I’ve crossed some kind of threshold and entered “Dragon Territory”.
What have I done? Should I retreat, and if so, to where?
Thanks for any advice here,
Cheers,
Chris