@@ -5,7 +5,7 @@ import java.nio.file.Paths
55import java .{util => ju }
66
77import scala .jdk .CollectionConverters ._
8- import scala .util .control . NonFatal
8+ import scala .util ._
99
1010import com .sourcegraph .scip_java .BuildInfo
1111import org .gradle .api .DefaultTask
@@ -416,42 +416,56 @@ class WriteDependencies extends DefaultTask {
416416 // List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project.
417417 // The code below is roughly equivalent to the following with Groovy:
418418 // deps += "$publication.groupId $publication.artifactId $publication.version $sourceSets.main.output.classesDirectory"
419- try {
420- for {
421- classesDirectory <- project
422- .getExtensions()
423- .getByType(classOf [SourceSetContainer ])
424- .getByName(" main" )
425- .getOutput()
426- .getClassesDirs()
427- .getFiles()
428- .asScala
429- .toList
430- .map(_.getAbsolutePath())
431- .sorted
432- .take(1 )
433- publication <-
419+
420+ Try (
421+ project
422+ .getExtensions()
423+ .findByType(classOf [PublishingExtension ])
424+ .getPublications()
425+ .withType(classOf [MavenPublication ])
426+ .asScala
427+ ) match {
428+ case Failure (exception) =>
429+ System
430+ .err
431+ .println(
432+ s """
433+ |Failed to extract Maven publication from the project ` ${project
434+ .getName()}`.
435+ |This will not prevent a SCIP index from being created, but the symbols
436+ |extracted from this project won't be available for cross-repository navigation,
437+ |as this project doesn't define any Maven coordinates by which it can be referred back to.
438+ |See here for more details: https://sourcegraph.github.io/scip-java/docs/manual-configuration.html#step-5-optional-enable-cross-repository-navigation
439+ |Here's the raw error message:
440+ | " ${exception.getMessage()}"
441+ |Continuing without cross-repository support.
442+ """ .stripMargin.trim()
443+ )
444+
445+ case Success (publications) =>
446+ publications.foreach { publication =>
434447 project
435448 .getExtensions()
436- .findByType(classOf [PublishingExtension ])
437- .getPublications()
438- .withType(classOf [MavenPublication ])
449+ .getByType(classOf [SourceSetContainer ])
450+ .getByName(" main" )
451+ .getOutput()
452+ .getClassesDirs()
453+ .getFiles()
439454 .asScala
440- } {
441- deps +=
442- List (
443- publication.getGroupId(),
444- publication.getArtifactId(),
445- publication.getVersion(),
446- classesDirectory
447- ).mkString(" \t " )
448- }
449- } catch {
450- case NonFatal (ex) =>
451- println(
452- s " Failed to extract publication from project ${project.getName()}"
453- )
454- ex.printStackTrace()
455+ .toList
456+ .map(_.getAbsolutePath())
457+ .sorted
458+ .take(1 )
459+ .foreach { classesDirectory =>
460+ deps +=
461+ List (
462+ publication.getGroupId(),
463+ publication.getArtifactId(),
464+ publication.getVersion(),
465+ classesDirectory
466+ ).mkString(" \t " )
467+ }
468+ }
455469 }
456470
457471 project
0 commit comments