Skip to content

Commit

Permalink
Upgraded SBT to 1.0, improved settings for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Nov 18, 2017
1 parent ff81e4e commit cbe45bc
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 36 deletions.
2 changes: 1 addition & 1 deletion project/giter8.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.7.2")
addSbtPlugin("org.foundweekends.giter8" %% "sbt-giter8" % "0.9.0")
4 changes: 4 additions & 0 deletions src/main/g8/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sbt._
import Settings._

scalaVersion in ThisBuild := scalaVersionUsed
scalafmtVersion in ThisBuild := scalaFmtVersionUsed

lazy val root = project.root
.setName("$name$")
Expand Down Expand Up @@ -42,3 +43,6 @@ lazy val second = project.from("second")
.compileAndTestDependsOn(common)
.settings(mainClass in (Compile, run) := Some("$package$.second.Second"))
.settings(mainClass in assembly := Some("$package$.second.Second"))


addCommandAlias("fullTest", ";test;it:test;scalastyle")
8 changes: 6 additions & 2 deletions src/main/g8/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ object Dependencies {
// scala version
val scalaVersion = "2.12.3"

val scalaFmtVersion = "1.2.0"

val monixVersion = "2.3.0"
val specs2Version = "3.8.9"

Expand All @@ -17,7 +19,7 @@ object Dependencies {
Resolver.bintrayRepo("cakesolutions", "maven")
)

val scalaConfig = "com.typesafe" % "config" % "1.3.1"
val scalaConfig = "com.typesafe" % "config" % "1.3.1"
val pureConfig = "com.github.pureconfig" %% "pureconfig" % "0.8.0"

// async
Expand All @@ -28,7 +30,7 @@ object Dependencies {
val cats = "org.typelevel" %% "cats" % "0.9.0"

// logging
val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.5.0"
val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2"
val logback = "ch.qos.logback" % "logback-classic" % "1.2.3"

// testing
Expand All @@ -42,6 +44,8 @@ trait Dependencies {

val scalaVersionUsed = scalaVersion

val scalaFmtVersionUsed = scalaFmtVersion

// resolvers
val commonResolvers = resolvers

Expand Down
4 changes: 2 additions & 2 deletions src/main/g8/project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ object Settings extends Dependencies {
resolvers ++= commonResolvers,

libraryDependencies ++= mainDeps,
libraryDependencies ++= testDeps map (_ % Test),

scalafmtOnCompile in Compile := true,

scalastyleFailOnError := true,
scalastyleFailOnError in Test := false,

wartremoverWarnings in (Compile, compile) ++= Warts.allBut(
Wart.Any,
Expand All @@ -107,6 +105,8 @@ object Settings extends Dependencies {
.settings(inConfig(config)(Defaults.testSettings): _*)
.settings(inConfig(config)(scalafmtSettings))
.settings(scalafmtOnCompile in config := true)
.settings(scalastyleConfig in config := baseDirectory.value / "scalastyle-test-config.xml")
.settings(scalastyleFailOnError in config := false)
.settings(fork in config := requiresFork)
.settings(testFrameworks := Seq(Specs2))
.settings(libraryDependencies ++= testDeps map (_ % config.name))
Expand Down
2 changes: 1 addition & 1 deletion src/main/g8/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.16
sbt.version=1.0.3
18 changes: 7 additions & 11 deletions src/main/g8/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")

addSbtPlugin("com.github.tkawachi" % "sbt-lock" % "0.3.0")
addSbtPlugin("com.github.tkawachi" % "sbt-lock" % "0.4.0")

addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.10")
addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.12")

addSbtPlugin("com.lucidchart" % "sbt-scalafmt-coursier" % "1.10")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.5")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.0")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC3")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.2.0")

addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.1.1")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.9.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")

libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.7.25"
99 changes: 99 additions & 0 deletions src/main/g8/scalastyle-test-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<scalastyle>
<name>$name$ test style</name>
<check level="error" class="org.scalastyle.file.FileLengthChecker" enabled="false">
<parameters>
<parameter name="maxFileLength"><![CDATA[800]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.file.FileLineLengthChecker" enabled="false">
<parameters>
<parameter name="maxLineLength"><![CDATA[120]]></parameter>
<parameter name="tabSize"><![CDATA[2]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.file.FileTabChecker" enabled="true"/>
<check level="error" class="org.scalastyle.file.HeaderMatchesChecker" enabled="false"/>
<check level="error" class="org.scalastyle.file.NewLineAtEofChecker" enabled="true"/>
<check level="error" class="org.scalastyle.file.NoNewLineAtEofChecker" enabled="false"/>
<check level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[println]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.file.WhitespaceEndOfLineChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.ClassNamesChecker" enabled="false">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.CovariantEqualsChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<parameters>
<parameter name="maximum"><![CDATA[15]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.EqualsHashCodeChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.IfBraceChecker" enabled="false">
<parameters>
<parameter name="singleLineAllowed"><![CDATA[true]]></parameter>
<parameter name="doubleLineAllowed"><![CDATA[true]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.IllegalImportsChecker" enabled="true">
<parameters>
<parameter name="illegalImports"><![CDATA[sun._,java.awt._]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MagicNumberChecker" enabled="false">
<parameters>
<parameter name="ignore"><![CDATA[-1,0,1,2,3,200,201,400,401,403,404]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MethodLengthChecker" enabled="true">
<parameters>
<parameter name="maxLength"><![CDATA[50]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-zA-Z][A-Za-z0-9]*|\*\$]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NoCloneChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="false"/>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.NoFinalizeChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.NullChecker" enabled="false"/>
<check level="error" class="org.scalastyle.scalariform.NumberOfMethodsInTypeChecker" enabled="true">
<parameters>
<parameter name="maxMethods"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.NumberOfTypesChecker" enabled="true">
<parameters>
<parameter name="maxTypes"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ObjectNamesChecker" enabled="false">
<parameters>
<parameter name="regex"><![CDATA[[A-Z][A-Za-z]*]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.PackageObjectNamesChecker" enabled="true">
<parameters>
<parameter name="regex"><![CDATA[^[a-z][A-Za-z0-9]*\$]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.ParameterNumberChecker" enabled="true">
<parameters>
<parameter name="maxParameters"><![CDATA[8]]></parameter>
</parameters>
</check>
<check level="error" class="org.scalastyle.scalariform.PublicMethodsHaveTypeChecker" enabled="false"/>
<check level="error" class="org.scalastyle.scalariform.ReturnChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.SimplifyBooleanExpressionChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.SpacesAfterPlusChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.SpacesBeforePlusChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.StructuralTypeChecker" enabled="true"/>
<check level="error" class="org.scalastyle.scalariform.UppercaseLChecker" enabled="true"/>
</scalastyle>
48 changes: 29 additions & 19 deletions src/main/g8/scripts/sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

set -o pipefail

declare -r sbt_release_version="0.13.15"
declare -r sbt_unreleased_version="0.13.15"
declare -r sbt_release_version="0.13.16"
declare -r sbt_unreleased_version="0.13.16"

declare -r latest_212="2.12.1"
declare -r latest_213="2.13.0-M2"
declare -r latest_212="2.12.4"
declare -r latest_211="2.11.11"
declare -r latest_210="2.10.6"
declare -r latest_29="2.9.3"
Expand All @@ -27,7 +28,7 @@ declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory
declare sbt_jar sbt_dir sbt_create sbt_version sbt_script sbt_new
declare sbt_explicit_version
declare verbose noshare batch trace_level
declare sbt_saved_stty debugUs
declare debugUs

declare java_cmd="java"
declare sbt_launch_dir="$HOME/.sbt/launchers"
Expand All @@ -43,19 +44,21 @@ echoerr () { echo >&2 "$@"; }
vlog () { [[ -n "$verbose" ]] && echoerr "$@"; }
die () { echo "Aborting: $@" ; exit 1; }

# restore stty settings (echo in particular)
onSbtRunnerExit() {
[[ -n "$sbt_saved_stty" ]] || return
vlog ""
vlog "restoring stty: $sbt_saved_stty"
stty "$sbt_saved_stty"
unset sbt_saved_stty
}
setTrapExit () {
# save stty and trap exit, to ensure echo is re-enabled if we are interrupted.
export SBT_STTY="$(stty -g 2>/dev/null)"

# restore stty settings (echo in particular)
onSbtRunnerExit() {
[ -t 0 ] || return
vlog ""
vlog "restoring stty: $SBT_STTY"
stty "$SBT_STTY"
}

# save stty and trap exit, to ensure echo is re-enabled if we are interrupted.
trap onSbtRunnerExit EXIT
sbt_saved_stty="$(stty -g 2>/dev/null)"
vlog "Saved stty: $sbt_saved_stty"
vlog "saving stty: $SBT_STTY"
trap onSbtRunnerExit EXIT
}

# this seems to cover the bases on OSX, and someone will
# have to tell me about the others.
Expand Down Expand Up @@ -228,8 +231,13 @@ execRunner () {
vlog ""
}

[[ -n "$batch" ]] && exec </dev/null
exec "$@"
setTrapExit

if [[ -n "$batch" ]]; then
"$@" < /dev/null
else
"$@"
fi
}

jar_url () { make_url "$1"; }
Expand Down Expand Up @@ -320,6 +328,7 @@ runner with the -x option.
-210 use $latest_210
-211 use $latest_211
-212 use $latest_212
-213 use $latest_213
-scala-home <path> use the scala build at the specified directory
-scala-version <version> use the specified version of scala
-binary-version <version> use the specified scala version when searching for dependencies
Expand Down Expand Up @@ -399,7 +408,8 @@ process_args () {
-210) setScalaVersion "$latest_210" && shift ;;
-211) setScalaVersion "$latest_211" && shift ;;
-212) setScalaVersion "$latest_212" && shift ;;
new) sbt_new=true && sbt_explicit_version="$sbt_release_version" && addResidual "$1" && shift ;;
-213) setScalaVersion "$latest_213" && shift ;;
new) sbt_new=true && : ${sbt_explicit_version:=$sbt_release_version} && addResidual "$1" && shift ;;
*) addResidual "$1" && shift ;;
esac
done
Expand Down

0 comments on commit cbe45bc

Please sign in to comment.