Add special handling for the main and test source sets in aspectJ
the test source set now inherits all aspects of the main aspectpath and main output
(The same way as the test classpath inherits from the main classpath and main output"
@@ -6,9 +6,11 @@ import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.internal.plugins.DslObject;
import org.gradle.api.plugins.JavaBasePlugin;
+import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.internal.SourceSetUtil;
import org.gradle.api.provider.Provider;
+import org.gradle.api.tasks.SourceSet;
/**
* @see org.gradle.api.plugins.GroovyBasePlugin
@@ -16,14 +18,36 @@ import org.gradle.api.provider.Provider;
*/
public class AspectJPlugin implements Plugin<Project> {
+ private Project project;
+
@Override
public void apply(Project project) {
+ this.project = project;
project.getPlugins().apply(AspectJBasePlugin.class);
project.getPlugins().apply(JavaBasePlugin.class);
JavaPluginConvention plugin = project.getConvention().getPlugin(JavaPluginConvention.class);
- plugin.getSourceSets().all(sourceSet -> {
+ plugin.getSourceSets().all(this::configureSourceSet);
+
+ project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
+
+ SourceSet main = plugin.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
+ SourceSet test = plugin.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
+
+ DefaultAspectjSourceSet mainAj = new DslObject(main).getConvention().getPlugin(DefaultAspectjSourceSet.class);
+ DefaultAspectjSourceSet testAj = new DslObject(test).getConvention().getPlugin(DefaultAspectjSourceSet.class);
+
+ Configuration aspectpath = project.getConfigurations().getByName(mainAj.getAspectConfigurationName());
+ Configuration testAspectpath = project.getConfigurations().getByName(testAj.getAspectConfigurationName());
+
+ testAspectpath.extendsFrom(aspectpath);
+
+ testAj.setAspectPath(project.getObjects().fileCollection().from(main.getOutput(), testAspectpath));
+ });
+ }
+
+ private void configureSourceSet(SourceSet sourceSet) {
DefaultAspectjSourceSet aspectjSourceSet = new DefaultAspectjSourceSet(project.getObjects(), sourceSet);
new DslObject(sourceSet).getConvention().getPlugins().put("aspectj", aspectjSourceSet);
@@ -53,6 +77,5 @@ public class AspectJPlugin implements Plugin<Project> {
SourceSetUtil.configureOutputDirectoryForSourceSet(sourceSet, aspectjSourceSet.getAspectj(), project, compileTask, compileTask.map(AspectjCompile::getOptions));
project.getTasks().named(sourceSet.getClassesTaskName(), task -> task.dependsOn(compileTask));
- });
}
}
