Gradle: Executing a custom JavaCompile task that was created in a custom plugin (in Java, not Groovy)

I’m writing a plugin that compiles the Java files that are in (/buildDir/generatedSrc) and puts them inside (/buildDir/generatedClasses). I registered the JavaCompile custom task in the plugin, and now when I run my test I want to be able to execute the JavaCompile task to see if it is actually compiling the files.

My plugin registers the JavaCompile task as follows:

TaskProvider javaCompileTaskProvider = tasks.register(COMPILE_GENERATED_CODE, JavaCompile.class, this::configureCompileTask);

private void configureCompileTask(JavaCompile task) task.dependsOn(project.getTasks().named(GENERATE_CODE));
    task.setSource(drwpPojoGen.getGeneratedSourcesDirectory());
    task.setDestinationDir(drwpPojoGen.getGeneratedClassesPath());
    task.setClasspath(project.files());
}

My test creates a project with a temporary project directory that applies the plugin. How can I execute the JavaCompile task in Java in my test?