When are a.b and a { b } interchangeable and when not?

software-model

(Kai Noda) #1

By experiments (rather than fully understanding the underlying mechanism,) I learned

cppCompiler {
  args '-pthread'
}

and

cppCompiler.args '-pthread'

were interchangeable. But to my surprise,

linker.args '-pthread'

and

linker {
    args '-pthread'
}

were not; the latter yielded an error:

* What went wrong:
A problem occurred configuring root project 'svn.maggott'.
> The following model rules could not be applied due to unbound inputs and/or subjects:

    model.components > create(timer) > org.gradle.platform.base.internal.DefaultComponentSpecIdentifier@6940e4b.getBinaries() > named(linker)
      subject:
        - components.timer.binaries.linker BinarySpec [*]

  [*] - indicates that a model item could not be found for the path or type.

Which part of the Gradle DSL Reference should I consult for relevant properties? Also, other pointers I’ve found so far:

https://docs.gradle.org/current/userguide/writing_build_scripts.html


(David Cowden) #2

Similarly:

model {
    binaries {
        withType(GoogleTestTestSuiteBinarySpec) {
            sources {
                ...
                }
            }
        }
    }
}

Yields

 "Could not find method sources() for arguments [org.gradle.model.dsl.internal.transform.ClosureBackedRuleFactory$1@133d6ff5] on project"

While

model {
    binaries {
        withType(GoogleTestTestSuiteBinarySpec) {
            it.sources {
                ...
                }
            }
        }
    }
}

Yields

"The following model rules could not be applied due to unbound inputs and/or subjects"