Question: I need to know what language is used on a iOS/Android device because I build a MonoGame application in Xamarin Studio that supports three different languages. If the current language of the device is english, than the app will show texts in english, but if the current language of the device is french, than the texts will get displayed in french instead of english. If the current language of the device is not supported in my application(for example chinese), than the default language for the texts will be english.

How can I get the current device language on iOS/Android in Xamarin Studio?

Answer: 
I ran into the same problem, which appears to still be a limitation of `maven-publish`. I found a workaround that works pretty well for me:

```
publishing {
  repositories {
    def repositoryName = 'X'
    maven { name = repositoryName /* ... */ }

    afterEvaluate {
      def targetComponent = System.getProperty("targetComponent")
      components.each { component ->
        if (component.name != targetComponent) return

        def appendage = component.name.replaceAll("[Rr]elease", "")
        if (!appendage.isEmpty()) appendage = "-$appendage"

        publications {
          "${component.name}"(MavenPublication) {
            from component
            artifactId = project.name + appendage
          }
        }

        publish.doFirst {
          if (targetComponent == null)
            throw new GradleException("Deployment requires specifying -DtargetComponent option")
        }
      }
    }
  }
}

```

Invoke with `gradle project:publish -DtargetComponent=release`, or whatever other component you're trying to release.

*Explanation:* Gradle sees intra-workspace dependencies at the `project` level, but it outputs to Maven repos at the `component` level. Maven doesn't have this same project vs. component concept. This also means you can't specify, in a Gradle `dependencies` block, which component of a Maven-style dependency you are looking for (since Maven doesn't really get that concept). The result: Gradle can't figure out how to write the POM file entry for an intra-workspace dependency with multiple `publication`s.

Minimal problem example:

```
// a/build.gradle:
publications {
  release(MavenPublication) { from components.release }
  debug(MavenPublication) { from components.debug; artifactId = 'a-debug' }
}

// b/build.gradle:
dependencies {
  project(':a') // ERROR: should this be 'group:b:1.0.0' or 'group:b-debug:1.0.0'?
}

```

The workaround works by having you indicate which component you want to deploy, across all projects, before configuration time. During configuration, Gradle only generates one publication per project, based on the component you flagged, adding the extra information Gradle needs to map intraproject deps to Maven-style deps. You only need to specify the command line argument when you want to deploy; the conditional is bound to the `publish` task, so it only goes off if that task is actually invoked.

*Limitations:*

* Assumes that component information should be preserved in the Maven `artifactId`; you could change this if you wanted to
* If you don't specify the property, `gradle publish --dry-run` doesn't show meaningful results
* Gradle can only publish one component in each invocation
* Every project in your workspace has to expose similarly-named components (you could tailor this code to fix that, though), and they all bind within that selection (i.e. `a:release` binds to `b:release` and `a:debug` binds to `b:debug`)

*EDIT:* I had called my task `deploy` but renamed it to `publish` when writing this answer. Turns out `maven-publish` creates a task `publish` automatically which does exactly what I wanted. I've updated the code snippet to reflect this.

*EDIT2:* Throw `GradleException` instead; it's slightly more idiomatic.
Since Android Gradle Plugin (AGP) v7.1.0, it's possible to publish library variants as one Maven publication. See the [release notes](https://developer.android.com/studio/releases/gradle-plugin?buildsystem=ndk-build#build-variant-publishing).

The release notes currently link to the wrong page (it doesn't contain examples). The page that it should probably link to, and that has various examples, is [this one](https://android.googlesource.com/platform/tools/base/+/2e1ff8e3b05a4fcaad12066c6f38633b6875a2ae/build-system/gradle-api/src/main/java/com/android/build/api/dsl/LibraryPublishing.kt). Look for one of the `multipleVariants` examples.