@ -22,6 +22,8 @@ import org.gradle.api.file.ConfigurableFileCollection;
@@ -22,6 +22,8 @@ import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.plugins.JavaPlugin ;
import org.gradle.api.plugins.JavaPluginExtension ;
import org.gradle.api.tasks.SourceSet ;
import org.gradle.api.tasks.TaskProvider ;
import org.gradle.language.base.plugins.LifecycleBasePlugin ;
/ * *
* { @link Plugin } for projects that define test auto - configuration . When the
@ -39,16 +41,20 @@ public class TestAutoConfigurationPlugin implements Plugin<Project> {
@@ -39,16 +41,20 @@ public class TestAutoConfigurationPlugin implements Plugin<Project> {
@Override
public void apply ( Project target ) {
target . getPlugins ( ) . withType ( JavaPlugin . class , ( plugin ) - > {
target . getTasks ( ) . register ( "checkAutoConfigureImports" , CheckAutoConfigureImports . class , ( task ) - > {
SourceSet mainSourceSet = target . getExtensions ( )
. getByType ( JavaPluginExtension . class )
. getSourceSets ( )
. getByName ( SourceSet . MAIN_SOURCE_SET_NAME ) ;
task . setSource ( mainSourceSet . getResources ( ) ) ;
ConfigurableFileCollection classpath = target . files ( mainSourceSet . getRuntimeClasspath ( ) ,
target . getConfigurations ( ) . getByName ( mainSourceSet . getRuntimeClasspathConfigurationName ( ) ) ) ;
task . setClasspath ( classpath ) ;
} ) ;
TaskProvider < CheckAutoConfigureImports > checkAutoConfigureImports = target . getTasks ( )
. register ( "checkAutoConfigureImports" , CheckAutoConfigureImports . class , ( task ) - > {
SourceSet mainSourceSet = target . getExtensions ( )
. getByType ( JavaPluginExtension . class )
. getSourceSets ( )
. getByName ( SourceSet . MAIN_SOURCE_SET_NAME ) ;
task . setSource ( mainSourceSet . getResources ( ) ) ;
ConfigurableFileCollection classpath = target . files ( mainSourceSet . getRuntimeClasspath ( ) ,
target . getConfigurations ( ) . getByName ( mainSourceSet . getRuntimeClasspathConfigurationName ( ) ) ) ;
task . setClasspath ( classpath ) ;
} ) ;
target . getTasks ( )
. named ( LifecycleBasePlugin . CHECK_TASK_NAME )
. configure ( ( check ) - > check . dependsOn ( checkAutoConfigureImports ) ) ;
} ) ;
}