Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating new Scala project using SBT?

Tags:

scala

sbt

I can create a sbt project like so:

$ 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

This creates build.sbt file for the project.

$ cat build.sbt 
name := "project1"

scalaVersion :="2.10.2"

version :="1.0"

Now is there any command-line for doing the same? Something like:

sbt new_project "name" version scala_version

EDIT1

I figured out another way i.e. create project folder:

$ mkdir project1
$ cd project1/

Update project details:

$ 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/)

We have project generated and settings saved:

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

scalaVersion :="2.10.2"

version :="1.0"

I hope SBT to natively provide functionality like in Maven: mvn archetype:generate.

like image 200
tuxdna Avatar asked Mar 14 '14 10:03

tuxdna


People also ask

How do I create a Scala project in sbt?

Delegate a Scala project build to sbtPress Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.

What is Scala sbt project?

sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.

Do I need sbt for Scala?

No you don't need it. sbt will download Scala for you. If you install sbt-extras (basically just a script) you don't even need to download sbt : it will automatically download the sbt launcher you need.


1 Answers

From sbt 0.13.13 on there's a built in command new:

sbt new scala/scala-seed.g8
like image 102
tekbe Avatar answered Oct 08 '22 23:10

tekbe