Skip to content
Merged
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
5 changes: 4 additions & 1 deletion docs/manual-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ javac -classpath semanticdb-javac.jar MyApplication.java
If you're using Gradle.

```groovy
compileOnly group: 'com.sourcegraph', name: 'semanticdb-javac', version: '@STABLE_VERSION@'
// Option 1: if you are not using annotation processors
compileOnly 'com.sourcegraph:semanticdb-javac:@STABLE_VERSION@'
// Option 2: if you are using annotation processors
annotationProcessor 'com.sourcegraph:semanticdb-javac:@STABLE_VERSION@'
```

If you're using Maven.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ class GradleBuildTool(index: IndexCommand) extends BuildTool("Gradle", index) {
buildCommand +=
s"-Porg.gradle.java.installations.paths=${toolchains.paths()}"
}
buildCommand ++= index.finalBuildCommand(List("clean", "compileTestJava"))
buildCommand ++=
index.finalBuildCommand(
List(
// Disable the checkerframework plugin because it updates the processorpath
// in a way that causes the error "plug-in not found: semanticdb".
// Details: https://github.com/kelloggm/checkerframework-gradle-plugin/blob/76d1926ae22144b082dfcfde1abe625750469398/src/main/groovy/org/checkerframework/gradle/plugin/CheckerFrameworkPlugin.groovy#L374-L376
"-PskipCheckerFramework",
Comment on lines +84 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange that we need this, the commit that added this logic specifically mentions not overwriting the existing annotationProcessor path 🤔 kelloggm/checkerframework-gradle-plugin@3db37da

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's stranger is that I validated that SemanticdbAgent is updating the processorpath correctly. It looks like a Gradle initialization order issue to me that's difficult to fix. It's easy to disable the checker framework so I went with this approach instead

"clean",
"compileTestJava"
)
)
buildCommand += lsifJavaDependencies

val result = index.process(buildCommand, env = Map("TERM" -> "dumb"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,18 @@ public static void build(
switch (previousOption) {
case "-processorpath":
case "-processor-path":
case "-cp":
case "-classpath":
case "-class-path":
isProcessorpathUpdated = true;
newOptions.add(PLUGINPATH + File.pathSeparator + option);
break;
case "-Xlint":
break;
default:
if (option.startsWith("-Xplugin:ErrorProne")) {
break;
}
newOptions.add(option);
break;
}
Expand All @@ -155,13 +161,19 @@ public static void build(
"-Xplugin:semanticdb -sourceroot:%s -targetroot:%s", SOURCEROOT, TARGETROOT));

if (DEBUGPATH != null) {
try (PrintStream fos =
new PrintStream(
Files.newOutputStream(
Paths.get(DEBUGPATH), StandardOpenOption.APPEND, StandardOpenOption.CREATE))) {
fos.println("Java Home: " + System.getProperty("java.home"));
fos.println("Old Options: " + arguments);
fos.println("New Options: " + newOptions);
ArrayList<String> debuglines = new ArrayList<>();
debuglines.add("============== Java Home: " + System.getProperty("java.home"));
debuglines.add("============== Old Options");
debuglines.addAll(arguments);
debuglines.add("============== New Options");
debuglines.addAll(newOptions);

try {
Files.write(
Paths.get(DEBUGPATH),
debuglines,
StandardOpenOption.CREATE,
StandardOpenOption.APPEND);
} catch (IOException e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract class BaseBuildToolSuite extends MopedSuite(LsifJava.app) {
if (semanticdbFiles.length != expectedSemanticdbFiles) {
fail(
s"Expected $expectedSemanticdbFiles SemanticDB file(s) to be generated.",
clues(semanticdbFiles)
clues(semanticdbFiles, app.capturedOutput)
)
}
if (expectedPackages.nonEmpty) {
Expand Down
26 changes: 26 additions & 0 deletions tests/buildTools/src/test/scala/tests/GradleBuildToolSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,30 @@ class GradleBuildToolSuite extends BaseBuildToolSuite {
2, // Two files because `conf/routes` generates a Java file.
initCommand = gradleVersion("6.8")
)

checkBuild(
"checkerframework",
"""|/build.gradle
|plugins {
| id 'java'
| id 'org.checkerframework' version '0.5.24'
|}
|repositories {
| mavenCentral()
|}
|java {
| toolchain {
| languageVersion = JavaLanguageVersion.of(8)
| }
|}
|/src/main/java/foo/Example.java
|package foo;
|public class Example {}
|/src/test/java/foo/ExampleSuite.java
|package foo;
|public class ExampleSuite {}
|""".stripMargin,
2,
initCommand = gradleVersion("6.8.3")
)
}