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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
# NOTE(olafurpg) Windows is not enabled because it times out due to reasons I don't understand.
# os: [windows-latest, ubuntu-latest]
os: [ubuntu-latest]
java: [8, 11, 17, 21]
java: [11, 17, 21]
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [8, 11, 17, 21]
java: [11, 17, 21]
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 8
java-version: 11

- uses: coursier/setup-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 11
cache: 'sbt'
- uses: sbt/setup-sbt@v1
- uses: docker/setup-buildx-action@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 8
java-version: 11
cache: 'sbt'
- uses: sbt/setup-sbt@v1
- name: Publish ${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion bin/docker-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rm gradle.zip
mv /opt/gradle/*/* /opt/gradle

# pre-install JDK for all major versions
for JVM_VERSION in 21 17 11 8
for JVM_VERSION in 21 17 11
do
coursier java --jvm $JVM_VERSION --jvm-index https://github.com/coursier/jvm-index/blob/master/index.json -- -version
done
14 changes: 1 addition & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ lazy val agent = project
.settings(
fatjarPackageSettings,
javaOnlySettings,
javaToolchainVersion := "8",
moduleName := "semanticdb-agent",
libraryDependencies ++=
List(
Expand All @@ -110,8 +109,7 @@ lazy val gradlePlugin = project
scalaVersion := V.scala213,
buildInfoPackage := "com.sourcegraph.scip_java",
publish / skip := true,
javaToolchainVersion := "8",
scalacOptions ++= Seq("-target:8", "-release", "8"),
scalacOptions ++= Seq("-target:11", "-release", "11"),
libraryDependencies ++=
List(
"dev.gradleplugins" % "gradle-api" % V.gradle % Provided,
Expand Down Expand Up @@ -150,7 +148,6 @@ lazy val javacPlugin = project
fatjarPackageSettings,
javaOnlySettings,
moduleName := "semanticdb-javac",
javaToolchainVersion := "8",
javacOptions += "-g",
(assembly / assemblyShadeRules) :=
Seq(
Expand Down Expand Up @@ -186,7 +183,6 @@ lazy val scipProto = project
.in(file("scip-java-proto"))
.settings(
moduleName := "scip-java-proto",
javaToolchainVersion := "8",
javaOnlySettings,
libraryDependencies +=
"com.google.protobuf" % "protobuf-java-util" % V.protobuf,
Expand All @@ -200,7 +196,6 @@ lazy val scip = project
.settings(
publishMavenStyle := true,
moduleName := "scip-semanticdb",
javaToolchainVersion := "8",
javaOnlySettings,
(Compile / PB.targets) :=
Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value),
Expand All @@ -212,7 +207,6 @@ lazy val mavenPlugin = project
.in(file("maven-plugin"))
.settings(
moduleName := "maven-plugin",
javaToolchainVersion := "8",
javaOnlySettings,
libraryDependencies ++=
Seq(
Expand Down Expand Up @@ -388,12 +382,6 @@ lazy val minimized = project
.dependsOn(agent, javacPlugin)
.disablePlugins(JavaFormatterPlugin)

lazy val minimized8 = project
.in(file("tests/minimized/.j8"))
.settings(minimizedSettings, javaToolchainVersion := "8", javaOnlySettings)
.dependsOn(agent, javacPlugin)
.disablePlugins(JavaFormatterPlugin)

def javacModuleOptions = List(
"-J--add-exports",
"-Jjdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
Expand Down
4 changes: 1 addition & 3 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,4 @@ write tests because:
[snapshot testing](https://jestjs.io/docs/en/snapshot-testing), which is a
testing technique that's heavily used in this codebase.
- Multiline literal strings in Scala make it easy to write unit tests for source
code (which is always multiline). Modern versions of Java support multiline
string literals, but they're not supported in Java 8, which is supported by
scip-java.
code (which is always multiline).
8 changes: 3 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ finished indexing the project.

> The `sourcegraph/scip-java` Docker image is made available for convenience at
> the cost of performance. The `sourcegraph/scip-java` image is a big download
> because it includes pre-installed versions of Java 8, Java 11, and Java 17.
> because it includes pre-installed versions of Java 11, Java 17, and Java 21.
> The `sourcegraph/scip-java` image has slow performance because it needs to
> download all external dependencies of your codebase on every invocation.
>
Expand All @@ -46,9 +46,6 @@ Java 17 is the default Java version in the `sourcegraph/scip-java` Docker image.
Use the following commands to use a different JVM version:

```sh
# Java 8
docker run -v $(pwd):/sources --env JVM_VERSION=8 sourcegraph/scip-java:latest scip-java index

# Java 11
docker run -v $(pwd):/sources --env JVM_VERSION=11 sourcegraph/scip-java:latest scip-java index

Expand Down Expand Up @@ -227,9 +224,10 @@ of Java versions.
| Java version | Support | Tracking issue |
| ------------ | ---------------------------- | -------------- |
| Java 7 | ❌ | |
| Java 8 | | |
| Java 8 | | |
| Java 11 | ✅ | |
| Java 17 | ✅, requires `--add-exports` | |
| Java 21 | ✅, requires `--add-exports` | |

For Java 17 and newer versions, the following JVM options are required:

Expand Down
4 changes: 2 additions & 2 deletions docs/manual-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ targetroot directory.

```
❯ find $TARGETROOT -type f
build/semanticdb-targetroot/META-INF/semanticdb/j8/src/test/java/example/ExampleTest.java.semanticdb
build/semanticdb-targetroot/META-INF/semanticdb/j8/src/main/java/example/Example.java.semanticdb
build/semanticdb-targetroot/META-INF/semanticdb/j11/src/test/java/example/ExampleTest.java.semanticdb
build/semanticdb-targetroot/META-INF/semanticdb/j11/src/main/java/example/Example.java.semanticdb
...
```

Expand Down
4 changes: 2 additions & 2 deletions examples/maven-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<revision>1.0.0-SNAPSHOT</revision>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<goalPrefix>sourcegraph</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<requiredJavaVersion>1.8</requiredJavaVersion>
<requiredJavaVersion>11</requiredJavaVersion>
<requiredMavenVersion>3.9.5</requiredMavenVersion>
<mojos>
<mojo>
Expand Down
56 changes: 4 additions & 52 deletions project/JavaToolchainPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,16 @@ object JavaToolchainPlugin extends AutoPlugin {
import autoImport._

override lazy val projectSettings: Seq[Def.Setting[_]] = List(
javacOptions ++=
List(
"-target",
"1.8",
"-source",
"1.8",
"-bootclasspath",
java8Bootclasspath()
),
(doc / javacOptions) --= List("-target", "1.8"),
(doc / javacOptions) --= bootclasspathSettings(javaToolchainVersion.value),
javacOptions ++= List("--release", "11"),
(doc / javacOptions) --= List("--release", "11"),
(doc / javacOptions) --= List("-g"),
javacOptions ++= bootclasspathSettings(javaToolchainVersion.value),
javaOptions ++= bootclasspathSettings(javaToolchainVersion.value),
fork := true,
javaToolchainVersion := "11",
javaToolchainJvmIndex := None,
javaHome :=
Some(getJavaHome(javaToolchainVersion.value, javaToolchainJvmIndex.value))
)

/**
* For Java 8, we need to manually add the Java compiler to the boot
* classpath.
*
* Newer Java versions include the compiler by default.
*/
private def bootclasspathSettings(version: String): List[String] = {
val home = getJavaHome(version)
val toolsJar: File = home / "lib" / "tools.jar"
// The tools.jar file includes the bytecode for the Java compiler in the com.sun.source package.
// The Java compiler is available by default in Java 9+, so we only need to add tools.jar to the
// bootclasspath for Java 8.
if (version == "8" && toolsJar.isFile) {
List(s"-Xbootclasspath/p:$toolsJar")
} else {
List()
}
}

private def java8Bootclasspath(): String = {
(getJavaHome("8") / "jre" / "lib" / "rt.jar").toString
}

private val javaHomeCache: util.Map[String, File] = Collections
.synchronizedMap(new util.HashMap[String, File]())
private def getJavaHome(
Expand All @@ -85,28 +51,14 @@ object JavaToolchainPlugin extends AutoPlugin {
.toList
.flatMap(index => "--jvm-index" :: index :: Nil)
val arguments =
List(
"java",
"-jar",
coursier.toString,
"java-home",
"--jvm",
jvmName(v)
) ++ index
List("java", "-jar", coursier.toString, "java-home", "--jvm", v) ++
index

new File(Process(arguments).!!.trim)
}
)
}

private def jvmName(version: String) =
version match {
case "8" if isAppleM1 =>
"zulu:8" // the only Java 8 distribution available for Apple M1 is Zulu
case _ =>
version
}

private def isAppleM1 =
scala.util.Properties.isMac && sys.props("os.arch") == "aarch64"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,13 @@ case class GradleJavaCompiler(languageVersion: String, javacPath: Path) {

// For compile{Test}Kotlin when using jvm toolchains, we need to have access
// to JDK internals found in <java-installation-path>/lib in JDK 9+,
// as well as <java-installation-path>/jre/lib in JDK <=8, else we get
// "no class roots are found in the JDK path" from the compile{Test}Kotlin tasks.
// else we get "no class roots are found in the JDK path" from the
// compile{Test}Kotlin tasks.
// https://docs.oracle.com/en/java/javase/12/migrate/index.html#JSMIG-GUID-A78CC891-701D-4549-AA4E-B8DD90228B4B
val javaHome = javacPath.getParent.getParent
val libPath = dir.resolve("lib")
val javacLibPath = javaHome.resolve("lib")
copyFiles(javacLibPath, libPath)

if (languageVersion == "8") {
val jreLibPath = dir.resolve("jre").resolve("lib")
Files.createDirectories(jreLibPath.getParent)
val javacJreLibPath = javaHome.resolve("jre").resolve("lib")

copyFiles(javacJreLibPath, jreLibPath)
}
}
}
object GradleJavaCompiler {
Expand All @@ -150,9 +142,9 @@ object GradleJavaCompiler {
/**
* Parses a single space-separated line into a GradleJavaCompiler instance.
*
* Example input: "8 /javacLibPath/javac"
* Example input: "11 /javacLibPath/javac"
*
* Example output: `Some(GradleJavaCompiler("8", * /javacLibPath/javac))`
* Example output: `Some(GradleJavaCompiler("11", * /javacLibPath/javac))`
*/
def fromLine(line: String): Option[GradleJavaCompiler] =
line.split(' ') match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import os.SubprocessException
* {{{
* {
* "dependencies": ["junit:junit:4.13.1"],
* "jvm": "8"
* "jvm": "11"
* }
* }}}
*/
Expand Down Expand Up @@ -565,11 +565,7 @@ class ScipBuildTool(index: IndexCommand) extends BuildTool("SCIP", index) {
})
val javac = javacPath(config, tmp)
index.app.reporter.info(s"$$ $javac @$argsfile")
val javacModuleOptions: Seq[String] =
if (config.jvm != "8")
BuildInfo.javacModuleOptions
else
Nil
val javacModuleOptions: Seq[String] = BuildInfo.javacModuleOptions

val jvmOptions = config.jvmOptions.map("-J" + _)

Expand Down Expand Up @@ -671,16 +667,8 @@ class ScipBuildTool(index: IndexCommand) extends BuildTool("SCIP", index) {

}

private def jvmArchitecture(jvm: String): String =
if (
// Hack only for local development on ARM64 Mac OS X
// won't affect any other system
scala.util.Properties.isMac && sys.props("os.arch") == "aarch64" &&
(jvm.startsWith("8") || jvm.startsWith("1.8"))
)
"amd64"
else
JvmIndex.defaultArchitecture()
private def jvmArchitecture(jvm: String): String = JvmIndex
.defaultArchitecture()

def defaultCoursierJVMArchitecture: String =
sys.props("os.arch") match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final case class IndexDependencyCommand(
}

private def inferJvmVersion(jar: Path): Option[Int] = {
Option(JavaVersion.classfileJvmVersion(jar).orElse(8)).map(
Option(JavaVersion.classfileJvmVersion(jar).orElse(11)).map(
JavaVersion.roundToNearestStableRelease(_)
)
}
Expand Down
Loading
Loading