I'm loving scala and I can see myself creating a lot of sbt projects in the future. To avoid writing the boilerplate structure of sbt project everytime I start I created this simple bash function to do that for me:
function create_sbt_project() {
project_folder=$1
mkdir $project_folder
pushd $project_folder
git init
echo -e "name := \"$1\"\n\nversion := \"1.0\"\n\nscalaVersion := \"2.9.1\"" > build.sbt
mkdir -p src/main/resources
mkdir -p src/main/scala
mkdir -p src/main/java
mkdir -p src/test/resources
mkdir -p src/test/scala
mkdir -p src/test/java
echo -e "object Hi {\n def main(args:Array[String]) = println(\"Hi!\")\n}" > src/main/scala/hw.scala
echo target/ >> .gitignore
git add .
git commit -m "Initial Commit"
sbt compile run clean
popd
}
function create_sbt_project() {
project_folder=$1
mkdir $project_folder
pushd $project_folder
git init
echo -e "name := \"$1\"\n\nversion := \"1.0\"\n\nscalaVersion := \"2.9.1\"" > build.sbt
mkdir -p src/main/resources
mkdir -p src/main/scala
mkdir -p src/main/java
mkdir -p src/test/resources
mkdir -p src/test/scala
mkdir -p src/test/java
echo -e "object Hi {\n def main(args:Array[String]) = println(\"Hi!\")\n}" > src/main/scala/hw.scala
echo target/ >> .gitignore
git add .
git commit -m "Initial Commit"
sbt compile run clean
popd
}
e.g.
$ create_sbt_project test
will create a folder with standard sbt project structure that compiles and runs.
No comments:
Post a Comment