Skip to content

Commit

Permalink
Allow producing JDK8 bytecode on newer JDK's
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Feb 9, 2024
1 parent e870ee1 commit 244571f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
5 changes: 5 additions & 0 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ gradlePlugin {
}
}

tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

publishing {
publications.withType(MavenPublication) {
pom {
Expand Down
4 changes: 4 additions & 0 deletions maven-plugin/src/main/maven/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<groupId>org.apache.pekko</groupId>
<artifactId>pekko-grpc-maven-plugin</artifactId>
<goalPrefix>pekko-grpc</goalPrefix>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<mojos>
<mojo>
<goal>generate</goal>
Expand Down
45 changes: 26 additions & 19 deletions project/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,16 @@ object Common extends AutoPlugin {

override lazy val projectSettings = Seq(
projectInfoVersion := (if (isSnapshot.value) "snapshot" else version.value),
scalacOptions ++= (if (!isScala3.value)
Seq(
"-unchecked",
"-deprecation",
"-language:_",
"-Xfatal-warnings",
"-Ywarn-unused",
"-encoding",
"UTF-8")
else
Seq(
"-unchecked",
"-deprecation",
"-language:_",
"-Xfatal-warnings",
"-Wunused:imports",
"-encoding",
"UTF-8")),
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-language:_",
"-Xfatal-warnings",
"-encoding",
"UTF-8") ++ (if (!isScala3.value)
Seq("-Ywarn-unused")
else
Seq("-Wunused:imports")),
Compile / scalacOptions ++= (if (!isScala3.value)
Seq(
// Generated code for methods/fields marked 'deprecated'
Expand All @@ -79,7 +71,13 @@ object Common extends AutoPlugin {
"-Wconf:msg=unused import:silent",
"-Wconf:cat=feature:silent")),
Compile / console / scalacOptions ~= (_.filterNot(consoleDisabledOptions.contains)),
javacOptions ++= List("-Xlint:unchecked", "-Xlint:deprecation"),
// restrict to 'compile' scope because otherwise it is also passed to
// javadoc and -target is not valid there.
// https://github.com/sbt/sbt/issues/1785
Compile / compile / javacOptions ++=
onlyAfterJdk8("--release", "8"),
Compile / compile / scalacOptions ++=
onlyAfterJdk8("-release", "8"),
Compile / doc / scalacOptions := scalacOptions.value ++ Seq(
"-doc-title",
"Apache Pekko gRPC",
Expand Down Expand Up @@ -110,6 +108,15 @@ object Common extends AutoPlugin {
crossScalaVersions := Seq(scala212, scala213, scala3),
mimaReportSignatureProblems := true)

val specificationVersion: String = sys.props("java.specification.version")

def isJdk8: Boolean =
VersionNumber(specificationVersion).matchesSemVer(SemanticSelector(s"=1.8"))

def onlyOnJdk8[T](values: T*): Seq[T] = if (isJdk8) values else Seq.empty[T]

def onlyAfterJdk8[T](values: T*): Seq[T] = if (isJdk8) Seq.empty[T] else values

override lazy val buildSettings = Seq(
dynverSonatypeSnapshots := true)
}

0 comments on commit 244571f

Please sign in to comment.