From 18900aac03240e024bc33034cbbb225b9d24b284 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Fri, 11 Oct 2024 15:52:01 -0700 Subject: [PATCH 1/3] fixes #530: Disable logback-core in Java 8 and show warning messages --- build.sbt | 4 +--- .../xerial/sbt/sonatype/SonatypeClient.scala | 20 ++++++++++++++++--- .../sbt/sonatype/SonatypeClientTest.scala | 5 +++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index 6cc89545..2a4b7912 100755 --- a/build.sbt +++ b/build.sbt @@ -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, diff --git a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala index 80ccfa0b..bba4e42e 100644 --- a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala +++ b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala @@ -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 @@ -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) diff --git a/src/test/scala/xerial/sbt/sonatype/SonatypeClientTest.scala b/src/test/scala/xerial/sbt/sonatype/SonatypeClientTest.scala index 4a2d56a4..274a1b74 100644 --- a/src/test/scala/xerial/sbt/sonatype/SonatypeClientTest.scala +++ b/src/test/scala/xerial/sbt/sonatype/SonatypeClientTest.scala @@ -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")) From 3a72c962f09b8ebca2c95ccdfc769a8c9130fdf7 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Fri, 11 Oct 2024 15:53:06 -0700 Subject: [PATCH 2/3] Fix --- src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala index bba4e42e..fdd026e2 100644 --- a/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala +++ b/src/main/scala/xerial/sbt/sonatype/SonatypeClient.scala @@ -41,8 +41,6 @@ class SonatypeClient( private[sonatype] val clientConfig = { var config = Http.client .withName("sonatype-client") - // 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 From c7b1f0102db355606669c1492bbff05187a537f7 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Fri, 11 Oct 2024 15:55:09 -0700 Subject: [PATCH 3/3] update sbt script --- sbt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sbt b/sbt index f63a9ee5..7554340a 100755 --- a/sbt +++ b/sbt @@ -34,11 +34,11 @@ set -o pipefail -declare -r sbt_release_version="1.9.7" -declare -r sbt_unreleased_version="1.9.7" +declare -r sbt_release_version="1.10.2" +declare -r sbt_unreleased_version="1.10.2" -declare -r latest_213="2.13.12" -declare -r latest_212="2.12.18" +declare -r latest_213="2.13.15" +declare -r latest_212="2.12.20" declare -r latest_211="2.11.12" declare -r latest_210="2.10.7" declare -r latest_29="2.9.3"