Can anyone explain the javaPlugin source code?

I am trying to figure out how to solve this new issue in gradle 7.1.1 but do it in my plugin this time instead β†’ Gradle 7.1.1 broke sourceSet redirect?

I read this code in the java plugin

    private void configureSourceSets(Project project, JavaPluginExtension pluginExtension, BuildOutputCleanupRegistry buildOutputCleanupRegistry) {
        SourceSetContainer sourceSets = pluginExtension.getSourceSets();
        SourceSet main = (SourceSet)sourceSets.create("main");
        SourceSet test = (SourceSet)sourceSets.create("test");
        test.setCompileClasspath(project.getObjects().fileCollection().from(new Object[]{main.getOutput(), project.getConfigurations().getByName("testCompileClasspath")}));
        test.setRuntimeClasspath(project.getObjects().fileCollection().from(new Object[]{test.getOutput(), main.getOutput(), project.getConfigurations().getByName("testRuntimeClasspath")}));
        sourceSets.all((sourceSet) -> {
            buildOutputCleanupRegistry.registerOutputs(sourceSet.getOutput());
        });
    }

Using the above as an example, I think I want to call
main.setRuntimeClasspath(.) for files src/main/java//*.html
test.setRuntimeClasspath(…) for files in src/test/java/
/*html

This is a β€œset” method though and I don’t want to erase the classpath and replace. I only want to add to the classpath that is being set in the above code. Is there a way to do that?

thanks,
Dean

Hello,

I think your are looking for the plus method of FileCollection (Gradle API 7.1.1)

You often see in Groovy snippets compileClasspath += anotherFileCollection, in a Java plugin this translates to: x.setCompileClasspath(x.getCompileClasspath().plus(anotherFileCollection));

1 Like