gpt4 book ai didi

scala - 使用 SBT 创建新的 Scala 项目?

转载 作者:行者123 更新时间:2023-12-02 17:47:54 27 4
gpt4 key购买 nike

我可以像这样创建一个 sbt 项目:

$ mkdir project1
$ cd project1
$ sbt
Loading /usr/share/sbt/bin/sbt-launch-lib.bash

> set name := "project1"
[info] Defining *:name
...

> set scalaVersion :="2.10.2"
[info] Defining *:scalaVersion
...

> set version :="1.0"
[info] Defining *:version
...

> session save
[info] Reapplying settings...

> exit

这将为项目创建 build.sbt 文件。

$ cat build.sbt 
name := "project1"

scalaVersion :="2.10.2"

version :="1.0"

现在有没有命令行可以做同样的事情?像这样的东西:

sbt new_project "name" version scala_version

编辑1

我想出了另一种方法,即创建项目文件夹:

$ mkdir project1
$ cd project1/

更新项目详细信息:

$ sbt 'set name := "project1"' 'set scalaVersion :="2.10.2"' 'set version :="1.0"' 'session save'
Loading /usr/share/sbt/bin/sbt-launch-lib.bash
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Defining *:name
[info] The new value will be used by *:description, *:normalizedName and 6 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Defining *:scalaVersion
[info] The new value will be used by *:allDependencies, *:ivyScala and 10 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Defining *:version
[info] The new value will be used by *:isSnapshot, *:projectId and 3 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)
[info] Reapplying settings...
[info] Set current project to project1 (in build file:/tmp/scala/project1/)

我们已生成项目并保存设置:

$ ls
build.sbt project
$ cat build.sbt
name := "project1"

scalaVersion :="2.10.2"

version :="1.0"

我希望 SBT 能够原生提供像 Maven 中一样的功能:mvn archetype:generate

最佳答案

从 sbt 0.13.13 开始,有一个内置命令new:

sbt new scala/scala-seed.g8

关于scala - 使用 SBT 创建新的 Scala 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22401739/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com