Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@

public class ScipGradlePlugin implements Plugin<Project> {

private static final List<String> ANDROID_PLUGINS =
List.of(
"com.android.application",
"com.android.library",
"com.android.test",
"com.android.dynamic-feature");

private static final List<String> ANDROID_ANNOTATION_PROCESSORS =
List.of("annotationProcessor", "testAnnotationProcessor", "androidTestAnnotationProcessor");

@Override
public void apply(Project project) {
project.afterEvaluate(this::configureProject);
Expand All @@ -37,18 +47,24 @@ private void configureProject(Project project) {
project.getExtensions().getExtraProperties().getProperties();

String targetRoot = requiredExtra(extraProperties, "scipTarget").toString();
String sourceRoot = project.getRootDir().toString();
// The CLI's working directory, not project.getRootDir(): buildSrc and
// included builds have their own root directory.
String sourceRoot = requiredExtra(extraProperties, "scipSourceroot").toString();

// Compilation tasks we need to trigger to index all the sources we care
// about. Built up as we detect the java and kotlin plugins.
List<String> triggers = new ArrayList<>();

if (project.getPlugins().hasPlugin("java")) {
triggers.add("compileJava");
triggers.add("compileTestJava");
boolean isAndroid = ANDROID_PLUGINS.stream().anyMatch(id -> project.getPlugins().hasPlugin(id));

if (project.getPlugins().hasPlugin("java") || isAndroid) {
if (!isAndroid) {
triggers.add("compileJava");
triggers.add("compileTestJava");
}

Object javacPluginDep = project.files(requiredExtra(extraProperties, "javacPluginJar"));
boolean pluginAdded = tryAddJavacPlugin(project, javacPluginDep);
boolean pluginAdded = tryAddJavacPlugin(project, javacPluginDep, isAndroid);

project
.getTasks()
Expand Down Expand Up @@ -142,10 +158,20 @@ private static boolean hasAnnotationProcessors(Project project, String configura
}
}

private static boolean tryAddJavacPlugin(Project project, Object javacPluginDep) {
private static boolean tryAddJavacPlugin(
Project project, Object javacPluginDep, boolean isAndroid) {
try {
project.getDependencies().add("compileOnly", javacPluginDep);
project.getDependencies().add("testCompileOnly", javacPluginDep);
if (isAndroid) {
// AGP always passes -processorpath, so javac only finds the plugin there.
for (String name : ANDROID_ANNOTATION_PROCESSORS) {
if (project.getConfigurations().findByName(name) != null) {
project.getDependencies().add(name, javacPluginDep);
}
}
return true;
}
if (hasAnnotationProcessors(project, "annotationProcessor")) {
project.getDependencies().add("annotationProcessor", javacPluginDep);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ This means our SCIP compiler plugin was not attached to one or more JavaCompile

allprojects {
project.ext["scipTarget"] = "${targetroot()}"
project.ext["scipSourceroot"] = "${index.workingDirectory}"
project.ext["javacPluginJar"] = "$pluginpath"
project.ext["dependenciesOut"] = "$dependenciesPath"
project.ext["scipKotlincJar"] = "$scipKotlincPath"
Expand Down
Loading