Gradle `tasks.withType()` strange behavior for tasks added afterwards
<p>I am using Gradle 2.14.1 and the <a href="https://github.com/unbroken-dome/gradle-testsets-plugin" rel="nofollow">https://github.com/unbroken-dome/gradle-testsets-plugin</a> to add an integration test task. I would like to configures the location of the HTML reports.
The default tasks uses:</p>

<pre><code>&lt;project&gt;/build/reports/tests
</code></pre>

<p>The testsets plugin configures:</p>

<pre><code>&lt;project&gt;/build/intTest
</code></pre>

<p>for the <code>intTest</code> task, and I want:</p>

<pre><code>&lt;project&gt;/build/reports/test
&lt;project&gt;/build/reports/intTest
</code></pre>

<p>Here is my configuration:</p>

<pre><code>buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:1.2.0'
    }
}

apply plugin: 'java'
apply plugin: 'org.unbroken-dome.test-sets'

defaultTasks = ['clean', 'build']

tasks.withType(Test) {
    reports.html.destination = new File(project.reportsDir, name)

    println(it.name + '\t' + reports.html.destination)
}

task wrapper(type: Wrapper) {
    description = 'Defines the common gradle distribution for this project.'
    gradleVersion = '2.14.1'
}

testSets {
    intTest
}

intTest.dependsOn test
check.dependsOn intTest

repositories {
    jcenter()
}

dependencies {
    testCompile 'junit:junit:4.12'
    intTestCompile 'junit:junit:4.12'
}

println('===== final config =====')
println(test.name + '\t' + test.reports.html.destination)
println(intTest.name + '\t' + intTest.reports.html.destination)
</code></pre>

<p>(Please ignore the <code>println</code> statements for the time being.)</p>

<p>After a full build, the <code>intTest</code> task's reports are in the wrong place (the default), and the configuration for the standard <code>test</code> task is applied:</p>

<pre><code>$ ls build/
classes  dependency-cache  intTest  intTest-results  libs  reports  test-results  tmp

$ ls build/reports/
test
</code></pre>

<p>I added some output to see what is going on, and it seems strange (the project's root is 'blob'):</p>

<pre><code>test    /home/wujek/blob/build/reports/test
intTest /home/wujek/blob/build/reports/intTest
===== final config =====
test    /home/wujek/blob/build/reports/test
intTest /home/wujek/blob/build/intTest
</code></pre>

<p>So, in the <code>tasks.withType()</code> block the location is reported to be correct, but in the end, it is not.</p>

<p>Please note that moving the <code>tasks.withType()</code> block after the <code>testSets</code> block works for this project, but my real setup is mode complex: I have mutliple modules, and the root <code>build.gradle</code> uses the <code>subprojects</code> block with the <code>tasks.withType()</code> block to configure the report locations for all modules, and then one of the submodules adds a new test set and its test task's HTML report has the wrong location. To fix this, I have to repeat the configuration in the submodules that add test sets.</p>

<p>What is going on here? Why does the <code>tasks.withType()</code> block say the config works, but in reality it doesn't?</p>