20

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.

5
  • 1
    You may want to read stackoverflow.com/a/20362511/1305344. Mar 14, 2014 at 14:53
  • I also wonder why nobody mentioned typesafe.com/activator Mar 14, 2014 at 14:54
  • @JacekLaskowski That question you mentioned is really a curious one and great explanation there :-)
    – tuxdna
    Mar 14, 2014 at 18:36
  • @tuxdna Did you manage to get some way to create a maven type archetype for sbt?
    – lazywiz
    Apr 21, 2017 at 17:09
  • @lazywiz Not sure what you mean. Do you want to create mvn archetype projects using sbt cli ?
    – tuxdna
    Apr 24, 2017 at 6:46

3 Answers 3

15

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

sbt new scala/scala-seed.g8
8

There is a np plugin for SBT that does something you are looking for. Usage:

$ sbt 
$ np name:my-new-project org:org.myproject version:0.1.0-SNAPSHOT  
1
  • np plugin is a great thing. But it doesn't allow me to create my own archetypes. I want to have something like project template (with 10-15% of ready-to-use code, needed to be extended), not empty project. Is it possible?
    – pkozlov
    Jul 2, 2015 at 20:49
3

you may want to check out my project skeleton

It can simplify the first steps when you need to get up and running quickly.

1
  • 3
    Each time I have to create a project, I will have to follow same set of steps using skeleton. I want a simple command line tool. Perhaps you could add a shell script to make it even easier.
    – tuxdna
    Mar 14, 2014 at 11:58

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.