Skip to content

Commit

Permalink
Merge pull request #584 from fthomas/topic/ignore-deps-from-plugins
Browse files Browse the repository at this point in the history
Ignore dependencies introduced by plugins
  • Loading branch information
fthomas authored Jun 17, 2019
2 parents 3774160 + 88c1371 commit 3b16304
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions modules/core/src/main/resources/StewardPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package sbt.scalasteward
package org.scalasteward.core

import sbt.Keys._
import sbt._
Expand All @@ -24,19 +24,21 @@ object StewardPlugin extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements

object autoImport {
val libraryDependenciesAsJson = settingKey[String]("")
val libraryDependenciesAsJson = taskKey[String]("")
}

import autoImport._

override def projectSettings: Seq[Def.Setting[_]] = Seq(
libraryDependenciesAsJson := {
val deps = libraryDependencies.value.map {
val sourcePositions = dependencyPositions.value
val deps = libraryDependencies.value.filter(isDefinedInBuildFiles(_, sourcePositions)).map {
moduleId =>
val cross =
CrossVersion(moduleId.crossVersion, scalaVersion.value, scalaBinaryVersion.value)

val artifactIdCross =
CrossVersion.applyCross(moduleId.name, cross)
cross.fold(moduleId.name)(_(moduleId.name))

val entries: List[(String, String)] = List(
"groupId" -> moduleId.organization,
Expand All @@ -52,4 +54,16 @@ object StewardPlugin extends AutoPlugin {
deps.mkString("[ ", ", ", " ]")
}
)

// Inspired by https://github.com/rtimush/sbt-updates/issues/42
private def isDefinedInBuildFiles(
moduleId: ModuleID,
sourcePositions: Map[ModuleID, SourcePosition]
): Boolean =
sourcePositions.get(moduleId) match {
case Some(fp: FilePosition) if fp.path.startsWith("(sbt.Classpaths") => true
case Some(fp: FilePosition) if fp.path.startsWith("(") => false
case Some(fp: FilePosition) if fp.path.startsWith("Defaults.scala") => false
case _ => true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.scalasteward.core.sbt

object command {
val dependencyUpdates = "dependencyUpdates"
val libraryDependenciesAsJson = "libraryDependenciesAsJson"
val libraryDependenciesAsJson = "show libraryDependenciesAsJson"
val reloadPlugins = "reload plugins"
val scalafix = "scalafix"
val scalafixEnable = "scalafixEnable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ package object sbt {
"scala-steward.sbt",
"""addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.5")
|addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.0")
""".stripMargin
|""".stripMargin.trim
)

val stewardPlugin: FileData = {
Expand Down

0 comments on commit 3b16304

Please sign in to comment.