Need to provide a SettingKey from a plugin I use i

2019-08-20 05:57发布

问题:

I am using the s3 resolver plugin and would like to override it in my AutoPlugin.

I have tried added the value to projectSettings and globalSettings.

Error

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

Code

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
)

The plugin code I'm working on does not define any custom settings of it's own thus has no autoImport of it's own.

Update

I have been unable to resolve the fm.sbt.S3ResolverPlugin in MyPlugin and the code won't compile.

I have tried adding it to enablePlugins on MyPlugin's build.sbt as well as adding it to the dependencies like this:

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

I get an error from sbt which I've asked below:

sbt fails to resolve a plugin as dependency

回答1:

If you create an AutoPlugin in project directory. You need to add this to plugins.sbt.

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

If you create an independent plugin, add this to build.sbt of the plugin

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

autoImport does not work in scala files that are compiled for sbt, ie plugins for example. You have specify imports statements as in simple scala program. Something like this

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 := ???
  )
}

Note that to enable TestPlugin, you have to call enablePlugins(S3ResolverPlugin) in build.sbt



标签: scala sbt