将sbt命令的输出保存到Scala文件中。

huangapple go评论54阅读模式
英文:

Saving sbt command output to a file in Scala

问题

以下是您要翻译的内容:

"I am running cmd like "sbt dependencyTree" but it gives outlut like, first few lines some info about versions and all then gives the origanl cmd output.

Is there a way to directly put the cmd output in file using sbt cmd.

eg. sbt dependencyTree"

您要求的输出:

"I want the output only like below :

[info] org.http4s:http4s_2.13:0.23.19-6-b22f722-SNAPSHOT [S]
[info] org.http4s:http4s-scalafix-internal_2.13:0.23.19-6-b22f722-SNAPSHOT [S]
[info] +-ch.epfl.scala:scalafix-core_2.13:0.10.4 [S]
[info] +-com.geirsson:metaconfig-typesafe-config_2.13:0.10.0 [S]
[info] | +-com.geirsson:metaconfig-core_2.13:0.10.0 [S]
[info] | | +-com.geirsson:metaconfig-pprint_2.13:0.10.0 [S]
[info] | | | +-com.lihaoyi:fansi_2.13:0.3.0
[info] | | | | +-com.lihaoyi:sourcecode_2.13:0.2.7 (evicted by: 0.3.0)
[info] | | | | +-com.lihaoyi:sourcecode_2.13:0.3.0 [S]
[info] | | | |
[info] | | | +-org.scala-lang:scala-compiler:2.13.10 [S]
[info] | | | | +-io.github.java-diff-utils:java-diff-utils:4.12`
[info] | | | | +-net.java.dev.jna:jna:5.9.0"

请告诉我是否还需要其他信息。

英文:

I am running cmd like "sbt dependencyTree" but it gives outlut like, first few lines some info about versions and all then gives the origanl cmd output.

Is there a way to directly put the cmd output in file using sbt cmd.

eg. sbt dependencyTree

[info] welcome to sbt 1.8.3 (Eclipse Adoptium Java 17.0.7)
[info] loading settings for project http4s-build from build.sbt,plugins.sbt ...
[info] loading project definition from /Users/chandrapratapprajapati/sbt-local/http4s/project
[info] loading settings for project root from build.sbt ...
[info] resolving key references (63042 settings) ...
[info] set scmInfo to https://github.com/http4s/http4s
[info] set current project to http4s (in build file:/Users/chandrapratapprajapati/sbt-local/http4s/)
[info] org.http4s:http4s_2.13:0.23.19-6-b22f722-SNAPSHOT [S]
[info] org.http4s:http4s-scalafix-internal_2.13:0.23.19-6-b22f722-SNAPSHOT [S]
[info]   +-ch.epfl.scala:scalafix-core_2.13:0.10.4 [S]
[info]     +-com.geirsson:metaconfig-typesafe-config_2.13:0.10.0 [S]
[info]     | +-com.geirsson:metaconfig-core_2.13:0.10.0 [S]
[info]     | | +-com.geirsson:metaconfig-pprint_2.13:0.10.0 [S]
[info]     | | | +-com.lihaoyi:fansi_2.13:0.3.0
[info]     | | | | +-com.lihaoyi:sourcecode_2.13:0.2.7 (evicted by: 0.3.0)
[info]     | | | | +-com.lihaoyi:sourcecode_2.13:0.3.0 [S]
[info]     | | | |
[info]     | | | +-org.scala-lang:scala-compiler:2.13.10 [S]
[info]     | | | | +-io.github.java-diff-utils:java-diff-utils:4.12
[info]     | | | | +-net.java.dev.jna:jna:5.9.0


I want the output only like below :

[info] org.http4s:http4s_2.13:0.23.19-6-b22f722-SNAPSHOT [S]
[info] org.http4s:http4s-scalafix-internal_2.13:0.23.19-6-b22f722-SNAPSHOT [S]
[info]   +-ch.epfl.scala:scalafix-core_2.13:0.10.4 [S]
[info]     +-com.geirsson:metaconfig-typesafe-config_2.13:0.10.0 [S]
[info]     | +-com.geirsson:metaconfig-core_2.13:0.10.0 [S]
[info]     | | +-com.geirsson:metaconfig-pprint_2.13:0.10.0 [S]
[info]     | | | +-com.lihaoyi:fansi_2.13:0.3.0
[info]     | | | | +-com.lihaoyi:sourcecode_2.13:0.2.7 (evicted by: 0.3.0)
[info]     | | | | +-com.lihaoyi:sourcecode_2.13:0.3.0 [S]
[info]     | | | |
[info]     | | | +-org.scala-lang:scala-compiler:2.13.10 [S]
[info]     | | | | +-io.github.java-diff-utils:java-diff-utils:4.12`
[info]     | | | | +-net.java.dev.jna:jna:5.9.0

IS there a way to achieve that.

答案1

得分: 2

你可以通过运行以下命令来实现:

sbt 'dependencyGraph/toFile "/path/to/output"'

如果你是从sbt REPL运行的,你可以省略命令周围的单引号(当然也可以省略sbt)。

请注意,这在单个模块上运行良好,但在聚合项目上不起作用(这是一个已知问题),所以如果你需要在多模块项目上运行它,你需要手动在各个子项目上进行范围运行,例如:

sbt 'someSubModuleName/depedencyGraph/toFile "/path/to/output"'

结果将仅包含依赖树,没有[info]前缀,希望这对你不是问题。

英文:

You can do so by running the following:

sbt 'dependencyGraph/toFile "/path/to/output"'

If you are running from the sbt REPL you can omit the single quotes around the command (and sbt as well, of course).

Please note that this works fine on individual modules but not on aggregates (it's a known issue), so if you need to run it on a multi-module project you'll have to manually run it scoped on individual sub-projects, e.g.:

sbt 'someSubModuleName/depedencyGraph/toFile "/path/to/output"'

The result will contain only the dependency tree, without the [info] prefix, hopefully that's not a problem for you.

huangapple
  • 本文由 发表于 2023年5月30日 00:28:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358928.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定