4

Android build.gradle directives often have parts like

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        // do something to output
    }
}

The variant.outputs is puzzling. It seems to work, but the outputs property is neither visible in the code nor in the plugin user guide or the gradle index.

How do I know the properties in applicationVariants of android gradle plugin? asks about ApplicationVariant in general, but neither the question's nor the answer's links seems to contain the outputs property.

Where is outputs specified/described?

Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188
  • 1
    Did you check the Groovy documentation? – OneCricketeer Jul 22 '16 at 13:08
  • @cricket_007: good idea. I looked in gradle's https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskOutputs.html, https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSetOutput.html, https://docs.gradle.org/current/userguide/logging.html, but not at Groovy. Google for `groovy outputs` did not yield pointers, though. Any further ideas? – serv-inc Jul 22 '16 at 13:12
  • @cricket_007: [The index](http://docs.groovy-lang.org/latest/html/api/index-all.html#_O_) did not seem to contain `outputs`. (there are several `out` and 1 `output`, though) – serv-inc Jul 22 '16 at 13:14
  • 1
    I don't actually know Groovy, I just know that's the language used for Gradle. I see that ApplicationVariants is an interface that doesn't extend anything, so I'm not sure what outputs is either – OneCricketeer Jul 22 '16 at 13:16
  • @cricket_007: It makes a lot of sense to look at Groovy. – serv-inc Jul 22 '16 at 13:19
  • 1
    I think `applicationVariants.all` is a function thing to a closure with a `variant` variable and **that** is what has `outputs` – OneCricketeer Jul 22 '16 at 13:34
  • @cricket_007: applicationVariants has an `all` method which applies a Closure, see https://docs.gradle.org/current/javadoc/org/gradle/api/DomainObjectCollection.html. (seems pretty much like `map` in python, etc.) If so, `variant` is the variable name, which should be of type `ApplicationVariant`). – serv-inc Jul 22 '16 at 15:49
  • 2
    Seems to be what you are looking for. http://stackoverflow.com/a/25999264/2308683 – OneCricketeer Jul 22 '16 at 17:03
  • 1
    Example 18.10... https://docs.gradle.org/current/userguide/working_with_files.html – OneCricketeer Jul 22 '16 at 17:06
  • 1
    The method. [`Task.getOutputs()`](https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html#getOutputs()) – OneCricketeer Jul 22 '16 at 17:13
  • @cricket_007: thank you. That kind of solves it (even though it is still unclear why it is a `Task` (see https://docs.gradle.org/current/dsl/org.gradle.api.Task.html and https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html). Post an answer if you would like the upvote and accept. – serv-inc Jul 22 '16 at 17:17

1 Answers1

3

It should be BaseVariant.getOutputs() and implement at BaseVariantImpl.

The code you check is probably at a very old version that outputs has not be added.

Vigi Droid
  • 66
  • 5