2.12 nightly running rule twice


(pledbrook) #1

I’ve started to play with Gradle 2.12 nightly to take advantage of improvements in the software model, but I’m hitting the following error for an @ComponentBinaries rule:

* What went wrong:
A problem occurred configuring root project 'junit8188350447950370203'.
> Exception thrown while executing model rule: AsciidoctorPlugin.Rules#generateBinaries
   > Cannot create 'components.docs.binaries.html' using creation rule 'AsciidoctorPlugin.Rules#generateBinaries > create(html)' as the rule 'AsciidoctorPlugin.Rules#generateBinaries > create(html)' has already been used to create this model element.

The rule itself isn’t complicated:

void generateBinaries(
        ModelMap<AsciidocBinarySpecInternal> binaries,
        AsciidocDocumentSpec component,
        @Path("buildDir") File buildDir) {
    println "Running generateBinaries() rule"
    println "Binaries: ${binaries}"
    println "Component: ${component.name}"
    binaries.create("html", HtmlBinarySpecInternal) { binary ->
        binary.document = component

    binaries.create("pdf", PdfBinarySpecInternal) { binary ->
        binary.document = component

I’ve put the project on a dedicated branch in GitHub. Simply get hold of it and run ./gradlew intTest. The error appears in the test reports.

(Mark Vieira) #2

Are you defining multiple components? If so then the result is you’ll try to creating multiple binaries called “pdf” and “html”. You should give these unique names, typically via some convention that includes the originating component name. Essentially, yes, this rule is being run multiple times, once for each AsciidocDocumentSpec.

(pledbrook) #3

There is only one component, defined in the test build file. Here’s the output from those printlns:

Running generateBinaries() rule
Binaries: ModelMap<AsciidocBinarySpecInternal> 'components.docs.binaries'
Component: docs
Running generateBinaries() rule
Binaries: ModelMap<AsciidocBinarySpecInternal> 'components.docs.binaries'
Component: docs

which indicates that the rule is running twice for the same component.

(pledbrook) #4

@mark_vieira You say that the binaries should be given unique names, but there is no indication of this in section 73.5.1 of the user guide. The example hard codes the binary name “exploded”. Should that example recommend unique names for binaries?

(Mark Vieira) #5

That does indeed make it seem like that rules is being evaluated twice.

That’s my understanding, unless @ComponentBinaries does some trickery here. In reality, you can’t have multiple model elements with the same path, so there cannot be two binaries.exploded.

@CedricChampeau are my assumptions correct. Is Peter running into a bug here?

(Cédric Champeau) #6

Yes, it’s very likely a bug.

(pledbrook) #7

This still seems to be a problem in 2.12-rc-1.

(pledbrook) #8

Yup, 2.12 hasn’t fixed it. This may be an issue with the TestKit, but whatever the source of the problem, it’s a blocker for me continuing with the new software model experiment.

(Cédric Champeau) #9

Hi Peter,

Just to let you know, I’m investigating this issue. The rule is still executed twice, and as far as I can tell, it’s not related to TestKit.

(pledbrook) #10

OK. Thanks for the update.