Skip to content

Commit

Permalink
fix: Use hidden project configuration for dependency management
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnnei committed Nov 11, 2024
1 parent 0766a8c commit 235a9c4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ runner.dialect = scala212
maxColumn = 120
align.preset = none
rewrite.trailingCommas.style = always

Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -149,7 +150,7 @@ object ScapegoatSbtPlugin extends AutoPlugin {
case _ => "1.4.17"
}
}
crossVersion(GroupId %% ArtifactId % selectedScapegoatVersion) % Scapegoat
crossVersion(GroupId %% ArtifactId % selectedScapegoatVersion) % ScapegoatDeps
},
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/artifacts/report-and-inclusion/build.sbt
Original file line number Diff line number Diff line change
@@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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

}
6 changes: 5 additions & 1 deletion src/sbt-test/artifacts/report-and-inclusion/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 235a9c4

Please sign in to comment.