Skip to content

Commit

Permalink
Merge pull request #54 from hmrc/BDOG-662
Browse files Browse the repository at this point in the history
Check all scopes and report failures in one go
  • Loading branch information
colin-lamed authored Nov 30, 2022
2 parents 807c463 + 76c8bb3 commit cad6cd4
Show file tree
Hide file tree
Showing 85 changed files with 3,212 additions and 1,518 deletions.
45 changes: 0 additions & 45 deletions .scalafmt.conf

This file was deleted.

85 changes: 42 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[![Join the chat at https://gitter.im/hmrc/sbt-bobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/hmrc/sbt-bobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

# sbt-bobby

![](https://img.shields.io/github/v/release/hmrc/sbt-bobby)

## Overview

Expand Down Expand Up @@ -39,7 +42,7 @@ BobbyViolation from the specified date, so should be looked at with high priorit

Bobby Rules are defined in a single `json` file, and look like this:

```
```json
{
"libraries": [
{
Expand Down Expand Up @@ -82,11 +85,9 @@ Rules can be placed on both libraries and plugins, and will be enforced on all l
>Note that as of version 3.2.0 the two lists are merged together by the plugin and used as one. They are only divided into two to preserve
>backwards compatiblity with previous releases of `sbt-bobby`
> In order to apply Bobby to the meta scope to validate plugin output, see the section below on 'Running in different configurations'
## Rule Schema
Each rule takes the same form:
```
```json
{
"organisation": "com.typesafe.play",
"name": "sbt-plugin",
Expand All @@ -108,19 +109,26 @@ Where:
Bobby should *not* be added to an individual projects build. Instead, it should be added as a global plugin

This means:
* All projects can benefit from Bobby
* All projects can benefit from Bobby, including the meta build (plugins)
* Bobby can be updated centrally

>At HMRC bobby is added on the Jenkins build-servers and runs automatically for you. You do not need to do anything, unless you
>wish to also run it locally
Just add the plugin to `./sbt/<version>/plugins/plugins.sbt`:
```

```scala
resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)

addDependencyTreePlugin
addSbtPlugin("uk.gov.hmrc" % "sbt-bobby" % "[INSERT-VERSION]")
```

If you are using sbt < 1.4, you will need to replace `addDependencyTreePlugin` with
```scala
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")
```

Then, create your rules configuration as above. This file can live anywhere, you just need to tell Bobby where to find it.

This can be done by setting a `bobby-rules-url` property in `~/.sbt/bobby.conf`. Bobby can read both local or remote files:
Expand All @@ -132,29 +140,11 @@ bobby-rules-url = file:///~/.sbt/deprecated-dependencies.json

That's it!

Now you can run bobby with `sbt validate`.
Now you can run bobby with `sbt validateAll`.

If your build is making use of any outlawed dependencies, an exception will be thrown.
Otherwise, all is good and you can carry on with your day.

> See the 'Configuration Options' section below for more configuration options
### Running in different configurations

Bobby respects the configuration scoping mechanisms built into sbt, which means you can run:

`sbt validate` to validate _compile_ dependencies
`sbt 'Test / validate'` to validate _test_ dependencies
`sbt 'IntegrationTest / validate'` to validate _it_ dependencies
`sbt "reload plugins; validate; reload return"` to validate _plugin_ dependencies

There is also a helper command alias which runs all three of these in one:

`sbt validateAll`

>Prior to major version 3, Bobby tried to pull out both local and plugin dependencies in one task. This has been
>changed to better integrate with the sbt [scoping](https://www.scala-sbt.org/1.x/docs/Scopes.html) ecosystem
### Sbt 1.x

Since major version 1, this plugin is cross compiled for sbt 1.x (specifically 1.3.4).
Expand Down Expand Up @@ -210,15 +200,11 @@ a different violation each time.

## Understanding the Bobby output

Bobby will write out a summary table to the console, as well as generating two report artifacts for every project/configuration scope:
Bobby will write out a summary table to the console, as well as generating two report artifacts for every project/scope:

* `target/bobby-report-<project>-<configuration>.json`
* `target/bobby-report-<project>-<configuration>.json`

For example, if you are running `test:validate` from a project called `root`, the files generated will be:

* `target/bobby-report-root-test.json`
* `target/bobby-report-root-test.json`

These reports tell you of any rule violations that are preventing your job from building, as well as
highlighting any dependencies with warnings that will become violations in the future.
Expand Down Expand Up @@ -290,14 +276,14 @@ You can configure Bobby to be more fussy and fail a build on warnings as well as

To change the strict mode you can:

* Start SBT with an environment variable, `BOBBY_STRICT_MODE=true sbt validate`
* Start SBT with an environment variable, `BOBBY_STRICT_MODE=true sbt validateAll`
* Specify it in your build settings
```
bobbyStrictMode := true
```
* Change it manually just for your console session, e.g.
```
set uk.gov.hmrc.SbtBobbyPlugin.BobbyKeys.bobbyStrictMode := true
set uk.gov.hmrc.bobby.SbtBobbyPlugin.BobbyKeys.bobbyStrictMode := true
```
### Bobby Rule file location
Expand Down Expand Up @@ -337,14 +323,14 @@ output-directory = target/my-dir
By default, the console output will show with ANSI colours. To turn this off you can:
* Start SBT with an environment variable, `BOBBY_CONSOLE_COLOURS=false sbt validate`
* Start SBT with an environment variable, `BOBBY_CONSOLE_COLOURS=false sbt validateAll`
* Specify it in your build settings
```
bobbyConsoleColours := false
```
* Change it manually just for your console session, e.g.
```
set uk.gov.hmrc.SbtBobbyPlugin.BobbyKeys.bobbyConsoleColours := false
set uk.gov.hmrc.bobby.SbtBobbyPlugin.BobbyKeys.bobbyConsoleColours := false
```
### Changing the view type
Expand All @@ -357,14 +343,14 @@ Bobby can display the output table in a few different variations. Currently thes
To change the view type you can:
* Start SBT with an environment variable, `BOBBY_VIEW_TYPE=Nested sbt validate`
* Start SBT with an environment variable, `BOBBY_VIEW_TYPE=Nested sbt validateAll`
* Specify it in your build settings
```
bobbyViewType := Nested
```
* Change it manually just for your console session, e.g.
```
set uk.gov.hmrc.SbtBobbyPlugin.BobbyKeys.bobbyViewType := uk.gov.hmrc.bobby.output.Nested
set uk.gov.hmrc.bobby.SbtBobbyPlugin.BobbyKeys.bobbyViewType := uk.gov.hmrc.bobby.output.Nested
```
## How do I change the Bobby rules enforced by Jenkins?
Expand All @@ -378,21 +364,34 @@ An example commit is as follows. Note that we should always try to stick to one
* The `test-project` folder contains a simple example project which may be useful as a playground:
```
```bash
cd test-project
sbt validate
sbt validateAll
```

* Bobby uses [scripted](https://www.scala-sbt.org/1.x/docs/Testing-sbt-plugins.html) tests which are executed with ```sbt scripted```

## Notice
## Changes

### Version 5.0.0

`sbt-bobby` will now scan all [scopes](https://www.scala-sbt.org/1.x/docs/Scopes.html) in one go, reporting them all together, rather than stopping on the first scope with errors.

From major version 2, `sbt-bobby` makes use of the [sbt-dependency-graph](https://github.com/jrudolph/sbt-dependency-graph) plugin to compute
It also reworks it's dependency on the archived `sbt-dependency-graph` so it will work with sbt 1.3 or 1.4+ by configuring an appropriate plugin to generate dependency dot graphs with `dependencyDot`

### Version 3.0.0

`sbt-bobby` has been updated to integrate with sbt [scopes](https://www.scala-sbt.org/1.x/docs/Scopes.html). Enabling scanning of `Test` and `Integration` scopes.

### Version 2.0.0

`sbt-bobby` now makes use of the [sbt-dependency-graph](https://github.com/jrudolph/sbt-dependency-graph) plugin to compute
the transitive module graph. In previous versions only the locally declared dependencies were considered.

It also takes some inspiration from [sbt-blockade](https://github.com/Verizon/sbt-blockade)
## Notice

`sbt-bobby` takes some inspiration from [sbt-blockade](https://github.com/Verizon/sbt-blockade)

## License

This code is open source software licensed under the [Apache 2.0 License]("http://www.apache.org/licenses/LICENSE-2.0.html").
10 changes: 3 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ lazy val root = (project in file("."))
.settings(
name := "sbt-bobby",
sbtPlugin := true,
majorVersion := 4,
majorVersion := 5,
isPublicArtefact := true,
scalaVersion := "2.12.16",
crossSbtVersions := Vector("1.3.13"),
// Use the code from the sbt-dependency-graph plugin as if it was a standard library dependency
// We use the plugin to resolve the complete module graph for the purpose of validating bobby
// rule violations across transitive dependencies
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1"),
scalaVersion := "2.12.17",
crossSbtVersions := Vector("1.6.2"),
libraryDependencies ++= Seq(
"com.lihaoyi" %% "fansi" % "0.2.6",
"com.typesafe.play" %% "play-json" % "2.9.2",
Expand Down
32 changes: 0 additions & 32 deletions src/main/scala-sbt-0.13/uk/gov/hmrc/SbtCrossSupport.scala

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/scala-sbt-1.0/uk/gov/hmrc/SbtCrossSupport.scala

This file was deleted.

Loading

0 comments on commit cad6cd4

Please sign in to comment.