@@ -5,7 +5,7 @@ import java.nio.file.Paths
5
5
import java .{util => ju }
6
6
7
7
import scala .jdk .CollectionConverters ._
8
- import scala .util .Try
8
+ import scala .util .control . NonFatal
9
9
10
10
import com .sourcegraph .scip_java .BuildInfo
11
11
import org .gradle .api .DefaultTask
@@ -405,35 +405,42 @@ class WriteDependencies extends DefaultTask {
405
405
// List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project.
406
406
// The code below is roughly equivalent to the following with Groovy:
407
407
// 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()
437
444
}
438
445
439
446
project
0 commit comments