What are Variants and Attributes, and how can they be used?


(Mike Kobit) #1

I’ve seen “variant” come up quite a few times, and I’ve also tried to understand some of the documentation for “attributes” at https://docs.gradle.org/current/javadoc/org/gradle/api/attributes/package-summary.html , but I feel like I’m missing the “here is how you would use them as a plugin author” or some user documentation around them. I’m guessing the Android ecosystem makes use of them, but how could other plugins make use of them? There has always been the artifacts {} block, is this different?

I know is kind of fishing for information, but I didn’t think that it yet warranted creating an issue.


(Mike Kobit) #2

For example, I have a subproject that exports files in a few different ways

  • All the files
  • a subset of the files
  • a different subset of the files
  • a different zip for each of the above

I can do this today with:

artifacts {
  someFile(someFilesTask)
}

and then depend on it like

dependencies {
  runtimeOnly(project(path: ':data', configuration: 'someFile'))
}

This is kind of awkward to use, though. Do variants and attributes improve this?


(Mike Kobit) #3

The documentation at https://docs.gradle.org/current/userguide/artifact_management.html is scant of details.

Another use case I have right now is, "in a multiproject build, how can I use the files from one project when they are not assembled by any task? I just have some data files I would like to be able to reference as a dependency in another project, and it just seems way too complex.