How do you best add resources to compileClasspath?

We have a project which is a java-compiler plugin which can’t be cleanly added to a composite build using --include-build. It works fine if we publish to our maven repo and do not use --include-build.

We depend on and apply the compiler plugin as follows:

dependencies {

tasks.withType<JavaCompile> {

What makes a java compiler plugin special is that it includes a file in the jar telling the compiler what classes are compiler plugins. That file is META-INF/services/com.sun.source.util.Plugin which just contains a list of compiler plugins.

So, when not using composite builds, the jar is downloaded and everything works because this file is present on the classpath simply by virtue of being in the jar.

But, if you use --include-build, then the compileOnly dependency will create a dependency on the output of the compileJava task - but crucially not the outputs of processResources.

I have solved it for now with this piece of code - but it’s an ugly hack IMO:

        // Java compiler plugin needs some special love if used with --include-build feature of gradle
        try {
            val includedPlugin = gradle.includedBuild("plugin-root-project")
            sourceSets {
                named("main") {
                    java {
                        compileClasspath += files(includedPlugin.projectDir.resolve("plugin-project/build/resources/main/"))
            tasks.withType<JavaCompile> {
        } catch (_: UnknownDomainObjectException) {
            // Ignored - plugin is not included

Is there a better way to add the resources of the plugin-project to the compile classpath?

1 Like