@@ -37,16 +37,8 @@ private void configureProject(Project project) {
3737 triggers .add ("compileJava" );
3838 triggers .add ("compileTestJava" );
3939
40- boolean hasAnnotationPath ;
41- try {
42- Configuration apConfig = project .getConfigurations ().getByName ("annotationProcessor" );
43- hasAnnotationPath = apConfig .isCanBeResolved () && !apConfig .getDependencies ().isEmpty ();
44- } catch (Exception exc ) {
45- hasAnnotationPath = false ;
46- }
47-
4840 Object javacPluginDep = project .files (requiredExtra (extraProperties , "javacPluginJar" ));
49- boolean pluginAdded = tryAddJavacPlugin (project , javacPluginDep , hasAnnotationPath );
41+ boolean pluginAdded = tryAddJavacPlugin (project , javacPluginDep );
5042
5143 project
5244 .getTasks ()
@@ -113,13 +105,32 @@ private void configureProject(Project project) {
113105 project .getTasks ().create ("scipPrintDependencies" , WriteDependencies .class );
114106 }
115107
116- private static boolean tryAddJavacPlugin (
117- Project project , Object javacPluginDep , boolean hasAnnotationPath ) {
108+ /**
109+ * javac discovers {@code -Xplugin:} plugins from the annotation processor path when {@code
110+ * -processorpath} is set, and only falls back to the classpath when it isn't. Gradle populates
111+ * {@code -processorpath} from the {@code annotationProcessor} (main) and {@code
112+ * testAnnotationProcessor} (test) configurations, so whenever one of them declares a processor we
113+ * must add the SCIP javac plugin to that same configuration or the corresponding compile task
114+ * fails with "plug-in not found: scip". The two configurations are independent (test does not
115+ * extend main), so each is checked separately.
116+ */
117+ private static boolean hasAnnotationProcessors (Project project , String configurationName ) {
118+ try {
119+ Configuration config = project .getConfigurations ().getByName (configurationName );
120+ return config .isCanBeResolved () && !config .getDependencies ().isEmpty ();
121+ } catch (Exception exc ) {
122+ return false ;
123+ }
124+ }
125+
126+ private static boolean tryAddJavacPlugin (Project project , Object javacPluginDep ) {
118127 try {
119128 project .getDependencies ().add ("compileOnly" , javacPluginDep );
120129 project .getDependencies ().add ("testCompileOnly" , javacPluginDep );
121- if (hasAnnotationPath ) {
130+ if (hasAnnotationProcessors ( project , "annotationProcessor" ) ) {
122131 project .getDependencies ().add ("annotationProcessor" , javacPluginDep );
132+ }
133+ if (hasAnnotationProcessors (project , "testAnnotationProcessor" )) {
123134 project .getDependencies ().add ("testAnnotationProcessor" , javacPluginDep );
124135 }
125136 return true ;
0 commit comments