|
#!/bin/bash |
|
|
|
function usage () { |
|
script=$0 |
|
cat <<USAGE |
|
Creates scala project structure to be used with sbt |
|
|
|
Syntax |
|
`basename $script` project_name artifact_id |
|
|
|
Example |
|
`basename $script` test com.test |
|
USAGE |
|
exit 1 |
|
} |
|
|
|
if [ $# -ne 2 ]; |
|
then |
|
echo "Arguments required" |
|
usage |
|
fi |
|
|
|
directoryName=$1 |
|
projectName=$1 |
|
artifactId=$2 |
|
|
|
[ ! -d $directoryName ] && mkdir $directoryName |
|
|
|
echo "[*] Creating directory structure" |
|
mkdir -p ${directoryName}/src/{main,test}/{java,resources,scala} |
|
mkdir ${directoryName}/lib ${directoryName}/project ${directoryName}/target |
|
|
|
if which git &> /dev/null; then |
|
echo "[*] Initializing git repository" |
|
( cd ${directoryName} && git init &>/dev/null ) |
|
echo "[*] Creating files for git" |
|
echo 'target/ |
|
.cache |
|
.classpath |
|
project/project |
|
project/target |
|
.project/ |
|
.settings |
|
.idea |
|
.idea_modules |
|
*.log |
|
' > ${directoryName}/.gitignore |
|
|
|
touch ${directoryName}/README.md |
|
touch ${directoryName}/CHANGES.md |
|
touch ${directoryName}/LICENSE.txt |
|
fi |
|
|
|
if [ ! -f ~/.sbt/0.13/plugins/build.sbt ]; then |
|
[ ! -d ~/.sbt/0.13/plugins ] && mkdir -p ~/.sbt/0.13/plugins |
|
echo "[*] Creating 'build.sbt' in '~/.sbt/0.13/plugins'" |
|
echo "[*] Adding 'sbt-idea' as dependency plugin" |
|
echo 'addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")' > ~/.sbt/0.13/plugins/build.sbt |
|
echo "[*] Adding 'sbt-assembly' as dependency plugin" |
|
echo 'addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.10.1")' >> ~/.sbt/0.13/plugins/build.sbt |
|
fi |
|
|
|
echo "[*] Creating scala project build files" |
|
cat > ${directoryName}/assembly.sbt <<EOF |
|
import AssemblyKeys._ |
|
|
|
assemblySettings |
|
EOF |
|
|
|
cat > ${directoryName}/project/build.properties <<EOF |
|
sbt.version=0.13.0 |
|
EOF |
|
|
|
cat > ${directoryName}/project/plugins.sbt <<EOF |
|
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.10.1") |
|
EOF |
|
|
|
cat > ${directoryName}/project/Build.scala <<BUILDEOF |
|
import sbt._ |
|
import Keys._ |
|
|
|
object Build extends Build { |
|
val ScalaVersion = "2.10.3" |
|
|
|
lazy val root = Project("${projectName}", file(".")) settings( |
|
version := "0.1", |
|
scalaVersion := ScalaVersion, |
|
organization := "${artifactId}", |
|
scalacOptions ++= Seq("-unchecked", "-deprecation"), |
|
libraryDependencies ++= Dependencies.compile, |
|
libraryDependencies ++= Dependencies.testDependencies, |
|
resolvers ++= Dependencies.resolvers |
|
) |
|
|
|
object Dependencies { |
|
val compile = Seq( |
|
"ch.qos.logback" % "logback-classic" % "1.0.13" |
|
) |
|
|
|
val testDependencies = Seq( |
|
"org.specs2" %% "specs2" % "1.14" % "test", |
|
"org.mockito" % "mockito-all" % "1.9.0" % "test", |
|
"org.hamcrest" % "hamcrest-all" % "1.1" % "test" |
|
) |
|
|
|
val resolvers = Seq( |
|
"amateras-repo" at "http://amateras.sourceforge.jp/mvn/" |
|
) |
|
} |
|
} |
|
BUILDEOF |
|
|
|
echo "[*] Placing logback configuration file at ${directoryName}/src/main/resources/logback.xml" |
|
cat > ${directoryName}/src/main/resources/logback.xml <<EOF |
|
<configuration debug="false"> |
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
|
<encoder> |
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> |
|
</encoder> |
|
</appender> |
|
|
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
|
<file>logFile.log</file> |
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
|
<!-- rollover daily --> |
|
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern> |
|
<!-- keep 1 days worth of history --> |
|
<maxHistory>5</maxHistory> |
|
</rollingPolicy> |
|
<append>true</append> |
|
<encoder> |
|
<pattern>%d{HH:mm:ss.SSS} %-4relative [%thread] %-5level %logger{36} - %msg%n</pattern> |
|
</encoder> |
|
</appender> |
|
|
|
<!-- log to both stdout and file --> |
|
<root level="INFO"> |
|
<appender-ref ref="STDOUT" /> |
|
<appender-ref ref="FILE" /> |
|
</root> |
|
</configuration> |
|
EOF |
|
|
|
|
|
echo "" |
|
echo "Project structure created. See the following URL(s)" |
|
echo "* for build.sbt usage:" |
|
echo -e "\thttp://www.scala-sbt.org/release/docs/Getting-Started/Basic-Def.html" |
|
echo "* for sbt commands:" |
|
echo -e "\thttp://www.scala-sbt.org/release/docs/Getting-Started/Running.html" |
|
|
|
echo "Comman Tasks:" |
|
echo "* To export the project to Intellij:" |
|
echo " Add the following line to ~/.sbt/plugins/build.sbt (or) PROJECT_DIR/project/plugins.sbt" |
|
echo ' addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")' |
|
echo " Then use 'gen-idea' sbt task to export the project to intellij" |
|
echo "* To export the project to Eclipse:" |
|
echo " Use 'SbtEclipsify' @ https://github.com/musk/SbtEclipsify" |
Thank you so much. i have spent like 4 hrs on getting my head around packaging and with sbt version issues. this script solved everything in one shot.