This message was deleted.
# community-support
s
This message was deleted.
m
I think that this configuration is broken anyway. Imagine you only run `jacocoReport`: then the task to be configured would be
jacocoReport
, which has no dependency, so the
dependsOn
wouldn't be executed. I think the reason it kind of works is because you use
map
, which will trigger eager configuration of the test tasks.
j
I agree! That's why I am looking for some nicer way to do this (if there is any). I don't want the dependsOn at all.
v
What is wrong with
jacocoReport.executionData(project.tasks.withType(Test::class.java)
?
It would also configure all test tasks as it internally uses
.all
on the given task collection, but at least it is more succinct and doesn't need an explicit
dependsOn
Ah, no, it doesn't add the task dependency, but just configures
mustRunAfter
😞
So then only idea I have right now is
Copy code
val tests = project.tasks.withType(Test::class.java)
jacocoReport.executionData(tests)
jacocoReport.dependsOn(tests)
Which is slightly safer than your version as it also gets test tasks added in the future. Which you of course also could get by replacing
map
with
all
in your version.
j
I wasn't aware (or forgot) that this is sufficient in case of JaCoCo:
jacocoReport.executionData(project.tasks.withType(Test::class.java))
Thanks!
v
Not for having the task dependency, is it?
j
It's nicer (although you still need dependsOn)
m
is it sufficient? how does the report knows that it's the execution data output of the test task that it needs?
I would expect the output of
Test
to be the test reports...
j
I think that's implemented it he JacocoReport task
m
🤔
j
Magic from the old Gradle days...
v
Copy code
public void executionData(TaskCollection tasks) {
        tasks.all((Action<Task>) this::executionData);
    }
and
Copy code
public void executionData(Task... tasks) {
        for (Task task : tasks) {
            final JacocoTaskExtension extension = task.getExtensions().findByType(JacocoTaskExtension.class);
            if (extension != null) {
                executionData(new Callable<File>() {
                    @Override
                    public File call() {
                        return extension.getDestinationFile();
                    }
                });
                mustRunAfter(task);
            }
        }
    }
m
but
all
will eagerly configure 😞
j
Yes. It doesn't work! Good old:
Copy code
DefaultTaskCollection#all(Action) on task set cannot be executed in the current context.
This is pretty broken in the JacocoReportTask impl 😕
v
Oh. 😞
Yeah, there is some lazy mapping missing for task collections, or domain collections in general