Missing @Path("buildDir") in NativeBinaryRules#assignTools rule

There seems to be a bug at line 32 of file NativeBinaryRules.java [1]. The rule assume only one node will be of type File which maps to buildDir (the @Path is commented out). This is problematic when trying to follow the same pattern and have root element for reports directory and possibly more. The following code show the failure:

class Rules extends RuleSource {
  @Model
  File reportsDir(@Path("buildDir") File buildDir) {
    return new File(buildDir, "reports")
  }
}
apply plugin: Rules
apply plugin: "cpp"

model {
  toolChains {
    msvc(VisualCpp)
  }
  components {
    main(NativeExecutableSpec)
  }
}

Executing $ ./gradlew.bat :tasks will cause the following exception:

> Exception thrown while executing model rule: NativeComponentModelPlugin.Rules#createBinaries(TargetedNativeComponentInterval, PlatformResolvers, BuildTypeContainer, FlavorContainer, ServiceRegistry) > named(executable, org.gradle.nativeplatform.internal.configure.NativeBinaryRules)
    > There is a problem with model rule NativeBinaryRules#assignTools(NativeBinarySpec, NativeToolChainRegistryInternal, File).
        > Type-only model reference of type java.io.File (parameter 3) is ambiguous as multiple model elements are available for this type:
            - buildDir (created by: Project.<init>.buildDir())
            - reportsDir (created by: Rules#reportsDir(File))

The gradle version we are using is 2.14.1 on a Windows operating system. They may be other rules coded like this one which would require grepping the codebase in order to find them and apply a fix.

[1] https://github.com/gradle/gradle/blob/master/subprojects/platform-native/src/main/java/org/gradle/nativeplatform/internal/configure/NativeBinaryRules.java#L32

Hi Daniel and thanks for reporting this. It definitely looks like a bug. I have created https://issues.gradle.org/browse/GRADLE-3523 to track this. Maybe you would be interested in contributing a fix?

I went ahead and fixed the issue.
It will be part of 3.1.

I confirmed, it is fixed. Thanks a lot!

1 Like