Skip to content

Commit

Permalink
fixes #530: Disable logback-core in Java 8 and show warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Oct 11, 2024
1 parent 7354799 commit 18900aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 1 addition & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ lazy val sbtSonatype =
libraryDependencies ++= Seq(
"org.sonatype.spice.zapper" % "spice-zapper" % versions.sonatypeZapperClient,
"org.wvlet.airframe" %% "airframe-http" % versions.airframe
// Logback 1.5.8 dropposed Java 8 support
exclude ("ch.qos.logback", "logback-core")
// A workaround for sbt-pgp, which still depends on scala-parser-combinator 1.x
// A workaround for sbt-pgp, which still depends on scala-parser-combinator 1.x
excludeAll (ExclusionRule("org.scala-lang.modules", "scala-parser-combinators_2.12")),
"org.wvlet.airframe" %% "airspec" % versions.airframe % Test,
"com.lumidion" %% "sonatype-central-client-sttp-core" % versions.sonatypeClient,
Expand Down
20 changes: 17 additions & 3 deletions src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class SonatypeClient(

@nowarn("msg=URLConnectionClientBackend")
private[sonatype] val clientConfig = {
Http.client
var config = Http.client
.withName("sonatype-client")
// Put the log file under target/sbt-sonatype directory
.withLoggerConfig(_.withLogFileName("target/sbt-sonatype/sonatype_client_logs.json"))
// TODO Enable client-side logging while avoiding Java8 compatibility of log-rotator (logback-core 1.5.x)
.noLogging
// Disables the circuit breaker, because Sonatype can be down for a long time https://github.com/xerial/sbt-sonatype/issues/363
.noCircuitBreaker
// Use URLConnectionClient for JDK8 compatibility. Remove this line when using JDK11 or later
Expand All @@ -62,6 +62,20 @@ class SonatypeClient(
.withAccept(MediaType.ApplicationJson)
.withHeader(HttpHeader.Authorization, s"Basic ${base64Credentials}")
}

val javaVersion = sys.props.getOrElse("java.version", "unknown")
if (javaVersion.startsWith("1.")) {
warn(
s"Disabled http client logging as Java version ${javaVersion} is no longer supported. Please use Java 17 or later."
)
config = config.noLogging
} else {
// Put the log file under target/sbt-sonatype directory
config = config.withLoggerConfig {
_.withLogFileName("target/sbt-sonatype/sonatype_client_logs.json")
}
}
config
}

private[sonatype] val httpClient = clientConfig.newSyncClient(repoUri.toString)
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/xerial/sbt/sonatype/SonatypeClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class SonatypeClientTest extends AirSpec {
profile shouldBe unpacked
}

test("build client") {
val client = new SonatypeClient("https://oss.sonatype.org/service/local/", Seq.empty, "")
client.httpClient
}

// test("create client") {
// val client = new SonatypeClient("https://httpbin.org/", Seq.empty, "")
// client.httpClient.readAs[Json](Http.GET("/status/500"))
Expand Down

0 comments on commit 18900aa

Please sign in to comment.