Configure a new subproject
In order to configure a new project the following steps must be taken:
- Create a directory at the root of the repository;
- Place a build.sbt file at the root of the created directory;
For now, support for build systems other than sbt is not expected
For now, we assume that each subproject has an sbt configuration. The build script will run each subproject that has some changes.
Structure of the project
The project could have any convenient structure, except it should have a build.sbt file at the root. Also, we assume that project follows SBT guidelines.
SBT basics
SBT is the build tool for Scala, that allows you to manage your dependencies and building process.
To allow your project to use SBT you should create a so-called build definition that is defined in build.sbt. In this file, you can specify dependencies for your project and describe the build process itself.
The very minimalistic version of build definition is:
name := "Your project name" version := "0.1" scalaVersion := "2.12.3" libraryDependencies += "org.typelevel" %% "cats-core" % "1.0.0-RC1"
Here we define a new project with a Cats library dependency.
The next step you would like to do is to start sbt command and run some tasks, like:
- compile - compiles the whole project
- test - run test suites
To learn more about sbt please visit http://www.scala-sbt.org/1.x/docs/Getting-Started.html
To learn more about testing in sbt please visit http://www.scala-sbt.org/1.0/docs/Testing.html
CI process
A quick description of the CI process is:
- Travis watch for github PR/merge hooks;
- When notification received, Travis starts a build process that is described in .travis.yaml file;
- The build runs a build script, that will try to figure out which directories have changed;
- Then script tries to treat these directories as projects and run the "sbt compile test" command;
- Based on output script can determine build as successful or failed;
#!/bin/bash COUNT=0 #list subdirectories for d in */ ; do #check for sbt subproject if [ -f "$d/build.sbt" ] then #check for changes if git diff --name-only HEAD^ | grep "$d" > /dev/null then DIFF[COUNT]="$d" COUNT=$((COUNT+1)) fi fi done #run test for all subprojects with changes for i in ${DIFF[@]}; do echo "Run sbt" cd "$i" sbt test cd ../ done