@@ -21,6 +21,8 @@ import org.gradle.api.tasks.compile.JavaCompile
21
21
import org .gradle .api .tasks .scala .ScalaCompile
22
22
23
23
class SemanticdbGradlePlugin extends Plugin [Project ] {
24
+ import Logging ._
25
+
24
26
override def apply (project : Project ): Unit = {
25
27
val gradle = new GradleVersion (project.getGradle().getGradleVersion())
26
28
project.afterEvaluate { project =>
@@ -41,7 +43,7 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
41
43
.get(" javacPluginJar" )
42
44
.map(_.asInstanceOf [String ])
43
45
44
- val javacDep = javacPluginJar
46
+ val javacPluginDep = javacPluginJar
45
47
.map[Object ](jar => project.files(jar))
46
48
// we fallback to javac plugin published to maven if there is no jar specified
47
49
// the JAR would usually be provided by auto-indexer
@@ -75,20 +77,24 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
75
77
76
78
val compilerPluginAdded =
77
79
try {
78
- project.getDependencies().add(" compileOnly" , javacDep)
79
- if (hasAnnotationPath)
80
- project.getDependencies().add(" annotationProcessor" , javacDep)
81
- project.getDependencies().add(" testCompileOnly" , javacDep)
80
+ project.getDependencies().add(" compileOnly" , javacPluginDep)
81
+
82
+ if (hasAnnotationPath) {
83
+ project
84
+ .getDependencies()
85
+ .add(" annotationProcessor" , javacPluginDep)
86
+ }
87
+
88
+ project.getDependencies().add(" testCompileOnly" , javacPluginDep)
89
+
82
90
true
83
91
} catch {
84
92
case exc : Exception =>
85
93
// If the `compileOnly` configuration has already been evaluated
86
94
// by the build, we need to fallback on agent injected into javac
87
- System
88
- .err
89
- .println(
90
- s " Failed to add compiler plugin to javac, will go through the agent route: ${exc.getMessage()}"
91
- )
95
+ warn(
96
+ s " Failed to add compiler plugin to javac, will go through the agent route: ${exc.getMessage()}"
97
+ )
92
98
false
93
99
}
94
100
@@ -155,10 +161,12 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
155
161
task.getOptions().setIncremental(false )
156
162
157
163
if (compilerPluginAdded) {
158
- task
159
- .getOptions()
160
- .getCompilerArgs()
161
- .addAll(
164
+ val args = task.getOptions().getCompilerArgs()
165
+
166
+ // It's important we don't add the plugin configuration more than
167
+ // once, as javac considers that an error
168
+ if (! args.asScala.exists(_.startsWith(" -Xplugin:semanticdb" ))) {
169
+ args.addAll(
162
170
List (
163
171
// We add this to ensure that the sources are _always_
164
172
// recompiled, so that Gradle doesn't cache any state
@@ -168,6 +176,7 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
168
176
s " -Xplugin:semanticdb -targetroot: $targetRoot -sourceroot: $sourceRoot -randomtimestamp= ${System .nanoTime()}"
169
177
).asJava
170
178
)
179
+ }
171
180
}
172
181
173
182
/**
@@ -399,6 +408,8 @@ class SemanticdbGradlePlugin extends Plugin[Project] {
399
408
}
400
409
401
410
class WriteDependencies extends DefaultTask {
411
+ import Logging ._
412
+
402
413
@ TaskAction
403
414
def printResolvedDependencies (): Unit = {
404
415
@@ -411,11 +422,20 @@ class WriteDependencies extends DefaultTask {
411
422
412
423
val deps = List .newBuilder[String ]
413
424
val project = getProject()
425
+ val projectName = project.getName()
414
426
415
427
// List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project.
416
428
// The code below is roughly equivalent to the following with Groovy:
417
429
// deps += "$publication.groupId $publication.artifactId $publication.version $sourceSets.main.output.classesDirectory"
418
430
431
+ val crossRepoBanner =
432
+ """
433
+ |This will not prevent a SCIP index from being created, but the symbols
434
+ |extracted from this project won't be available for cross-repository navigation,
435
+ |as this project doesn't define any Maven coordinates by which it can be referred back to.
436
+ |See here for more details: https://sourcegraph.github.io/scip-java/docs/manual-configuration.html#step-5-optional-enable-cross-repository-navigation
437
+ """
438
+
419
439
Try (
420
440
project
421
441
.getExtensions()
@@ -425,45 +445,58 @@ class WriteDependencies extends DefaultTask {
425
445
.asScala
426
446
) match {
427
447
case Failure (exception) =>
428
- System
429
- .err
430
- .println(
431
- s """
432
- |Failed to extract Maven publication from the project ` ${project
433
- .getName()}`.
434
- |This will not prevent a SCIP index from being created, but the symbols
435
- |extracted from this project won't be available for cross-repository navigation,
436
- |as this project doesn't define any Maven coordinates by which it can be referred back to.
437
- |See here for more details: https://sourcegraph.github.io/scip-java/docs/manual-configuration.html#step-5-optional-enable-cross-repository-navigation
438
- |Here's the raw error message:
439
- | " ${exception.getMessage()}"
440
- |Continuing without cross-repository support.
441
- """ .stripMargin.trim()
442
- )
448
+ warn(s """
449
+ |Failed to extract Maven publication from the project ` $projectName`.
450
+ $crossRepoBanner
451
+ |Here's the raw error message:
452
+ | " ${exception.getMessage()}"
453
+ |Continuing without cross-repository support.
454
+ """ .stripMargin.trim())
443
455
444
456
case Success (publications) =>
445
457
publications.foreach { publication =>
446
- project
447
- .getExtensions()
448
- .getByType(classOf [SourceSetContainer ])
449
- .getByName(" main" )
450
- .getOutput()
451
- .getClassesDirs()
452
- .getFiles()
453
- .asScala
454
- .toList
455
- .map(_.getAbsolutePath())
456
- .sorted
457
- .take(1 )
458
- .foreach { classesDirectory =>
459
- deps +=
460
- List (
461
- publication.getGroupId(),
462
- publication.getArtifactId(),
463
- publication.getVersion(),
464
- classesDirectory
465
- ).mkString(" \t " )
466
- }
458
+ Try (
459
+ project
460
+ .getExtensions()
461
+ .getByType(classOf [SourceSetContainer ])
462
+ .getByName(" main" )
463
+ ) match {
464
+ case Failure (exception) =>
465
+ val publicationName = List (
466
+ publication.getGroupId(),
467
+ publication.getArtifactId(),
468
+ publication.getVersion()
469
+ ).mkString(" :" )
470
+
471
+ warn(s """
472
+ |Failed to extract `main` source set from publication ` ${publicationName}` in project ` $projectName``.
473
+ $crossRepoBanner
474
+ |Here's the raw error message:
475
+ | " ${exception.getMessage()}"
476
+ |Continuing without cross-repository support.
477
+ """ .stripMargin.trim())
478
+
479
+ case Success (value) =>
480
+ value
481
+ .getOutput()
482
+ .getClassesDirs()
483
+ .getFiles()
484
+ .asScala
485
+ .toList
486
+ .map(_.getAbsolutePath())
487
+ .sorted
488
+ .take(1 )
489
+ .foreach { classesDirectory =>
490
+ deps +=
491
+ List (
492
+ publication.getGroupId(),
493
+ publication.getArtifactId(),
494
+ publication.getVersion(),
495
+ classesDirectory
496
+ ).mkString(" \t " )
497
+ }
498
+
499
+ }
467
500
}
468
501
}
469
502
@@ -511,3 +544,12 @@ class WriteDependencies extends DefaultTask {
511
544
}
512
545
}
513
546
}
547
+
548
+ private object Logging {
549
+ def info (msg : Any * ) =
550
+ System .err.println(s " [INFO] [scip-java.gradle] ${msg.mkString(" " )}" )
551
+
552
+ def warn (msg : Any * ) =
553
+ System .err.println(s " [WARNING] [scip-java.gradle] ${msg.mkString(" " )}" )
554
+
555
+ }
0 commit comments