本文介绍了需要从我在 sbt 插件中使用的插件中提供 SettingKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用 s3 解析器插件 并希望在我的 AutoPlugin 中覆盖它.

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

我尝试将值添加到 projectSettingsglobalSettings.

I have tried added the value to projectSettings and globalSettings.

错误

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.

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.

更新

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

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

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

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"
)

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

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

sbt 无法将插件解析为依赖项

推荐答案

如果您在 project 目录中创建 AutoPlugin.您需要将此添加到 plugins.sbt.

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")

如果你创建一个独立的插件,把这个添加到插件的build.sbt

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 在为 sbt 编译的 scala 文件中不起作用,例如插件.您已经在简单的 Scala 程序中指定了 imports 语句.类似这样的

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

注意要启用TestPlugin,你必须在build.sbt

这篇关于需要从我在 sbt 插件中使用的插件中提供 SettingKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:57