需要从我在sbt插件中使用的插件中提供SettingKey

时间:2019-02-07 06:15:37

标签: scala sbt

我正在使用s3 resolver plugin,并且想在我的AutoPlugin中覆盖它。

我尝试将值添加到projectSettingsglobalSettings

错误

not found: value s3CredentialsProvider
[error]     s3CredentialsProvider := s3CredentialsProviderChain

代码

lazy val s3CredentialsProviderChain = {bucket: String =>
    new AWSCredentialsProviderChain(
      new EnvironmentVariableCredentialsProvider(),
      CustomProvider.create(bucket)
    )
  }

 override lazy val projectSettings = Seq(
publishTo := {
   if (Keys.isSnapshot.value) {
      Some("my-snapshots" at "s3://rest-of-stuff")
    } else {
      Some("my-releases" at "s3://rest-of-stuff")
    }
  },
  s3CredentialsProvider := s3CredentialsProviderChain
)

我正在使用的插件代码未定义其自己的任何自定义设置,因此不具有autoImport

更新

我无法解析fm.sbt.S3ResolverPlugin中的MyPlugin,并且代码无法编译。

我尝试将其添加到enablePlugins的build.sbt的MyPlugin上,并尝试将其添加到dependencies上,如下所示:

libraryDependencies ++= Seq(
  "com.amazonaws" % "aws-java-sdk-sts" % amazonSDKVersion,
  "com.frugalmechanic" % "fm-sbt-s3-resolver" % "0.17.0"
)

我从sbt收到一个错误,该错误已在下面询问:

sbt fails to resolve a plugin as dependency

1 个答案:

答案 0 :(得分:1)

如果您在project目录中创建自动插件。您需要将此添加到plugins.sbt

addSbtPlugin("com.frugalmechanic" % "fm-sbt-s3-resolver" % "0.16.0")

如果您创建一个独立的插件,请将其添加到插件的build.sbt

sbtPlugin := true
addSbtPlugin("com.frugalmechanic" % "fm-sbt-s3-resolver" % "0.16.0")

autoImport在为scala编译的sbt文件(例如插件)中不起作用。您已经指定了import的语句,就像在简单的scala程序中一样。像这样

import fm.sbt.S3ResolverPlugin
import sbt._

object TestPlugin extends AutoPlugin {

  override def requires = S3ResolverPlugin

  override def trigger = allRequirements

  override def projectSettings: Seq[Def.Setting[_]] = Seq(
    S3ResolverPlugin.autoImport.s3CredentialsProvider := ???
  )
}

请注意,要启用TestPlugin,您必须在enablePlugins(S3ResolverPlugin)中呼叫build.sbt