Circular task dependencies when adding compiled reports to classpath

I have a problem with circular task dependencies in a very simple build file.

I’m using jasperreports-gradle-plugin, which provides a task (compileAllReports) for compiling report designs into reports.

One of my reports uses a class from src/main/java, so the report compilation task depends on the runtimeClasspath (which also contains the required JasperReports library jars).

The plugin provides a way to do that:

jasperreports {
    classpath.from(project.sourceSets.main.runtimeClasspath)
}

But now I need those compiled reports available as resources on the classpath.

So I tried to add the following:

sourceSets.main.resources.srcDir(compileAllReports)

But now I get the following error:

Circular dependency between the following tasks:
:classes
\--- :processResources
     \--- :compileAllReports
          \--- :classes (*)

This does make sense, but I’m wondering if there is a way to achieve what I’m trying to do?

Well, as you see, the runtimeClasspath of course also contains the resources, so besides having this circular dependency, you would also do unnecessary work.

I think these two should work better and more as expected:

jasperreports {
    classpath.from(
        project.sourceSets.main.java.classesDirectory,
        configurations.named(project.sourceSets.main.compileClasspathConfigurationName)
    )
}

jasperreports {
    classpath.from(
        tasks.named(project.sourceSets.main.compileJavaTaskName).flatMap { it.destinationDirectory },
        configurations.named(project.sourceSets.main.compileClasspathConfigurationName)
    )
}

Thank very much you Björn!

This was exactly what I was looking for, problem solved.

1 Like