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
10 changes: 7 additions & 3 deletions docs/manual-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in

- `javacopts.txt`: line-separated list of Java compiler options that got passed
to the compiler. For example,

```sh
$ cat $TARGETROOT/javacopts.txt
-Xlint
Expand All @@ -172,22 +173,25 @@ one of the following files in the SemanticDB _targetroot_ directory (the path in
/path/to/classes/directory
/path/to/com/example/Main.java
```

The `javacopts.txt` file format can only be used if the jars on the dependency
classpath have sibling `.pom` files. In some build tools like Gradle, the POM
files are not siblings to the jars on the classpath so the `javacopts.txt`
format cannot be used.

- `dependencies.txt`: a tab-separated values file where the columns are: group
ID, artifact ID, version and jar path. For example,

```sh
$ cat $TARGETROOT/dependencies.txt
junit junit 4.13.2 /path/to/junit.jar
org.hamcrest hamcrest-core 1.3 /path/to/hamcrest-core.jar
```

The `dependencies.txt` format is used by scip-java to map symbols such as
`org.junit.Assert` to Maven co-ordinates like `junit:junit:4.13.2`. As long as
`org.junit.Assert` to Maven coordinates like `junit:junit:4.13.2`. As long as
your Sourcegraph instance has another repository that defines that symbol, the
cross-repository navigation should succeed. Only jar files are supported at
the moment, classes directories are ignored.
cross-repository navigation should succeed.

Cross-repository navigation is a feature that allows "goto definition" and "find
references" to show results from multiple repositories.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.nio.file.Paths
import java.{util => ju}

import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal
import scala.util._

import com.sourcegraph.scip_java.BuildInfo
import org.gradle.api.DefaultTask
Expand Down Expand Up @@ -416,42 +416,56 @@ class WriteDependencies extends DefaultTask {
// List the project itself as a dependency so that we can assign project name/version to symbols that are defined in this project.
// The code below is roughly equivalent to the following with Groovy:
// deps += "$publication.groupId $publication.artifactId $publication.version $sourceSets.main.output.classesDirectory"
try {
for {
classesDirectory <- project
.getExtensions()
.getByType(classOf[SourceSetContainer])
.getByName("main")
.getOutput()
.getClassesDirs()
.getFiles()
.asScala
.toList
.map(_.getAbsolutePath())
.sorted
.take(1)
publication <-

Try(
project
.getExtensions()
.findByType(classOf[PublishingExtension])
.getPublications()
.withType(classOf[MavenPublication])
.asScala
) match {
case Failure(exception) =>
System
.err
.println(
s"""
|Failed to extract Maven publication from the project `${project
.getName()}`.
|This will not prevent a SCIP index from being created, but the symbols
|extracted from this project won't be available for cross-repository navigation,
|as this project doesn't define any Maven coordinates by which it can be referred back to.
|See here for more details: https://sourcegraph.github.io/scip-java/docs/manual-configuration.html#step-5-optional-enable-cross-repository-navigation
|Here's the raw error message:
| "${exception.getMessage()}"
|Continuing without cross-repository support.
""".stripMargin.trim()
)

case Success(publications) =>
publications.foreach { publication =>
project
.getExtensions()
.findByType(classOf[PublishingExtension])
.getPublications()
.withType(classOf[MavenPublication])
.getByType(classOf[SourceSetContainer])
.getByName("main")
.getOutput()
.getClassesDirs()
.getFiles()
.asScala
} {
deps +=
List(
publication.getGroupId(),
publication.getArtifactId(),
publication.getVersion(),
classesDirectory
).mkString("\t")
}
} catch {
case NonFatal(ex) =>
println(
s"Failed to extract publication from project ${project.getName()}"
)
ex.printStackTrace()
.toList
.map(_.getAbsolutePath())
.sorted
.take(1)
.foreach { classesDirectory =>
deps +=
List(
publication.getGroupId(),
publication.getArtifactId(),
publication.getVersion(),
classesDirectory
).mkString("\t")
}
}
}

project
Expand Down