Skip to content

Instantly share code, notes, and snippets.

@rkaneko
Last active December 19, 2015 12:19
Show Gist options
  • Save rkaneko/5954323 to your computer and use it in GitHub Desktop.
Save rkaneko/5954323 to your computer and use it in GitHub Desktop.
Hello Scala World with sbt and giter8 .

Hello Scala World !

env

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 12.04.2 LTS
Release:	12.04
Codename:	precise

$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) Server VM (build 23.21-b01, mixed mode)

# OpenJDKでも大丈夫だと思う

$ scala -version
Scala code runner version 2.10.1 -- Copyright 2002-2013, LAMP/EPFL

$ g8
giter8 0.5.3
Usage: g8 [TEMPLATE] [OPTION]...
Apply specified template.

OPTIONS
    -b, --branch
        Resolves a template within a given branch
    --paramname=paramvalue
        Set given parameter value and bypass interaction.


Apply template and interactively fulfill parameters.
    g8 n8han/giter8

Or
    g8 git://github.com/n8han/giter8.git

Apply template from a remote branch
    g8 n8han/giter8 -b some-branch

Apply template from a local repo
    g8 file://path/to/the/repo

Apply given name parameter and use defaults for all others.
    g8 n8han/giter8 --name=template-test

dev

$ mkdir -p ~/workspace/scala

$ cd ~/workspace/scala

$ g8 kobmic/plain-scala.g8

Plain Scala project with scalatest and/or specs2 

version [0.1.0-SNAPSHOT]: 
organization [my.organization]: com.rkaneko
name [MyScalaProject]: HelloScalaWorld

Template applied in ./helloscalaworld

$ tree helloscalaworld/
helloscalaworld/
├── build.sbt
├── project
│   └── plugins.sbt
└── src
    ├── main
    │   └── scala
    │       └── Stub.scala
    └── test
        └── scala
            ├── StubSpec.scala
            └── StubTest.scala

6 directories, 5 files

$ cd helloscalaworld

$ vi src/main/scala/Stub.scala

## Please refer src gist Stub.scala

$ sbt compile
[info] Loading project definition from /home/rkaneko/workspace/scala/helloscalaworld/project
[info] Updating {file:/home/rkaneko/workspace/scala/helloscalaworld/project/}default-424bc3...
[info] Resolving org.scala-sbt#precompiled-2_10_1;0.12.3 ...
[info] Done updating.
[info] Set current project to HelloScalaWorld (in build file:/home/rkaneko/workspace/scala/helloscalaworld/)
[info] Updating {file:/home/rkaneko/workspace/scala/helloscalaworld/}default-e66bf6...
[info] Resolving org.scala-lang#scala-reflect;2.10.0 ...
[info] Done updating.
[info] Compiling 1 Scala source to /home/rkaneko/workspace/scala/helloscalaworld/target/scala-2.10/classes...
[success] Total time: 10 s, completed 2013/07/09 11:45:44

$ sbt run
[info] Loading project definition from /home/rkaneko/workspace/scala/helloscalaworld/project
[info] Set current project to HelloScalaWorld (in build file:/home/rkaneko/workspace/scala/helloscalaworld/)
[info] Running com.rkaneko.Stub 
Hello Scala World !
package com.rkaneko
object Stub {
def main(args: Array[String]) {
val list = "Hello"::"Scala"::"World"::"!"::Nil
println(list.mkString(" "))
}
}
class Stub {
// do something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment