Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / Collectors

Scala build

The sbt build in the project directory: the Scala and sbt versions it pins, every subproject the reader saw, the library dependencies each build file names with their configurations, and the plugins the build itself runs. build.sbt is Scala rather than a declaration, so what it declares indirectly is not seen and scanned says so.

Facts keyscala
Versionv1
Scriptscala.py
Timeout30 seconds

Inputs

InputDescriptionDefaultEnvironment
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

A guardrail that declares an input of the same name passes it through, so the guardrail's configuration in buildnote.json is what decides these values.

A guardrail asks for these facts by name, and reads them back the same way:

json
{
  "collect": ["scala"]
}
python
scala = guardrail.facts("scala")

Facts

The document scala collects. A path carrying [] is an entry of the list before it, and one carrying [path] is a key of the object before it.

FactMeaning
directoryThe projectDir input, as the guardrail configured it.
existsWhether that directory is there. Nothing else is collected when it is not.
manifestPath of the primary manifest, relative to projectDir, always build.sbt.
sourcesEvery build file that was read, in the order they were read.
scannedEvery build file that is Scala rather than a declaration and was read by pattern. A dependency built by a function, added inside a condition or held in a variable is not seen, so a guardrail reading dependencies from one of these is reading a floor rather than the whole list.
declaredThe Scala version the build declares, or null when the reader could not see one.
declared.versionVersion exactly as written, such as 3.4.1.
declared.sourceBuild file declaring it, relative to projectDir.
declared.pinnedWhether it names one exact version. sbt takes a literal version rather than a range, so this is true wherever a version was read and false only when it is an unresolved reference.
sbtThe sbt version project/build.properties pins, such as 1.9.9, or null when the checkout pins none and whatever launcher the runner has decides.
projectsThe root build, followed by every subproject the reader saw declared with project in file(...).
projects[].pathDirectory of the subproject, relative to projectDir, . for the project directory itself.
projects[].manifestThe build file declaring it, relative to projectDir.
projects[].nameName the lazy val binds it to, or null for the root.
dependenciesWhat the build files declare, split by whether the build asks for it itself.
dependencies.directEvery libraryDependencies entry the reader saw, in the order they appear.
dependencies.direct[].nameCoordinates as group:artifact, such as org.typelevel:cats-effect. An artifact declared with %% keeps its base name, without the Scala binary version sbt appends.
dependencies.direct[].versionRevision exactly as written, such as 3.5.4, or null when it is an unresolved reference rather than a literal.
dependencies.direct[].scopesThe configuration the entry names, such as Test or Provided, or default when it names none and the dependency is on the compile classpath.
dependencies.direct[].sourceBuild file declaring it, relative to projectDir.
dependencies.direct[].pinnedWhether the revision is a literal version rather than a reference or a latest.integration style moving revision.
dependencies.direct[].crossVersionWhether the entry uses %%, which makes sbt append the Scala binary version to the artifact name.
dependencies.transitiveAlways empty. sbt resolves at build time and commits nothing by default: lockfiles says whether a locking plugin wrote one.
pluginsEvery sbt plugin project/plugins.sbt adds, as group:artifact, which is code the build runs with the build's own privileges.
lockfilesEvery dependency lock file committed, relative to projectDir. sbt writes none by default, so an empty list is the usual answer rather than a finding on its own.
unparsedEvery build file the reader could not open, so a guardrail can tell a build that declares nothing from one nobody could read.
unparsed[].pathPath of that build file, relative to projectDir.
unparsed[].reasonWhat stopped the reader.

A collector that cannot finish prints what it had along with an incomplete key saying why, so the facts below the point it stopped are absent. A check that cares reads incomplete before the rest.

Example facts

The example facts collected by scala collector:

json
{
  "directory": ".",
  "exists": true,
  "manifest": "build.sbt",
  "sources": [
    "build.sbt",
    "project/build.properties",
    "project/plugins.sbt"
  ],
  "scanned": [
    "build.sbt",
    "project/plugins.sbt"
  ],
  "declared": {
    "version": "3.4.1",
    "source": "build.sbt",
    "pinned": true
  },
  "sbt": "1.9.9",
  "projects": [
    {
      "path": ".",
      "manifest": "build.sbt",
      "name": null
    },
    {
      "path": "core",
      "manifest": "build.sbt",
      "name": "core"
    },
    {
      "path": "server",
      "manifest": "build.sbt",
      "name": "server"
    }
  ],
  "dependencies": {
    "direct": [
      {
        "name": "org.typelevel:cats-effect",
        "version": "3.5.4",
        "scopes": [
          "default"
        ],
        "source": "build.sbt",
        "pinned": true,
        "crossVersion": true
      },
      {
        "name": "com.lihaoyi:upickle",
        "version": "3.3.0",
        "scopes": [
          "default"
        ],
        "source": "build.sbt",
        "pinned": true,
        "crossVersion": true
      },
      {
        "name": "org.http4s:http4s-ember-server",
        "version": "0.23.27",
        "scopes": [
          "default"
        ],
        "source": "build.sbt",
        "pinned": true,
        "crossVersion": true
      },
      {
        "name": "org.scalameta:munit",
        "version": "1.0.0",
        "scopes": [
          "Test"
        ],
        "source": "build.sbt",
        "pinned": true,
        "crossVersion": true
      }
    ],
    "transitive": []
  },
  "plugins": [
    "org.scalameta:sbt-scalafmt"
  ],
  "lockfiles": [],
  "unparsed": []
}

Collected for

GuardrailCategoryInputs
scala/dependencies-pinnedscalaprojectDir
scala/no-snapshot-dependenciesscalaprojectDir
scala/sbt-version-pinnedscalaprojectDir
scala/version-declaredscalaprojectDir

All collectors

Buildnote Limited
Registered in England and Wales, Reg: 16140412