Information about who was Soteria.
If you have any question submit an issue.
Created by gh-md-toc
Feel free to watch the talk given at Scala in the city (2020-05-28) with the slide deck.
- Make sure you are using
SBT 1.2.x
. - Add to
./project/soteria.sbt
in your project:The latest release isaddSbtPlugin("com.leobenkel" % "soteria" % soteriaVersion)
- Make sure to have a config file. Take a look at soteria.json for examples
- If you need a fat-jar:
- Add to your
build.sbt
the following lines:assemblyOption in assembly := soteriaAssemblySettings.value enablePlugins(DockerPlugin)
- Add to your
- Clean up your
build.sbt
by removing all pre-set settings:dependencyOverrides
scalacOptions
- All settings related to
sbt-assembly
andsbt-docker
- All test options
in Test
:javaOptions in Test
testOptions in Test
parallelExecution in Test
fork in Test
- Remove all plugins that are already included for you:
sbt-scoverage
sbt-assembly
sbt-docker
sbt-dependency-graph
sbt-scalafix
sbt-scalafmt
scalastyle-sbt-plugin
- You can run your project the same as before. There can be compilation issues due to vulnerable dependencies.
- Dangerous! If you are not able to fix compiler issues, add:
soteriaSoftOnCompilerWarning := true
- Dangerous! If you are not able to fix dependencies issues, add:
soteriaSoft := true
- You can now then fix scala style issues:
- Run
sbt soteriaCheckScalaStyle
- Run
sbt soteriaCheckScalaFix
- Run
sbt soteriaCheckScalaFmt
- If you are ready to rewrite the broken files:
- Create a clean branch
- Run
sbt soteriaCheckScalaFmtRun
- If you are ready to rewrite the broken files:
- Run
To override where the config file is read from, update the setting soteriaConfPath
in your build.sbt
. This setting can be a URL starting by http://
or https://
or a local file path.
By default it will search for ./soteria.json
.
Root level:
dockerImage
: To set in which image the fat-jar will be built.sbtVersion
: SBTVersion to enforce. If a project is trying to compile with a different version, it will break.scalaVersions
: Is an array of authorized scala Version. This is an array and not a value to allow Spark/Play project on different version.scalaCFlags
: The list of compile flag to add to the build process. IfsoteriaSoftOnCompilerWarning
is not true, then-Xfatal-warnings
will be added as well to trigger a compilation failure.modules
: This is where the bulk of the settings are living.- The structure is
groupId|com.organization
->artifactName
-> description of the constraints
- The structure is
The modules are the constraint enforced by the plugin related to each dependencies.
The path to each module is groupId|com.organization
-> artifactName
-> description of the constraints.
A module can accept those keys:
version
: EitherNone
or a version number. If the library is added with a different version number, the compilation will failexactName
: Default is True if absent. If false, theartifactName
can just be a start. It is used for instance where you want to enforce a version for a library and related ones.circe
orspark-
can be good examples.excludeName
: Default empty. It is used to exclude libraries that would be catch by thename
+exactName
:false. It is used for instance in Play project where you would enforce something for all libraries starting byplay-
except a few that are behind on version numbers.needDoublePercent
: By default is false. If true, the conversion tosbt.ModuleID
will be with%%
instead of%
. The same way it would be in thebuild.sbt
.shouldDownload
: Is true by default and is only used forsbt soteriaGetAllDependencies
.overrideIsEnough
: Default is true. This is related todependenciesToRemove
.- If
overrideIsEnough
is true, the library will be added todependencyOverrides
. - If
overrideIsEnough
is false, the library will be converted to an exclusion rule.
- If
forbidden
: Default is null. If this is set, and the library is added, the message will be displayed as a build failure. For instance you can use it to forbid one MySQL library and advise to use a different one.shouldBeProvided
: Default is false. If true, the compilation will fail if the library is not set toProvided
inbuild.sbt
. It is used for Spark.dependenciesToRemove
: This is a list ofgroupID | artifactName
libraries to remove from this library. This is whenoverrideIsEnough
come into play.scalaVersionsFilter
: This field is a list of scala versions, following this format:[+-][MajorVersion].[MinorVersion]<.[SmallVersion]>
.
"modules": {
"groupID.A": {
"artifactName-A": {
"version": "x.y",
"shouldBeProvided": true
}
}
}
"modules": {
"groupID.D": {
"artifactName-D": {
"version": "None",
"overrideIsEnough": false
}
},
"groupID.A": {
"artifactName-A": {
"dependenciesToRemove": [
"groupID.D | artifactName-D"
],
"version": "vA.A"
}
}
}
The dependenciesToRemove
in A, will search for D.
Since overrideIsEnough
is false in D, the plugin will remove D from A using an ExclusionRule.
Then, the plugin gather all the library which have been removed, and add them back with the appropriate version.
In this case the version of D is None
, so it will not be added back.
Yes there is !
First assemble your json:
"modules": {
"groupID.D": {
"artifactName-D": {
"version": "None",
"overrideIsEnough": false
}
},
"groupID.A": {
"artifactName-A": {
"version": "vA.A"
}
},
"groupID.B": {
"artifactName-B": {
"version": "vB.B"
}
}
}
Then run sbt soteriaDebugAllModules
.
This will:
- Remove all the dependencies from your
build.sbt
- List all the known libraries from your config file
- Add one library at a time, compile and get the fetched dependencies
- Compare the fetch dependencies with the known dependencies from your config file
- When all the libraries have been reviewed, the plugin will display a new json payload that you can just copy paste with all the
dependenciesToRemove
set to the knowledge you have in your json.
The sbt plugin includes ScalaFix, ScalaStyle and ScalaFmt.
- Check that you have .scalafix.conf, .scalafmt.conf and scalastyle-config.xml in your project
- Feel free to copy the one present in this repo to follow the same style guides
- Run
sbt soteriaCheckScalaCheckAll
to check that everything is correct.- You can run each system independently with:
sbt soteriaCheckScalaStyle
sbt soteriaCheckScalaFix
sbt soteriaCheckScalaFmt
- You can run each system independently with:
- To apply the fix for ScalaFmt, you can run
sbt soteriaCheckScalaFmtRun
You can run
sbt soteriaRunTestCoverage
to generate local reporting.
Just open:
./target/scala-2.xx/sbt-1.0/scoverage-report/index.html
To submit to coveralls
sbt soteriaRunSubmitCoverage
This will generate the reports and submit it to coveralls using your COVERALLS token, set in the env var: COVERALLS_REPO_TOKEN
.
You need to add
assemblyOption in assembly := soteriaAssemblySettings.value
enablePlugins(DockerPlugin)
to your build.sbt
file.
You can now call sbt docker
to create the fat-jar. It will be located at ./target/docker/0/*.jar
.
To change in which docker image the build is ran, you can change dockerImage
in soteria.json.
By default, you won't be able to compile if you have errors in your build.
If you need time to fix several issues, you can add:
soteriaSoft := true
to your build.sbt
file while you are fixing them.
If you also want to allow compiler warning, you will need to add:
soteriaSoftOnCompilerWarning := true
to your build.sbt
file while you are fixing them
To print more or less logs for this plugin, you can set soteriaLogLevel
.
For Debug
:
soteriaLogLevel := Level.Debug
For Error
only:
soteriaLogLevel := Level.Error
- Update version number in
VERSION
file. - Deploy the updated plugin locally:
make publishLocal
- Update version number in
./project/soteria.sbt
. - Run the plugin on itself with
make publishLocal
- Publish:
make publish