Skip to content

Instantly share code, notes, and snippets.

@melrief
Last active August 29, 2015 14:12
Show Gist options
  • Save melrief/1196a605f32853cbe022 to your computer and use it in GitHub Desktop.
Save melrief/1196a605f32853cbe022 to your computer and use it in GitHub Desktop.
This is a simple script to create an sbt template project in a directory
#!/bin/bash -eu
#
# Set up a sbt project. This script requires sbt and bash :).
#
# usage:
# - mkdir <project_name>
# - cd <project_name>
# - ./<this_script_dir>/init_sbt_project.sh
#
# author: Mario Pastorelli <pastorelli.mario@gmail.com>
###################
## Check for sbt ##
hash sbt 2>/dev/null || { echo >&2 <<EOF
I require sbt but it's not installed. Download and install it from http://www.scala-sbt.org/download.html. Aborting.
EOF
exit 1; }
echo "Found $(sbt --version)"
######################
## Ask the settings ##
project_name=${PWD##*/}
project_version="0.0.1"
scala_version="2.10.4"
scalac_options="Seq(\"-feature\")"
sbt_version="0.13.7"
for var in "project_name" "project_version" "scala_version" "scalac_options" "sbt_version"; do
name=$(tr '_' ' ' <<<${var})
echo -n "Insert the ${name} followed by [ENTER] (default: ${!var}): "
read temp
if [ -n "${temp}" ];then
eval ${var}="${temp}"
unset temp
fi
done
#############################
## Summary of the settings ##
echo -e "\nConfiguration is:"
for var in "project_name" "project_version" "scala_version" "scalac_options" "sbt_version"; do
name=$(tr '_' ' ' <<<${var})
echo "${name} = ${!var}"
done
########################
## Create the project ##
if [ -e "build.sbt" ]; then
echo 'File build.sbt exists, if you want to continue please delete it and restart this script'
exit -1
fi
cat <<EOF > "build.sbt"
name := "${project_name}"
version := "${project_version}"
scalaVersion := "${scala_version}"
scalacOptions ++= ${scalac_options}
EOF
mkdir -p "project"
if [ -e "project/build.properties" ]; then
echo 'File project/build.properties exists, if you want to continue please delete it and restart this script'
exit -1
fi
cat <<EOF > "project/build.properties"
sbt.version=${sbt_version}
EOF
mkdir -p "src/main/scala"
mkdir -p "src/test/scala"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment