在我的project/plugins.sbt 文件中,我添加了一个插件,该插件会引入存在漏洞的依赖项。 该修复是另一个具有完全不同的组 ID 的工件。 如何用修复程序替换第一个依赖项?
所以,如果在plugins.sbt中,我有类似的东西
addSbtPlugin("com.fake.something", "myplugin", "0.1.2")
并且该插件具有依赖性
org.some.framework:framework-core:1.2.3
我想用另一个具有完全不同组 ID 的依赖项替换该依赖项:
com.fixed.framework:framework-core:4.5.5
有没有办法配置plugins.sbt(或build.sbt),以便在构建时将 org.some.framework:framework-core:1.2.3 替换为 com.fixed.framework:framework-core:4.5.6 ? (我已经考虑过使用该插件的新版本 - 不幸的是,新版本具有相同的漏洞)
感谢您阅读我的问题?
第一个选项可能是:
第二个选项:
在插件存储库中创建一个 PR,并详细说明您这样做的原因
第三个选项(不确定这个是否有效,因为我还没有尝试过)
addSbtPlugin(
("com.fake.something" % "myplugin" % "0.1.2")
.exclude("org.some.framework", "framework-core")
)
libraryDependencies += {
val sbtV = (pluginCrossBuild / sbtBinaryVersion).value
val scalaV = (update / scalaBinaryVersion).value
sbtPluginExtra("com.fixed.framework" % "framework-core" % "4.5.5", sbtV, scalaV)
}
如果你看一下 addSbtPlugin 的三个实现,该方法返回一个
Setting[Seq[ModuleID]]
/** * Adds `dependency` as an sbt plugin for the specific sbt version `sbtVersion` and Scala version `scalaVersion`. * Typically, use the default values for these versions instead of specifying them explicitly. */ def addSbtPlugin( dependency: ModuleID, sbtVersion: String, scalaVersion: String ): Setting[Seq[ModuleID]] = libraryDependencies += sbtPluginExtra(dependency, sbtVersion, scalaVersion) /** * Adds `dependency` as an sbt plugin for the specific sbt version `sbtVersion`. * Typically, use the default value for this version instead of specifying it explicitly. */ def addSbtPlugin(dependency: ModuleID, sbtVersion: String): Setting[Seq[ModuleID]] = libraryDependencies += { val scalaV = (update / scalaBinaryVersion).value sbtPluginExtra(dependency, sbtVersion, scalaV) } /** * Adds `dependency` as an sbt plugin for the sbt and Scala versions configured by * `sbtBinaryVersion` and `scalaBinaryVersion` scoped to `update`. */ def addSbtPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] = libraryDependencies += { val sbtV = (pluginCrossBuild / sbtBinaryVersion).value val scalaV = (update / scalaBinaryVersion).value sbtPluginExtra(dependency, sbtV, scalaV) }
所有这些,请致电 sbtPluginExtra
def sbtPluginExtra(m: ModuleID, sbtV: String, scalaV: String): ModuleID = partialVersion(sbtV) match { case Some((0, _)) | Some((1, _)) => m.extra( PomExtraDependencyAttributes.SbtVersionKey -> sbtV, PomExtraDependencyAttributes.ScalaVersionKey -> scalaV ) .withCrossVersion(Disabled()) case Some(_) => // this produces a normal suffix like _sjs1_2.13 val prefix = s"sbt${binarySbtVersion(sbtV)}_" m.cross(CrossVersion.binaryWith(prefix, "")) case None => sys.error(s"unknown sbt version $sbtV") }
sbtPluginExtra
返回一个 ModuleID ,其中包含方法 exclude(org, name)
/** Excludes the dependency with organization `org` and `name` from being introduced by this dependency during resolution. */ def exclude(org: String, name: String): ModuleID = excludeAll(ExclusionRule().withOrganization(org).withName(name))
根据开头共享的代码,我排除了您所说的组织和名称,然后手动添加了您要使用您正在使用的 sbt 和 scala 版本添加的依赖项