在没有插件的情况下从命令行运行SBT任务.sbt

发布于 2025-02-11 23:53:57 字数 636 浏览 1 评论 0原文

如何从plugins.sbt中未定义的插件中运行 sbt 使用任务构建?

在Maven中,这很容易: mvn groupID:artifactID:1.2.3:目标

eg mvn org.owasp:depentency-check-maven:7.1.1:

在SBT中检查我得到:

$ sbt net.vonbuchholtz:sbt-dependency-check:4.1.0:check
...
[error] Expected ID character
[error] Not a valid command: net (similar: set, new, inspect)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':'
[error] Expected key
[error] Not a valid key: net (similar: test, name, run)
[error] net.vonbuchholtz:sbt-dependency-check:4.1.0:check
[error]    ^

How to run an sbt build with task from a plugin that is not defined in plugins.sbt?

In maven it's as easy as:
mvn groupId:artifactId:1.2.3:goal

e.g. mvn org.owasp:dependency-check-maven:7.1.1:check

In sbt I get:

$ sbt net.vonbuchholtz:sbt-dependency-check:4.1.0:check
...
[error] Expected ID character
[error] Not a valid command: net (similar: set, new, inspect)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':'
[error] Expected key
[error] Not a valid key: net (similar: test, name, run)
[error] net.vonbuchholtz:sbt-dependency-check:4.1.0:check
[error]    ^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2025-02-18 23:53:57

您必须将插件添加到SBT中才能调用它。

如果您不想将其添加到项目中,则可以在全球上添加它:

// Put things into
//   ~/.sbt/1.0/plugins/plugins.sbt
// Actually, you can name the file differently as long as it's in
//   ~/.sbt/1.0/plugins/
// and ends with .sbt, sbt will load all files ending with .sbt
// from there. 
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.1.0")

或者,您可以在.gitignore中定义一些全球忽略的文件(假设您正在使用git,并且不想偶然地提交东西)。

// ~/.gitconfig
[core]
     excludesfile = ~/.gitignore_global
// ~/.gitignore_global
local.sbt

然后,您可以添加所有想要的东西,例如local.sbt - 您将能够向您的回购添加一些临时更改,而不必担心它们会在上游。

还有另一个选项,您可以将这些插件配置放入某些文件中,例如〜/.extra_plugins.sbt,并用命令行添加它们:

// ~/extra_plugins.sbt
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.1.0")
sbt --addPluginSbtFile="~/extra_plugins.sbt" dependencyCheck

据我所知,我不能在您当您时跳过步骤创建.sbt文件。充其量您可以自动生成它并用脚本填充它:

// something like this
local tmp_sbt=`mktemp`
echo 'addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.1.0")' >> "$tmp_sbt"
sbt --addPluginSbtFile="$tmp_sbt" dependencyCheck
rm "$tmp_sbt"

You have to have plugin added to sbt to be able to call it.

If you don't want to add it to the project you can add it globally:

// Put things into
//   ~/.sbt/1.0/plugins/plugins.sbt
// Actually, you can name the file differently as long as it's in
//   ~/.sbt/1.0/plugins/
// and ends with .sbt, sbt will load all files ending with .sbt
// from there. 
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.1.0")

Alternatively, you can define some globally ignored file in .gitignore (assuming you are using git and don't want to accidentally commit things).

// ~/.gitconfig
[core]
     excludesfile = ~/.gitignore_global
// ~/.gitignore_global
local.sbt

Then you can add all you want there e.g. local.sbt - you will be able to add some ad hoc changes to you repo and don't worry that they will be commited upstream.

As yet another option, you can put these plugin configs into some file e.g. ~/.extra_plugins.sbt and add them with a command line:

// ~/extra_plugins.sbt
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.1.0")
sbt --addPluginSbtFile="~/extra_plugins.sbt" dependencyCheck

As far as I can tell you cannot skip the step when you are creating the .sbt file. At best you could auto-generate it and populate it with a script:

// something like this
local tmp_sbt=`mktemp`
echo 'addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "4.1.0")' >> "$tmp_sbt"
sbt --addPluginSbtFile="$tmp_sbt" dependencyCheck
rm "$tmp_sbt"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文