1515
1616public class ScipGradlePlugin implements Plugin <Project > {
1717
18+ // `--add-exports` flags required so our compiler plugin can access javac
19+ // internals. Required on JDK 17+ (JEP 403), no-op on 11-16. Kept in sync with
20+ // `javacModuleOptions` in build.sbt.
21+ private static final List <String > JAVAC_MODULE_OPTIONS =
22+ List .of (
23+ "-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" ,
24+ "-J--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" ,
25+ "-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED" ,
26+ "-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" ,
27+ "-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" );
28+
1829 @ Override
1930 public void apply (Project project ) {
2031 project .afterEvaluate (this ::configureProject );
@@ -29,17 +40,6 @@ private void configureProject(Project project) {
2940
3041 Object targetRoot = extraProperties .getOrDefault ("scipTarget" , project .getBuildDir ());
3142
32- String javacPluginVersion = BuildInfo .version ;
33-
34- Object javacPluginJar = extraProperties .get ("javacPluginJar" );
35-
36- // We fall back to the javac plugin published to Maven if there is no jar
37- // specified. The JAR would usually be provided by the auto-indexer.
38- Object javacPluginDep =
39- javacPluginJar != null
40- ? project .files (javacPluginJar )
41- : "com.sourcegraph:scip-javac:" + javacPluginVersion ;
42-
4343 File sourceRoot = project .getRootDir ();
4444
4545 // List of compilation commands that we will need to trigger to index all
@@ -61,6 +61,16 @@ private void configureProject(Project project) {
6161
6262 boolean compilerPluginAdded ;
6363 try {
64+ // The CLI's init script writes the absolute path of the embedded
65+ // scip-javac jar into the `javacPluginJar` extra property.
66+ Object javacPluginJar = extraProperties .get ("javacPluginJar" );
67+ if (javacPluginJar == null ) {
68+ throw new IllegalStateException (
69+ "javacPluginJar extra property must be set by the "
70+ + "scip-java init script when indexing Java sources" );
71+ }
72+ Object javacPluginDep = project .files (javacPluginJar );
73+
6474 project .getDependencies ().add ("compileOnly" , javacPluginDep );
6575
6676 if (hasAnnotationPath ) {
@@ -76,14 +86,16 @@ private void configureProject(Project project) {
7686 // dependencies to it. The project will be skipped (no SCIP output) and
7787 // the post-build check in `GradleBuildTool` will surface a clearer
7888 // error.
79- Logging .warn (
80- "scip-java: failed to attach SCIP compiler plugin to project '"
81- + project .getName ()
82- + "' ("
83- + exc .getClass ().getSimpleName ()
84- + ": "
85- + exc .getMessage ()
86- + "). This subproject will not be indexed." );
89+ project
90+ .getLogger ()
91+ .warn (
92+ "scip-java: failed to attach SCIP compiler plugin to project '"
93+ + project .getName ()
94+ + "' ("
95+ + exc .getClass ().getSimpleName ()
96+ + ": "
97+ + exc .getMessage ()
98+ + "). This subproject will not be indexed." );
8799 compilerPluginAdded = false ;
88100 }
89101
@@ -98,7 +110,7 @@ private void configureProject(Project project) {
98110 // 11-16.
99111 ForkOptions forkOptions = task .getOptions ().getForkOptions ();
100112 List <String > jvmArgs =
101- BuildInfo . javacModuleOptions .stream ()
113+ JAVAC_MODULE_OPTIONS .stream ()
102114 .map (arg -> arg .startsWith ("-J" ) ? arg .substring (2 ) : arg )
103115 .collect (Collectors .toList ());
104116 if (forkOptions .getJvmArgs () == null ) {
0 commit comments