@@ -5,7 +5,7 @@ import java.nio.file.Paths
55import java .{util => ju }
66
77import scala .jdk .CollectionConverters ._
8- import scala .util .Try
8+ import scala .util .control . NonFatal
99
1010import com .sourcegraph .scip_java .BuildInfo
1111import org .gradle .api .DefaultTask
@@ -405,35 +405,42 @@ class WriteDependencies extends DefaultTask {
405405 // List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project.
406406 // The code below is roughly equivalent to the following with Groovy:
407407 // deps += "$publication.groupId $publication.artifactId $publication.version $sourceSets.main.output.classesDirectory"
408- Try (
409- project
410- .getExtensions()
411- .getByType(classOf [SourceSetContainer ])
412- .getByName(" main" )
413- .getOutput()
414- .getClassesDirs()
415- .getFiles()
416- .asScala
417- .toList
418- .map(_.getAbsolutePath())
419- .sorted
420- .headOption
421- ).collect { case Some (classesDirectory) =>
422- project
423- .getExtensions()
424- .findByType(classOf [PublishingExtension ])
425- .getPublications()
426- .withType(classOf [MavenPublication ])
427- .asScala
428- .foreach { publication =>
429- deps +=
430- List (
431- publication.getGroupId(),
432- publication.getArtifactId(),
433- publication.getVersion(),
434- classesDirectory
435- ).mkString(" \t " )
436- }
408+ try {
409+ for {
410+ classesDirectory <- project
411+ .getExtensions()
412+ .getByType(classOf [SourceSetContainer ])
413+ .getByName(" main" )
414+ .getOutput()
415+ .getClassesDirs()
416+ .getFiles()
417+ .asScala
418+ .toList
419+ .map(_.getAbsolutePath())
420+ .sorted
421+ .take(1 )
422+ publication <-
423+ project
424+ .getExtensions()
425+ .findByType(classOf [PublishingExtension ])
426+ .getPublications()
427+ .withType(classOf [MavenPublication ])
428+ .asScala
429+ } {
430+ deps +=
431+ List (
432+ publication.getGroupId(),
433+ publication.getArtifactId(),
434+ publication.getVersion(),
435+ classesDirectory
436+ ).mkString(" \t " )
437+ }
438+ } catch {
439+ case NonFatal (ex) =>
440+ println(
441+ s " Failed to extract publication from project ${project.getName()}"
442+ )
443+ ex.printStackTrace()
437444 }
438445
439446 project
0 commit comments