From 235a9c48049b3aad3895a44d9ffbb35ff9fcd052 Mon Sep 17 00:00:00 2001 From: Johnnei Date: Thu, 10 Oct 2024 21:28:27 +0700 Subject: [PATCH] fix: Use hidden project configuration for dependency management --- .scalafmt.conf | 1 - .../com/sksamuel/scapegoat/sbt/ScapegoatSbtPlugin.scala | 7 ++++--- src/sbt-test/artifacts/report-and-inclusion/build.sbt | 3 ++- .../report-and-inclusion/src/main/scala/Boot.scala | 6 +++++- src/sbt-test/artifacts/report-and-inclusion/test | 6 +++++- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index 1250c64..078add3 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -3,4 +3,3 @@ runner.dialect = scala212 maxColumn = 120 align.preset = none rewrite.trailingCommas.style = always - diff --git a/src/main/scala/com/sksamuel/scapegoat/sbt/ScapegoatSbtPlugin.scala b/src/main/scala/com/sksamuel/scapegoat/sbt/ScapegoatSbtPlugin.scala index 77d6ff9..2cac2e5 100644 --- a/src/main/scala/com/sksamuel/scapegoat/sbt/ScapegoatSbtPlugin.scala +++ b/src/main/scala/com/sksamuel/scapegoat/sbt/ScapegoatSbtPlugin.scala @@ -12,6 +12,7 @@ object ScapegoatSbtPlugin extends AutoPlugin { object autoImport { val Scapegoat = config("scapegoat") extend Compile + val ScapegoatDeps = (config("scapegoat-dep") extend Compile).hide lazy val scapegoat = taskKey[Unit]("Run scapegoat quality checks") lazy val scapegoatCleanTask = taskKey[Unit]("Conditionally clean the scapegoat output directories") @@ -41,7 +42,7 @@ object ScapegoatSbtPlugin extends AutoPlugin { } } - override def projectConfigurations: Seq[Configuration] = Seq(Scapegoat) + override def projectConfigurations: Seq[Configuration] = Seq(ScapegoatDeps) override def trigger = allRequirements @@ -69,7 +70,7 @@ object ScapegoatSbtPlugin extends AutoPlugin { unmanagedClasspath := (Compile / unmanagedClasspath).value, scalacOptions := { // find all deps for the compile scope - val scapegoatDependencies = (Scapegoat / update).value matching configurationFilter(Scapegoat.name) + val scapegoatDependencies = (ScapegoatDeps / update).value matching configurationFilter(ScapegoatDeps.name) // ensure we have the scapegoat dependency on the classpath and if so add it as a scalac plugin scapegoatDependencies.find(_.getAbsolutePath.contains(ArtifactId)) match { case None => @@ -149,7 +150,7 @@ object ScapegoatSbtPlugin extends AutoPlugin { case _ => "1.4.17" } } - crossVersion(GroupId %% ArtifactId % selectedScapegoatVersion) % Scapegoat + crossVersion(GroupId %% ArtifactId % selectedScapegoatVersion) % ScapegoatDeps }, ) } diff --git a/src/sbt-test/artifacts/report-and-inclusion/build.sbt b/src/sbt-test/artifacts/report-and-inclusion/build.sbt index 2c1bf09..adcf8cf 100644 --- a/src/sbt-test/artifacts/report-and-inclusion/build.sbt +++ b/src/sbt-test/artifacts/report-and-inclusion/build.sbt @@ -1,7 +1,8 @@ lazy val root = (project in file(".")) .settings( name := "test-scapegoat-inclusion-in-pom", - ThisBuild / scalaVersion := "2.13.10", + libraryDependencies += "org.typelevel" %% "cats-core" % "2.12.0", + ThisBuild / scalaVersion := "2.13.14", TaskKey[Unit]("check") := { val pom = scala.xml.XML.loadFile(makePom.value) (pom \\ "dependencies").map(_ \ "dependency").find(dependency => diff --git a/src/sbt-test/artifacts/report-and-inclusion/src/main/scala/Boot.scala b/src/sbt-test/artifacts/report-and-inclusion/src/main/scala/Boot.scala index f484912..00b6cc5 100644 --- a/src/sbt-test/artifacts/report-and-inclusion/src/main/scala/Boot.scala +++ b/src/sbt-test/artifacts/report-and-inclusion/src/main/scala/Boot.scala @@ -1,6 +1,10 @@ +import cats.syntax.all._ + object Boot extends App { - println("Hello World") + // Depend on Cats to verify that dependencies are maintained + println("Hello " |+| " World") + val ohno = Option(42).get } diff --git a/src/sbt-test/artifacts/report-and-inclusion/test b/src/sbt-test/artifacts/report-and-inclusion/test index 5da5ccd..15c241c 100644 --- a/src/sbt-test/artifacts/report-and-inclusion/test +++ b/src/sbt-test/artifacts/report-and-inclusion/test @@ -1,5 +1,9 @@ -> compile +> clean -> scapegoat $ exists target/scala-2.13/scapegoat-report/scapegoat.xml +-$ exists target/scala-2.13/classes/Boot.class +> clean +> compile > makePom +-$ exists target/scala-2.13/scapegoat-report/scapegoat.xml > check