PlatformAwareComponentSpec.targetPlatform doesn't behave according to documentation

It was raised to my attention that the behavior stated in the documentation 72.16.4 ( does reflect the reality for native development.

Considering the following build.gradle:

apply plugin: "c"
model {
  buildTypes {
  platforms {
    x86 {
      architecture "x86"
    x64 {
      architecture "x64"
  components {

The task listing show:

$ ./gradlew.bat :tasks

However, if we change the component definition to add targetPlatform specifically:

main(NativeExecutableSpec) {
  targetPlatform "x86"
  targetPlatform "x64"

The task listing is correct:

$ ./gradlew.bat :tasks

We should be expecting the later result with the first build.gradle configuration if the documentation is right. This was tested using Gradle 2.14.1

Hi Daniel,

You’re right, this is confusing.

The documentation says that as soon as you declare platforms they are all used as target platforms for all components except if you specify target platforms at the component level.

The actual behaviour is that as long as you don’t specify target platforms at the component level then only the “default current” one is used.

This changed in 2.3, see the breaking change section in the 2.3 release notes.
Looks like the documentation has not been updated since then, good catch!

I’ll update the docs.


Excellent thanks for the information. I will make sure my team is aware.

Here is the fix, please comment the commit if it is not clear enough.

Thanks Paul for the fix!

I commented the response I got from my developers on this fix. Hopefully, we can make the documentation clearer for Gradle users.

@Daniel_L, refined in 283b5b68b6a841e175390b308bb709dac4de1488

Thanks Paul! This works better. Thanks for the effort in clarifying this.

1 Like