Access platforms extension Gradle 2.0

In pre Gradle 2.0 to get the PlatformContainer (added by native-binaries plugin) one could do the following:

project.extensions.getByType(PlatformContainer).whenObjectAdded { targetPlatforms ->
...
}

I can’t seem to find out how to do a similar action with Gradle 2.0, because the code above throws:

> Extension of type 'PlatformContainer' does not exist. Currently registered extension types: [DefaultExtraPropertiesExtension, DefaultArtifactPublicationSet_Decorated, DefaultProjectComponentContainer_Decorated, DefaultProjectSourceSet_Decorated, DefaultBinaryContainer_Decorated, DefaultNativeComponentExtension_Decorated, DefaultNamedDomainObjectSet_Decorated, TypedDomainObjectContainerWrapper_Decorated, TypedDomainObjectContainerWrapper_Decorated, DefaultPublishingExtension_Decorated, ReportingExtension_Decorated]

I’m trying to hook into what platforms have been specified in the build file in order to create tasks based on the platform/architecture configurations.

Looks like this stuff is in limbo: https://github.com/gradle/gradle/blob/master/design-docs/unified-configuration-and-task-model.md

Through some investigation, I found that the Gradle 2.0 way of doing this can be shown via the following example:

model {
  platforms {
    create("linux-x86_64") {
      operatingSystem "linux"
      architecture "x86_64"
    }
      create("linux-i386") {
      operatingSystem "linux"
      architecture "i386"
    }
  }
    tasks {
    platforms.each { platform ->
      tasks.create("build${platform.name}", Exec) {
        executable "make"
        args "platform=${platform.operatingSystem.name}",
             "arch=${platform.architecture.name}"
      }
    }
  }
}

The last remaining issue I’m having is that the publishing mechanism doesn’t seem to be able to see these tasks during publication configuration time. If I add a “builtBy” function into the artifact… such as:

artifact(...) {
  ...
  builtBy "build${platform.name}"
}

I get the error:

Could not determine the dependencies of task ':publishLinux-x86_64PublicationToIvyRepository'

These incubating features are under heavy development as we migrate to the new configuration model. This affects the native component model as well as the ‘new’ publishing model. It’s a rapidly moving target, and your best bet would be to stick with a working version, or track the progress closely.

Until the new publishing plugins are fully converted to model rules, it’s going to be tough to get them working together with the native stuff.