Skip to main content

Brightspot Gradle plugins reference

This page describes every setting, check, and plugin in the Brightspot Gradle plugins. For the recommended configuration and the most common overrides, see Brightspot Gradle plugins.

Requirements​

  • Gradle 8.4 or higher. Some features need a higher version:
  • Java 11 or higher to run the build. The build can produce Java 8 classes; see versions.java.

Plugins​

Apply com.brightspot.gradle in settings.gradle. It supplies all of the other plugins, so apply them in each subproject's build.gradle without a version.

PluginApply inPurpose
com.brightspot.gradlesettings.gradleConfigures every project in the build. Required.
com.brightspot.java-corecore/build.gradleJava code for a delivery project.
com.brightspot.java-librarylibrary subprojectsJava code published as a JAR.
com.brightspot.warweb/build.gradleBuilds the WAR file. See WAR.
com.brightspot.viewgenfrontend/build.gradleGenerates view classes from the root styleguide. See Viewgen.
com.brightspot.bundleeach bundle's build.gradleBuilds a front-end bundle. See Bundle.
com.brightspot.jakarta-substitutionweb/build.gradleMigrates Java EE to Jakarta EE in the WAR. See Jakarta EE substitution.
com.brightspot.sonarnoneConfigures SonarQube. com.brightspot.gradle applies it. See SonarQube.
com.brightspot.spotlessany Java subprojectFormatting. Applied automatically by plugin = true.
com.brightspot.error-proneany Java subprojectError Prone and NullAway. Applied automatically by plugin = true.

All functionality is broken down into discrete plugins which you can use individually if the standard plugins are not appropriate for your project's needs. See the Javadoc on each plugin for details.

Gradle properties and command-line arguments​

buildNumber

Written to the generated build.properties for informational purposes. Set as a command-line argument; defaults to local.

1
./gradlew -PbuildNumber=123 build

codePath

Used to generate code paths in the generated build.properties file. Required for reloader support in local development. Defaults to the project's root directory. gradle.properties

1
systemProp.codePath=/code

release

Marks the build as a release. It sets the release version for the project and can change release-specific behavior, such as the Maven repository that artifacts publish to. Without it, the version is the versions.project value.

1
./gradlew -Prelease=1.0.0 build

brightspot.test.maxHeapSize

Heap size for test workers; defaults to 1g. Set it in the project's gradle.properties, not in a user or CI runner gradle.properties. The value is part of the test task's cache key, so a value that is different on one machine stops that machine from sharing test results with other machines. gradle.properties

1
brightspot.test.maxHeapSize=2g

brightspot.test.mockitoAgent

Whether test workers start with Mockito as a Java agent; defaults to true. Set it to false to turn off the agent. See Tests. gradle.properties

1
brightspot.test.mockitoAgent=false

disableLocalCache

Turns off the local build cache for one run.

1
./gradlew -DdisableLocalCache build

brightspot.color

The plugins show the advice at the end of the build in a red banner, with each command in bold. By default, Gradle decides: it shows the colors in a terminal, and plain text when the output goes to a file or a pipe, in CI, or with --console=plain. Set brightspot.color=true to always use colors, or false to never use them.

1
./gradlew -Pbrightspot.color=false build

brightspot.upgradeCheck.cacheTime

How long Gradle keeps the lists of versions that brightspotUpgradeCheck and brightspotGradleUpgradeCheck read. The default is 1h. Write a number and a unit: s, m, h, or d. A number without a unit is in minutes. 0 lists the versions again on every build. Gradle keeps no list from a file: repository.

1
./gradlew -Pbrightspot.upgradeCheck.cacheTime=30m build

brightspot.columns

The width of the terminal, to which the plugins wrap the advice at the end of the build. The plugins use the COLUMNS environment variable instead when the shell exports it. The default is 80. Gradle runs the plugins in a background process, which cannot read the width of your terminal, so set it once in ~/.gradle/gradle.properties:

1
brightspot.columns=135

BOM check properties

bomConsistencyFail, bomOverlap, bomOverlapPlatforms, and bomOverlapExclusions can also be given as Gradle properties, for a one-off run without editing settings.gradle. List values are comma-separated. A value set in settings.gradle takes precedence over the Gradle property. enforcedBomDowngradeExclusions can also be given as a comma-separated Gradle property. brightspot.failOnDeprecatedDependencies makes relocationDependencyCheck fail the build. bomJavaTargetAllowLower is available only as a Gradle property. See Build checks and tasks.

1
./gradlew -PbomConsistencyFail=false -PbomOverlap=true build

The brightspot block​

These settings go in the brightspot block in settings.gradle. Each one applies to every project in the build.

Required settings​

projectGroup

Group used for generated artifacts.

1
brightspot {
2
projectGroup = 'com.example'
3
}

versions.java

See versions.

dependencies​

A dependencies block that applies to every subproject that uses a Brightspot Java plugin: java-core, java-library, war, bundle, and viewgen. It declares the BOMs and version constraints for the whole build in one place.

1
brightspot {
2
dependencies {
3
implementation enforcedPlatform('com.psddev:brightspot-bom:5.0.8')
4
implementation enforcedPlatform('com.psddev:brightspot-dependencies:5.0.8')
5
sharedTest enforcedPlatform('com.brightspot.shared-tests:bom:1.6.1')
6
}
7
}
  • Delivery projects declare platforms on implementation. Plugin projects declare them on api, so that their published poms include them.
  • Platforms on implementation or api also apply to the sharedTest and annotationProcessor configurations, so version-less annotation processors resolve, such as com.psddev:javadoc-annotationprocessor.
  • Declare the shared tests BOM on sharedTest only.
  • Delivery projects use enforcedPlatform. Plugin projects use platform.
  • Set versions in the nested blocks:
    • constraints for a module that no BOM manages, or to raise one above a plain platform;
    • pins to move a module that a BOM manages above or below the BOM's version;
    • substitutions and exclusions to replace or remove modules.
  • Each entry of these blocks can give its reason with Gradle's because; see Reasons.

These pairs of BOMs must have the same version as each other. The versionConsistency check fails the build if they do not.

ProductBOMs
Brightspotcom.psddev:brightspot-bom, com.psddev:brightspot-dependencies
Brightspot Gocom.brightspot.go:bom, com.brightspot.go:go-dependencies
Component Libcom.psddev.component-lib:bom, com.psddev.component-lib:cl-dependencies
Brightspot Migrationcom.psddev.migration:bom, com.psddev.migration:dependencies

If a project has neither this block nor a version catalog, the build logs a warning and version-less dependencies do not resolve.

Dependabot updates the versions in this block. See Dependabot.

constraints​

Gradle's own constraints block. It sets the lowest version of a module, in one configuration, without adding a dependency, and applies only when something else in the graph pulls the module in.

1
brightspot {
2
dependencies {
3
constraints {
4
implementation 'com.some-group:some-artifact:1.2.3'
5
}
6
}
7
}
  • Use it for a module that no BOM manages, or, in a plugin project, to raise a module above its BOM.
  • An entry below the version that the configuration's BOMs manage does not change the version, so the build fails and names it. To keep a lower version, use a downgrade. An entry at the BOM's version stays: it gives the version to the configurations that the BOM does not reach.
  • In a delivery project, an enforced BOM wins over a constraint. To move a module that it manages, use pins.

pins​

Forces the version of a module that a BOM manages, in every configuration of every project, over the BOMs.

1
brightspot {
2
dependencies {
3
pins {
4
upgrade 'com.squareup.retrofit2:retrofit:2.11.0'
5
downgrade 'org.xerial:sqlite-jdbc:3.36.0.3'
6
}
7
}
8
}
  • upgrade must be above the version the BOMs manage, and downgrade below it. Where the BOMs disagree on a module, an upgrade must be above the lowest of their versions, and a downgrade below the highest.
  • When the build's only BOMs are those of the dependencies block, a pin that the BOMs moved past fails the build and is named: an upgrade that the BOMs now meet or pass, or a downgrade that the BOMs now meet or go under, no longer does anything. Remove it, or run brightspotDoctor, which removes it. When a build file or a project platform declares a BOM too, the BOMs reach only some configurations, so the pins apply as they are and the build does not judge them.
  • Where no BOM of a configuration manages the module, the pin applies as it is. The doctor moves a pin of a module that no BOM of the build manages into constraints.
  • A downgrade allows the downgrade: versionDowngradeCheck and bomConsistency skip the module. At the end of every build, versionDowngradeCheck lists each downgrade that still resolves below its BOM; its reason says why.
  • A module cannot have both an upgrade and a downgrade.

substitutions​

Adds, overrides, or removes dependency substitutions.

1
brightspot {
2
dependencies {
3
substitutions {
4
substitute 'com.some-group:some-artifact' using 'com.some-preferred-group:some-preferred-artifact'
5
substitute 'com.some-group:other-artifact' using 'com.some-preferred-group:other-artifact:1.0.0'
6
substitute 'com.some-group:local-artifact' using ':local-project'
7
keep 'javax.el:javax.el-api'
8
}
9
}
10
}
  • The version of the target is optional. Without one, the target takes the version of a pins entry, else the version its BOMs manage, else the version of a constraints entry, else the version that another dependency asks for.
  • A module with a version, group:name:version, substitutes only that version of it. group:name: with no version after the colon is the same as group:name.
  • A target that starts with : substitutes a project in the build.
  • keep removes a default substitution, so the module stays.

These substitutions apply by default. Each one replaces a module with the module that the platform standardizes on:

ModuleReplaced byVersion
commons-logging:commons-loggingorg.slf4j:jcl-over-slf4j2.0.18
org.springframework:spring-jclorg.slf4j:jcl-over-slf4j2.0.18
com.zaxxer:HikariCP-java7com.zaxxer:HikariCP4.0.3
io.swagger.core.v3:swagger-annotations-jakartaio.swagger.core.v3:swagger-annotations2.2.55
javax.xml.bind:jaxb-apijakarta.xml.bind:jakarta.xml.bind-api2.3.3
com.github.bbottema:jetbrains-runtime-annotationsorg.jetbrains:annotations26.0.1
com.google.android.tools:dxjunit:junit4.13.2
com.sun.mail:javax.mailcom.sun.mail:jakarta.mail1.6.8
javax.activation:activationcom.sun.activation:jakarta.activation1.2.2
javax.activation:javax.activation-apicom.sun.activation:jakarta.activation1.2.2
jakarta.activation:jakarta.activation-api (1.x only)com.sun.activation:jakarta.activation1.2.2
javax.annotation:javax.annotation-apijakarta.annotation:jakarta.annotation-api1.3.5
javax.el:javax.el-apiorg.glassfish:jakarta.el3.0.4
javax.inject:javax.injectorg.glassfish.hk2.external:javax.inject2.4.0
  • The version applies only when nothing else gives the replacement module one. When a BOM of the configuration manages it, imports included, the BOM's version applies, higher or lower. When the build pins it in pins, the pinned version applies. A dependency that asks for a higher version still wins.
  • The versions of the replacement modules keep the javax package. Their later versions use the jakarta package.
  • A substitution in the other direction removes the default. For example, substitute 'io.swagger.core.v3:swagger-annotations' using 'io.swagger.core.v3:swagger-annotations-jakarta:2.2.22' removes the default for io.swagger.core.v3:swagger-annotations-jakarta. Do not reverse a default without a reason: the doctor keeps the substitution, since removing it would change the dependencies, and lists it under "Needs a person".

exclusions​

Removes modules from every configuration, as group:name.

1
brightspot {
2
dependencies {
3
exclusions {
4
exclude 'com.some-group:some-unwanted-artifact'
5
}
6
}
7
}

Reasons​

Each entry of pins, substitutions, and exclusions takes an optional reason after because, as Gradle's own dependency declarations do. An entry of constraints takes it in Gradle's own form, a closure.

1
brightspot {
2
dependencies {
3
constraints {
4
implementation('com.some-group:unmanaged-artifact:1.2.3') { because 'no BOM manages it' }
5
}
6
pins {
7
upgrade 'com.squareup.retrofit2:retrofit:2.11.0' because 'fixes the timeout in 2.9.0'
8
}
9
substitutions {
10
substitute 'com.some-group:some-artifact' using 'com.some-preferred-group:some-preferred-artifact' because 'renamed'
11
keep 'javax.el:javax.el-api' because 'the server provides it'
12
}
13
exclusions {
14
exclude 'com.some-group:some-unwanted-artifact' because 'it duplicates classes of another module'
15
}
16
}
17
}
  • dependencyInsight shows the reason of a pin and of a constraint.
  • The doctor gives a reason to each version that differs from the BOMs and has none, such as because 'the BOMs manage 2.9.0'. It never changes a reason, and a reason goes only with its entry. It does not read comments; a comment stays where it is.

Settings properties that the blocks replace​

dependencyConstraints, dependencySubstitutions, dependencyExclusions, and allowedDowngrades in the brightspot block still work as before. brightspotDoctor moves them into the blocks above: a pin above the BOM's version into upgrade, one below it into downgrade, one of a module that no BOM manages into constraints, and an allowed downgrade into a downgrade at the version the build resolves. It removes an allowed downgrade of a module that the build does not resolve below its BOMs. When the build resolves the module at several versions, the allowed downgrade stays, and the doctor asks for a downgrade.

classEnhancers​

The class enhancers to run; defaults to ['com.psddev.dari.db.LazyLoadEnhancer', 'com.psddev.dari.db.QueryCommentEnhancer']. com.psddev.dari.util.JavadocEnhancer runs in addition to these whenever it is on the classpath, so do not list it; see Javadoc annotations. Changing this list causes the classes to be enhanced again.

1
brightspot {
2
classEnhancers = [
3
'com.psddev.dari.db.LazyLoadEnhancer',
4
]
5
}

A subproject can set its own classEnhancers in its build.gradle.

Javadoc annotations​

Every java-core, java-library, war, and viewgen subproject gets these without any configuration:

  • The com.psddev:javadoc-annotationprocessor annotation processor, which writes a *.javadoc.json resource for each class. It resolves in the brightspotJavadoc configuration and takes its version from the Brightspot BOM. If the BOM does not manage it, the subproject builds without it. Any other resolution or download failure of the processor or its dependencies fails the build.
  • com.psddev.dari.util.JavadocEnhancer, whenever the class is on the classpath of the class enhancement task.

A subproject that still declares the processor, or lists JavadocEnhancer in classEnhancers, builds without an error, and each runs once. Remove those declarations.

enhanceClasses and modifyClasses​

Whether to apply the class enhancement and class modification plugins; both default to true.

1
brightspot {
2
enhanceClasses = false
3
modifyClasses = false
4
}

enforcedBomDowngradeExclusions​

Modules that the enforcedBomDowngrade check does not report, as group:name. Use it when an enforced BOM holds a module back on purpose.

1
brightspot {
2
enforcedBomDowngradeExclusions = [
3
'com.some-group:some-artifact',
4
]
5
}

BOM check settings​

See Build checks and tasks for what each check does.

bomConsistencyFail

Whether bomConsistency and bomOverlap violations fail the build; defaults to true. Set it to false to report violations as warnings.

1
brightspot {
2
bomConsistencyFail = false
3
}

bomConsistencyExclusions

BOMs that bomConsistency ignores, as group:name.

1
brightspot {
2
bomConsistencyExclusions = [
3
'io.grpc:grpc-bom',
4
]
5
}

bomOverlap

Whether bomOverlap runs; defaults to false for delivery projects and true for plugin projects.

1
brightspot {
2
bomOverlap = true
3
}

bomOverlapPlatforms

The platforms whose managed coordinates a project must not set a version for, as group:name. Defaults to the shared dependencies BOM and its JDK overlays: com.brightspot.dependencies:bom, bom-java8, bom-java11, and bom-java21. Platforms that are not in the dependency graph are ignored.

1
brightspot {
2
bomOverlapPlatforms = [
3
'com.brightspot.dependencies:bom',
4
]
5
}

bomOverlapExclusions

Coordinates that bomOverlap ignores, as group:name. Use it only when a local version must be different from its manager on purpose, such as a plugin that ships a different major version of a library that an upstream plugin also carries.

1
brightspot {
2
bomOverlapExclusions = [
3
'org.apache.solr:solr-solrj',
4
]
5
}

buildProperties​

Which values the generated build.properties includes; both default to true.

1
brightspot {
2
buildProperties {
3
buildNumber = false
4
gitCommits = false
5
}
6
}

versions​

java

The Java version to compile classes for; required. Plugin projects compile with a Java 21 toolchain for any value; this value sets the bytecode target.

1
brightspot {
2
versions {
3
java = 21
4
}
5
}

project

The version of the project's artifacts; defaults to '1.0.0-SNAPSHOT'. Plugin projects default to '9999-SNAPSHOT'.

1
brightspot {
2
versions {
3
project = '2.0.0-SNAPSHOT'
4
}
5
}

basePrefix

The prefix for the versions of subprojects that are not BOMs; not set by default. Set it only in library projects that publish a BOM.

1
brightspot {
2
versions {
3
basePrefix = '2.0'
4
}
5
}

enforcePlatform

Applies only to BOMs from a version catalog. See that section.

Version catalog​

Existing projects can declare their Brightspot BOMs in a version catalog named brightspotLibs in dependencyResolutionManagement. New projects use the dependencies block instead.

1
dependencyResolutionManagement {
2
versionCatalogs {
3
brightspotLibs {
4
library('brightspot', 'com.psddev:brightspot-bom:5.0.8')
5
library('brightspotDependencies', 'com.psddev:brightspot-dependencies:5.0.8')
6
library('brightspotSharedTests', 'com.brightspot.shared-tests:bom:1.6.1')
7
}
8
}
9
}

The plugins read these aliases:

AliasBOM
brightspotcom.psddev:brightspot-bom
brightspotDependenciescom.psddev:brightspot-dependencies
brightspotSharedTestscom.brightspot.shared-tests:bom
brightspotGocom.brightspot.go:bom
brightspotGoDependenciescom.brightspot.go:go-dependencies
componentLibcom.psddev.component-lib:bom
componentLibDependenciescom.psddev.component-lib:cl-dependencies
brightspotMigrationcom.psddev.migration:bom
brightspotMigrationDependenciescom.psddev.migration:dependencies

versions.enforcePlatform controls whether these BOMs apply as enforcedPlatform or platform. It defaults to true (enforcedPlatform) for delivery projects and false for plugin projects.

1
brightspot {
2
versions {
3
enforcePlatform = false
4
}
5
}

Build checks and tasks​

Most checks run before compilation, so a failure stops the build early.

When a build fails on its dependencies, Gradle shows this line under "Try":

1
Run ./gradlew brightspotDoctor: it explains many of these failures, and fixes some of them.

Before Gradle 8.14, and on a build that reuses a configuration cache entry, the line shows above the failure, after This build failed on its dependencies. The line does not show on a build that runs brightspotDoctor, brightspotGradleUpgrade, or brightspotGradleRewrite.

Properties file encoding​

validateEncoding runs as part of check and fails the build if a .properties file does not have UTF-8 encoding. The advice at the end of the build names the command. To convert the files, run the following command, then commit the changes:

1
./gradlew convertEncoding

versionConsistency​

Fails the build if the two BOMs of a product pair have different versions. See the table in dependencies. Delivery projects only.

versionDowngradeCheck​

Fails the build if a dependency substitution downgrades a version that a BOM manages. Declare a downgrade to allow a module's downgrade. At the end of every build, it lists the allowed modules that resolve at another version than their BOM manages. Delivery projects only.

enforcedBomDowngrade​

Reports when an enforced BOM holds a module below the version that a dependency asks for. An enforced platform wins over conflict resolution, so that dependency runs against the older, pinned version. It names the module, the pinned version, the requested version, the dependency that asked for it, and the BOM that declares the pin, in build/reports/enforced-bom-downgrade.txt. It runs as part of check, and before war in WAR projects. In WAR projects it gives the findings in the advice at the end of the build; in the others it logs them at info level. It never fails the build. Modules the build already sets with a constraint or a substitution are not reported. To silence a deliberate hold, add the module to enforcedBomDowngradeExclusions. Delivery projects only.

relocationDependencyCheck and relocateApply​

relocationDependencyCheck lists the declared dependencies that have moved to new coordinates in the advice at the end of the build. To fail the build instead, pass -Pbrightspot.failOnDeprecatedDependencies=true. Delivery projects only. To rewrite them in your build scripts, run the following command, then review and commit the changes:

1
./gradlew relocateApply

relocateApply replaces each relocated dependency with its new coordinate, without a version.

bomConsistency​

Checks each BOM in the dependency graph whose name ends in -bom, such as jackson-bom. It reports modules of a BOM that resolve to a different major.minor version than that BOM declares, including Jackson modules that do not match the Jackson BOM. The usual causes are a substitution, a forced version, or a transitive dependency. It skips the modules of downgrade pins and the BOMs of bomConsistencyExclusions. Violations fail the build unless bomConsistencyFail is false.

bomOverlap​

Reports coordinates that have a manager but that the project also sets a version for, with a constraint or with a versioned dependency. A coordinate has a manager when one of these supplies it:

  • A platform in bomOverlapPlatforms.
  • Another Brightspot plugin on the compile classpath: a com.brightspot.* module outside the build's own group.

It runs only in plugin projects, unless you set bomOverlap to true. A published POM contains its resolved versions, so a local version on a managed coordinate goes to every project that consumes the plugin.

bomJavaTarget​

Compares the dependencies BOM tiers that the project imports, such as bom-java21, with versions.java. An unsuffixed com.brightspot.dependencies:bom counts as the Java 8 tier.

  • In every project, it fails the build when a tier is higher than the Java target. This failure cannot be changed to a warning.
  • In plugin projects, it also fails the build when the highest tier is lower than the tier for the Java target, which is the highest bom-javaN at or below it. A Java 21 plugin on bom-java11 misses the Java 21 versions. To accept a lower tier, pass -PbomJavaTargetAllowLower=true.

brightspotGradleUpgrade​

Moves the build to the latest release of these plugins, and applies the conventions of that release.

1
./gradlew brightspotGradleUpgrade

It sets the latest release in settings.gradle, or in gradle.properties when a property holds the version. Then it runs brightspotGradleRewrite of that release in a second build, since the build that runs it uses the rules of the release it started with. If the build is on the latest release, it does nothing. Usually, run brightspotUpgrade, which moves the plugins the same way, commits the move, and then runs the doctor and the upgrade of the new release.

  • It upgrades only to releases, never to a pre-release such as 3.14.0-rc.1. To try a pre-release, set its version in settings.gradle by hand.
  • It does not run when the git working tree has changes. To run it anyway, add --allow-dirty.
OptionEffect
--checkChanges nothing, unless -Pbrightspot.doctor.version is set: then it shows the edit as a diff and fails.
--allow-dirtyRuns when the git working tree has changes.
-Pbrightspot.doctor.version=<version>Moves to this release of the plugins instead of the latest one.

brightspotGradleUpgradeCheck​

Notes a newer release of these plugins at the end of the build. It never changes a file and never fails the build. It runs before every Java compilation, from the root project, like brightspotUpgradeCheck: it finds the releases through the repositories of the build, so Gradle keeps the list for brightspot.upgradeCheck.cacheTime, and the check is up to date or comes from the build cache until then.

1
The Brightspot plugins 3.15.0 are available; this build uses 3.14.2.
2
3
Apply: ./gradlew brightspotUpgrade

It notes the same release that brightspotGradleUpgrade moves to.

brightspotGradleRewrite​

Brings the Gradle files of a build to the current conventions of these plugins.

1
./gradlew brightspotGradleRewrite

Usually, run brightspotDoctor, which runs this task and commits its changes.

It does these steps:

  1. It edits settings.gradle, the build.gradle files, gradle.properties, and the Gradle wrapper. It removes settings that the plugins apply by default, moves the version catalog and the root build.gradle to the brightspot block, and moves versions from the build.gradle files to the BOMs or to constraints. It does not change a resolved version. A version below a BOM stays, as a downgrade whose reason names the BOM's version and the forced one. Only brightspotUpgrade removes the overrides at or above the versions that an upgraded BOM managed before the upgrade. It removes the pins that no longer apply, and moves the settings properties that the blocks replace into pins, constraints, substitutions, and exclusions. Where the enforced BOMs disagree on a module, it pins the version that the build resolves. It sets the maximum heap of the Gradle daemon (-Xmx in org.gradle.jvmargs) to 2g when it is smaller or not set. A larger value stays.
  2. It compares the resolved dependencies before and after its edits, and shows each version that changed.
  3. It decides the configuration cache, when gradle.properties does not set it.
  4. It does not commit. brightspotDoctor commits its edits.
  5. It writes a report to the console and to build/reports/brightspotGradleRewrite/report.json.
  • The doctor runs only when the build evaluates on its release of the plugins. Before the first run, do the manual steps in Automated upgrade.
  • The doctor does not run when the git working tree has changes, so that git checkout . undoes its edits. To run it anyway, add --allow-dirty.
  • Review the edits with git diff before you commit them.
  • A reason from the doctor marks a version that is different from the BOMs'. Replace it with your own reason, or remove the entry.
  • The report lists what the doctor cannot change. Change those items yourself.
OptionEffect
--checkShows the edits as a diff and fails when there are edits, but changes no file. Use it in CI.
--allow-dirtyRuns when the git working tree has changes.

To decide the configuration cache, the doctor runs a child build of build --rerun-tasks --configuration-cache --continue, so that every task runs. Each test task runs its own actions, such as a doFirst, but selects no tests. Then it stores the cache of the whole build with --dry-run. It runs this build only when gradle.properties sets neither org.gradle.configuration-cache nor org.gradle.unsafe.configuration-cache, and not with --check.

  • If the build succeeds, the doctor adds org.gradle.configuration-cache=true to gradle.properties. A build that fails only on compilation or on a verification task, such as buildHealth, spotlessCheck, or Checkstyle, with no cache problems, counts as a success.
  • If Gradle finds problems as it stores the cache, or a task fails on the configuration cache as it runs, the doctor adds org.gradle.configuration-cache=false, after a comment that lists each problem. A task that failed gives the line of the build script that its stack trace names:
    1
    # The configuration cache is off, since it does not support these yet. Fix them, then set this to true.
    2
    # core/build.gradle:12: Execution failed for task ':core:test'. > Cannot reference a Gradle script object from a Groovy closure as these are not supported with the configuration cache.
    3
    org.gradle.configuration-cache=false
    Fix the problems, then set the value to true.
  • If the build fails for another reason, the doctor changes nothing and shows the failure. The setting stays undecided, so the next run of the doctor checks again.

The build leaves out the checks that note upgrades, which the build that runs the doctor already ran. It also leaves out brightspotRewriteCheck, which fails when upgrade recipes are pending. The build selects no tests, so a problem that shows only while a test itself runs can still fail a later build with the cache. To repeat the probe, run ./gradlew build --rerun-tasks --configuration-cache --continue -Pbrightspot.doctor.configurationCacheProbe=true.

note

Starting in plugin version 3.14.1, the probe runs the test task actions. In earlier versions, the probe runs build -x test, so it runs no test task actions, and the comment that the doctor writes does not give the line of the build script.

In a plugin project, the doctor keeps the published POM the same:

  • It does not edit the files that come from the plugin template: bom/ and .github/.
  • It keeps forced versions (resolutionStrategy.force), because a constraint does not force a version.
  • It moves versions of test dependencies to testImplementation constraints in the brightspot block, not to api constraints, so that they stay out of the POM.
  • It removes a BOM that a build.gradle file declares again only when the brightspot block declares the same BOM at the same version.
  • It adds a product BOM to the brightspot block only when the BOM changes no resolved version.

brightspotGradleRewriteCheck​

Notes, at the end of the build, that brightspotGradleRewrite would change the Gradle files. To see which of its rules would change them, run ./gradlew brightspotGradleRewriteCheck --rerun --info: the check is cacheable, and it lists the rules only when it runs. It never changes a file and never fails the build.

1
The Gradle files do not follow the Brightspot Gradle Plugin conventions.
2
3
Apply: ./gradlew brightspotDoctor

It runs before every Java compilation, from the root project, and runs only the rules that read the Gradle files: settings.gradle, the build.gradle files, gradle.properties, and the Gradle wrapper properties. It is up to date, or comes from the build cache, until one of these files changes. The rules that read resolved dependencies, such as those that remove versions a BOM manages, need a full run of the doctor. brightspotUpgradeCheck notes the most common of those: the versions that a BOM makes redundant.

brightspotRewriteCheck​

Fails the build when the classpath brings upgrade recipes that the build has not run. Libraries publish upgrade recipes that change the code of the projects that use them, across a breaking change such as a renamed class or method.

The check runs before every Java compilation in each java-core, java-library, and war subproject. It compares the recipes on the testCompileClasspath with the ledger. If there is no ledger, every recipe is pending. When recipes are pending, the build fails with a message such as this one:

1
These upgrade recipes have not run on this project: [com.example.MigrateOldType]. Run ./gradlew brightspotDoctor to run them, ./gradlew brightspotDoctor --recipe=com.example.MigrateOldType to run one, or ./gradlew brightspotDoctor --recipe=com.example.MigrateOldType --acknowledge="<reason>" if it was applied by hand.

To upgrade a dependency:

  1. Change its version, or the version of its BOM, by any means: by hand, or with Dependabot or Renovate.
  2. If the build fails at brightspotRewriteCheck, run ./gradlew brightspotDoctor.
  3. Review the commits that the doctor made.

The check reads the jars only when the resolved dependencies or the ledger change.

brightspotDoctor​

Runs the pending upgrade recipes, brings the Gradle files to the current conventions of the plugins, and commits each change. Run it after a version change, or when brightspotRewriteCheck fails.

1
./gradlew brightspotDoctor

brightspotDoctor runs two other tasks and makes the git commits. Only it commits.

TaskWhat it doesCommits
brightspotDoctorRuns the two tasks below, and commits their changes.Yes
brightspotGradleRewriteEdits the Gradle files, and decides the configuration cache.No
brightspotRewriteRuns the pending upgrade recipes, and writes the files, the ledger, and a record of the changes.No

It does these steps:

  1. It fails if the git working tree has changes, even when no recipe is pending, so that each commit holds the changes of one step only.
  2. It runs brightspotGradleRewrite, with the same --check and --allow-dirty options. It does not change the release of the plugins; brightspotUpgrade does. It commits the other edits as build: apply the brightspotGradleRewrite fixes. The commit lists each fix by file; for each override it removes, it says why, such as the BOMs manage this version.
  3. It commits gradle.properties as build: enable the configuration cache or build: disable the configuration cache, when brightspotGradleRewrite decided the configuration cache.
  4. If modules do not resolve, it stops. brightspotGradleRewrite lists them under "Does not resolve" in its report, with what to do.
  5. It runs brightspotRewrite with the same --recipe, --acknowledge, and --check options, on the edited build. If the Gradle files changed, the doctor starts a child build for this step.
  6. It commits the changes of each recipe, with the ledger, as refactor: apply <recipe>, in the order that the recipes ran. When you acknowledge recipes, it makes one commit of the ledger, named chore: acknowledge <recipes>.
  7. In a delivery build, it runs bomConsistency and versionDowngradeCheck, and adds each module that they report as a downgrade. It commits this as fix(deps): allow the BOM modules that bomConsistency rejects. It changes no version.
  8. When a project of the build applies Error Prone, it compiles the code. For each Error Prone check that fails, it writes the fix that Error Prone suggests to the sources, and commits them as fix: apply the Error Prone fixes. Errors without a suggested fix, such as those of NullAway, stay.
  9. In a plugin build, it applies the advice of the dependency analysis (buildHealth) to the build.gradle file of each project, and commits it as fix(deps): apply the buildHealth advice. It adds a module that a BOM manages without a version. Each change can change the advice, so it runs the analysis again until there is none, at most three times. Advice it cannot apply, such as for a dependency that the settings or the plugins declare, shows under "Needs a person".
  10. When a project of the build enforces Spotless, it runs spotlessApply and commits the files that it changed as style: apply spotlessApply.

The commit messages follow Conventional Commits, with lines of at most 100 characters, so that a repository with commitlint accepts them.

If no recipe is pending, it shows Up to date: every recipe on the classpath has run.

With --allow-dirty, the doctor does not commit the files that had changes before it started. If a recipe changes one of these files, the doctor puts back the files that the recipes changed and the ledger, as they were before the recipes ran, with your changes, and fails. The recipes stay pending. Commit or stash your changes and run the doctor again, or add --no-commit. Outside a git repository, the doctor changes the files but commits nothing.

OptionEffect
--recipe=<name>Runs only this pending recipe. Repeat the option to name more recipes. They run in their usual order.
--recipe=<name> --acknowledge="<reason>"Records the recipe in the ledger as applied by hand, for this reason, and does not run it. It does not run brightspotGradleRewrite. --acknowledge needs --recipe.
--checkShows the pending changes as a diff and fails when there are changes, but changes no file.
--no-commitChanges the files and the ledger, but commits nothing.
--allow-dirtyRuns when the git working tree has changes.
--skip-buildRepairs only the Gradle files, the dependencies, and the upgrade recipes. It skips the steps that compile or format the code: the configuration cache probe, Error Prone, the buildHealth advice, the properties file encodings, and Spotless.
-Pbrightspot.doctor.gradle=falseDoes not run brightspotGradleRewrite, and does not decide the configuration cache.

A --recipe name that is not pending fails with These recipes are not pending, followed by the pending recipes.

A recipe runs only on Java sources. If no subproject has Java sources, the recipe stays pending, and the doctor shows a warning. To record it, use --acknowledge.

Upgrade recipe ledger​

gradle/brightspot.rewrite.properties records the upgrade recipes that the build has run, by name. Commit it.

1
# Recipes this project has run, kept by the Brightspot rewrite tasks. Commit this file.
2
recipe.com.example.MigrateOldType=run
3
recipe.com.example.RenameMethod=acknowledged\: Changed by hand
  • The value is run for a recipe that a task ran, and acknowledged: <reason> for a recipe that --acknowledge recorded. The : has a \ before it, as in all .properties files.
  • The ledger is at the root of the build, and applies to all subprojects. A recipe runs once per build, identified by its name, whichever version of a library brings it.
  • brightspotRewrite creates the ledger when it runs or acknowledges the first recipe.
  • Without a ledger, every recipe on the classpath is pending. A recipe changes only code that uses the old API, so code that does not use it stays the same.
  • The lines are sorted by name, so that merges seldom conflict.

brightspotRewrite​

Runs the pending upgrade recipes on the Java sources of the main and test source sets of every Java subproject.

1
./gradlew brightspotRewrite

Usually, run brightspotDoctor, which runs this task and commits its changes.

It does these steps:

  1. It finds the recipes on the classpath that the ledger does not have, or only the recipes that you name. The recipes of a library run in the order that the library declares them.
  2. It runs them on the code as it is, and writes the changed files. It does not change files that git ignores, or files in a build directory.
  3. It sorts the imports of each file that a recipe changes, in the import layout that the project already uses. If it finds no layout, it does not change the imports. It never replaces imports with a wildcard import.
  4. It records the recipes in the ledger.
  5. It writes a record of what each recipe changed to build/brightspotRewrite/record/record.json. brightspotDoctor reads the record to make its commits.
  • It does not commit, does not examine the git working tree, and does not run brightspotGradleRewrite.
  • It works with the configuration cache.
OptionEffect
--recipe=<name>Runs only this pending recipe. Repeat the option to name more recipes. They run in their usual order.
--recipe=<name> --acknowledge="<reason>"Records the recipe in the ledger as applied by hand, for this reason, and does not run it. --acknowledge needs --recipe.
--checkShows the pending changes as a diff and fails when a recipe is pending, but changes no file.

Advice​

At the end of the build, after the output of every task, the plugins show one block of advice:

1
======================== Advice from Brightspot ========================
2
Brightspot upgrades are available:
3
com.psddev:brightspot-bom 5.0.8 -> 5.0.9 patch
4
with com.psddev:brightspot-dependencies
5
6
Apply: ./gradlew brightspotUpgrade
7
8
See build/reports/brightspotUpgrade/report.txt
9
------------------------------------------------------------------------
10
The Gradle files do not follow the Brightspot Gradle Plugin conventions.
11
12
Apply: ./gradlew brightspotDoctor
13
------------------------------------------------------------------------
14
Relocated dependencies in :core:
15
These dependencies moved to new coordinates.
16
A future release removes the old coordinates.
17
Declare the new coordinates, and each dependency listed as missing.
18
19
com.psddev:dari-util
20
moved to com.brightspot.util:web-util:1.1.1
21
22
Apply: ./gradlew :core:relocateApply
23
------------------------------------------------------------------------
24
Enforced BOMs hold back requested dependency versions (1):
25
26
com.zaxxer:HikariCP: 7.0.2 -> 3.4.5
27
com.brightspot.db:db:3.1.1 wants 7.0.2, but
28
com.psddev:brightspot-dependencies:5.0.9 enforces 3.4.5
29
30
To use a requested version, pin it in settings.gradle:
31
brightspot {
32
dependencies {
33
pins {
34
upgrade 'com.zaxxer:HikariCP:7.0.2'
35
}
36
}
37
}
38
To raise the version in the BOM, contact the maintainers of:
39
com.psddev:brightspot-dependencies:5.0.9
40
To stop reporting a module, add it to enforcedBomDowngradeExclusions.
41
========================================================================
  • In the enforcedBomDowngrade section, 7.0.2 -> 3.4.5 means the requested version, then the version that the enforced BOM holds the module at. The section ends with what to do instead of an Apply: line, and build/reports/enforced-bom-downgrade.txt has the details.
  • A line of - separates the sections, one for each kind of advice. A task that runs in several projects, such as enforcedBomDowngrade in each WAR project, gives one section for all of them.
  • Each instruction is on a line of its own: Apply: ./gradlew <task> for a task that changes the build, Run: ./gradlew <task> for one that changes nothing.
  • The banner is red, and each command is bold; see brightspot.color.
  • The text wraps at spaces to the width of the terminal, and the banner is as wide as the longest line. A command never breaks. The width is the COLUMNS environment variable when the shell exports it, else brightspot.columns, else 80.
  • The advice comes from the tasks that ran: brightspotUpgradeCheck, brightspotGradleUpgradeCheck, brightspotGradleRewriteCheck, relocationDependencyCheck, enforcedBomDowngrade, and validateEncoding. A task that was up to date or came from the build cache gives its advice too.
  • When a task fails, the block shows only the advice of the failed tasks, before the failure. When nothing has advice, the build shows no block.

brightspotUpgradeCheck​

Lists the newer versions of the BOMs and other versions that settings.gradle declares. It never changes a file and never fails the build. It runs before every Java compilation, from the root project.

It reads the root settings.gradle. It does not read a settings.gradle.kts file or the version catalog. It checks these versions:

  • The platform(...) and enforcedPlatform(...) BOMs of the dependencies block. The BOMs that the main list of the upgrade policy names are in the main list. The other BOMs are in the second list.
  • The versions of pins and constraints, and the target versions of substitutions, in the second list.

A version can be a property of gradle.properties, such as "com.psddev:brightspot-bom:$brightspotVersion".

The check finds the versions through the repositories of the build, with their credentials. Gradle keeps the list of versions for one hour, or for brightspot.upgradeCheck.cacheTime, so a new release can take that long to show. Until then the check makes no network request. --refresh-dependencies gets a new list, and brightspotUpgrade always gets a new list before it upgrades. With --offline, the check uses the list that Gradle has kept. A module that it cannot check, for example offline with no kept list, is counted as "could not be checked", and the build continues.

Parent BOMs​

The check reads the POM of each declared BOM, with the BOMs it imports, at its current version and at each version it can be upgraded to. A declared BOM that manages another declared module or BOM is a parent. For example, com.psddev:brightspot-dependencies imports the BOMs of com.brightspot.ai, com.brightspot.db, and com.brightspot.ui, so it is the parent of the constraints and BOMs of those groups.

The check compares each other declaration with the version that its parent manages after the upgrade:

  • If the declaration is at that version or below it, brightspotUpgrade does not upgrade it.

    • When brightspotUpgrade moves the parent, it removes the declaration if the declaration was at or above the version that the parent managed before, so that the parent manages the version. See step 7 of brightspotUpgrade. A declaration below that old version is a downgrade, and stays.
    • Without an upgrade, the doctor removes a declaration at the parent's version, and keeps one below it as a downgrade.

    The doctor keeps a version that chooses between BOMs that manage different versions, a downgrade, a constraint on the target of a substitution, and every substitution.

  • If the declaration is above that version, or the doctor keeps it, its newer versions show under "Other upgrades (not recommended)". brightspotUpgrade changes it only when you name it with --module.

Thus the BOMs manage as many versions as they can, and the overrides go away over time. brightspotUpgrade changes a declaration that no parent manages, such as a library that the BOMs do not include, only when you name it with --module.

The check also reads the versions in the build.gradle file of each project (Groovy only). It does not upgrade them. It counts the versions that a parent BOM manages after the upgrade. Without an upgrade, the doctor removes a version at the parent's version, keeps one below it as a downgrade, and asks why one above it differs. After an upgrade, brightspotUpgrade removes the versions at or above those that the BOM managed before the upgrade:

1
3 versions in build files are managed by com.psddev:brightspot-dependencies:5.0.8; brightspotUpgrade removes those at or above the versions in com.psddev:brightspot-dependencies:5.0.4, and brightspotDoctor allows those below them or asks why they differ.

Output​

At the end of a build that runs the check, after the output of the other tasks, the build shows the upgrades:

1
Brightspot upgrades are available:
2
com.psddev:brightspot-bom 5.0.4 -> 5.0.8 patch
3
with com.psddev:brightspot-dependencies
4
com.brightspot.shared-tests:bom 1.5.8 -> 1.6.1 minor
5
6
Apply: ./gradlew brightspotUpgrade
7
8
Upgrades you can choose:
9
com.psddev.migration:bom + com.psddev.migration:dependencies 2.3.4
10
minor 2.4.0 ./gradlew brightspotUpgrade --module com.psddev.migration:bom --minor
11
12
20 versions are managed by com.psddev:brightspot-dependencies:5.0.8; brightspotUpgrade removes those at or above the versions in com.psddev:brightspot-dependencies:5.0.4, and brightspotDoctor allows those below them.
13
3 versions in build files are managed by com.psddev:brightspot-dependencies:5.0.8; brightspotUpgrade removes those at or above the versions in com.psddev:brightspot-dependencies:5.0.4, and brightspotDoctor allows those below them or asks why they differ.
14
15
4 other upgrades are available.
16
1 module could not be checked.
17
See build/reports/brightspotUpgrade/report.txt
18
19
The Brightspot plugins 3.15.0 are available; this build uses 3.14.2.
20
21
Apply: ./gradlew brightspotUpgrade
22
23
The Gradle files do not follow the Brightspot Gradle Plugin conventions.
24
25
Apply: ./gradlew brightspotDoctor

"Upgrades you can choose" lists the modules of the main list whose level allows no upgrade, with the commands for the higher levels. The last two lines come from brightspotGradleUpgradeCheck and brightspotGradleRewriteCheck. This text is part of the advice at the end of the build.

build/reports/brightspotUpgrade/report.txt has the full list:

1
Overrides with newer versions:
2
bom com.example.cms:bom 1.2.0 patch 1.2.3 minor 1.4.1
3
constraint com.fasterxml.jackson.core:jackson-databind 2.15.3 patch 2.15.4 minor 2.18.2
4
5
Other upgrades (not recommended):
6
constraint org.yaml:snakeyaml 1.29 (com.psddev:brightspot-dependencies:5.0.8 manages 2.5) minor 1.33 major 2.7
7
8
Versions that brightspotUpgrade removes:
9
constraint com.brightspot.ai:ai 3.1.0 (com.psddev:brightspot-dependencies:5.0.4 managed 3.0.0)
10
11
Versions that brightspotUpgrade moves to the BOM's version:
12
constraint com.brightspot.go:go 2.3.1 (com.psddev:brightspot-dependencies:5.0.4 managed 2.3.0)
13
14
Versions that brightspotUpgrade keeps:
15
site/build.gradle:14 com.brightspot.db:db 2.6.0 (com.psddev:brightspot-dependencies:5.0.4 managed 2.6.3)
16
17
Could not check: com.example:private-bom (No repository lists this module)

"Overrides with newer versions" also lists the BOMs outside the main list, such as com.example.cms:bom. "Versions that brightspotUpgrade removes", "moves to the BOM's version", and "keeps" list the versions that the upgraded BOMs manage, each with the version that the BOM managed before the upgrade (step 7 of brightspotUpgrade). A constraint is a pins entry, a legacy dependencyConstraints entry, or a constraints entry. A constraints entry is never under "removes".

To also list the release candidates of a newer version, run the check with --rc:

1
./gradlew brightspotUpgradeCheck --rc

It does not list a version that is not a version number, such as the range [1.0,2.0).

It writes these files:

  • build/reports/brightspotUpgrade/report.json, for CI. For each module, upgrades has the newest patch, minor, and major versions, and automatic is the version that brightspotUpgrade sets with no options, which only a BOM of the main list has. A module that a parent manages has managedBy, managedVersion, and redundant, which is true when the declaration can go: it is at the parent's version or, after an upgrade of the parent, at or below it. Of these, brightspotUpgrade removes only the declarations that were also at or above the version that the parent managed before (step 7 of brightspotUpgrade); a declaration below it is a downgrade, and stays. available is the number of modules with upgrades. buildFilePins lists the versions in build.gradle files that a parent manages, each with its file, line, managedBy, and managedVersion.
  • build/reports/brightspotUpgrade/report.txt, the full list.

The check works with the configuration cache. To keep the three checks that note upgrades out of compilation, set brightspot.upgradeCheck=false:

1
./gradlew -Pbrightspot.upgradeCheck=false build

Which version is an upgrade​

  • A level is the highest change, and includes the lower levels: patch is the newest version with the same major and minor numbers, minor the newest with the same major number, and major the newest version.
  • All numbers after the minor number are part of the patch: 4.1.112.1.Final is a patch upgrade of 4.1.112.Final.
  • An upgrade keeps the text after the numbers, such as .Final or -jre: 32.1.3-jre never moves to 33.0.0-android.
  • A release never moves to a pre-release, such as 5.0.9-rc.1, unless you add --rc to brightspotUpgrade.
  • A pre-release moves to its release, such as 5.0.9-rc.1 to 5.0.9. If there is no release yet, it moves to a newer pre-release of the same version, such as 5.0.9-rc.2. A suffix that starts with rc, cr, beta, alpha, pre, or M and a number marks a pre-release.
  • A suffix that no other published version shares, such as -hotfix.1 in 5.0.4-hotfix.1, is a branch tag, not a text such as -jre. The version counts as a pre-release of 5.0.4, so it moves to the main line like one.
  • Pull request, snapshot, and local builds, such as 5.0.9-pr.12.3, 5.0.9-SNAPSHOT, or 5.0.9-local.1, are never upgrades.

brightspotUpgrade​

Sets the versions that brightspotUpgradeCheck lists, commits each upgrade, and then runs brightspotDoctor, which repairs the build for the new versions.

1
./gradlew brightspotUpgrade

It does these steps:

  1. It fails if the git working tree has changes, or if the Gradle files do not follow the conventions that brightspotGradleRewriteCheck checks: then run brightspotDoctor first.
  2. It moves the build to the latest release of the plugins, as brightspotGradleUpgrade does, and commits it as build(deps): upgrade com.brightspot.gradle from <old> to <new>. Then it runs brightspotDoctor and brightspotUpgrade of the new release in second builds, and stops: the new release does the next steps. To keep the current release, add --no-plugin. -Pbrightspot.doctor.version=<version> moves to that release instead of the latest one.
  3. It chooses the versions. With no options, it moves only the BOMs of the main list of the upgrade policy, in the order of the list, each to its automatic version: the newest version within the level that the policy gives it. It moves no other declaration: the others are overrides or other libraries, which only --module upgrades. It does not change a module that a parent BOM manages.
  4. It changes the version in settings.gradle, or in gradle.properties when a property holds it.
  5. It commits each upgrade, such as feat(deps): upgrade com.brightspot.db:bom from 3.2.0 to 3.3.0. Modules that share a property of gradle.properties are in one commit.
  6. It keeps the versions that the upgraded BOMs no longer manage, where a module would not resolve without them, and commits this as feat(deps): keep the versions the upgraded BOMs no longer manage. A version is kept for a module that the build declares without a version when no other module pulls it in, or when the upgrade moves every module that pulls it in, since their new versions may not. The upgrade adds a constraints entry at the version the old BOM managed, with a reason:
    1
    implementation('com.example:some-library:1.4.0') { because 'com.example:bom:2.0.0 managed 1.4.0; the upgraded BOMs no longer manage it' }
    A module that pins already holds keeps its pin. When the doctor wrote the pin's reason, the reason changes to this one. Every other module that the BOMs no longer manage takes the version that Gradle resolves from the modules that ask for it.
  7. It removes the overrides that the upgraded BOMs moved over, and commits this as feat(deps): remove the overrides the upgraded BOMs moved over. An override goes when it was at or above the version that its parent BOM managed before, and the parent now manages its module at or above it:
    • An upgrade entry of pins, and a legacy dependencyConstraints entry, go.
    • A constraints entry moves to the BOM's version, for the configurations that the BOMs do not reach.
    • In the build.gradle file of a project that gets the BOMs, a version goes, and the dependency stays without one.
    • A BOM of a build.gradle file goes when the parents manage every module of it that the build resolves. Otherwise, an enforcedPlatform BOM whose modules the parents managed before becomes a platform.
    • A substitutions entry stays: its target version is only a lower bound, so the BOM's higher version wins.
  8. It runs brightspotDoctor in a second build, which reads the new versions. The doctor runs the upgrade recipes and makes its own commits.

If a module does not resolve after the upgrade, the doctor stops and lists it under "Does not resolve", with the BOM that manages it and this hint:

1
brightspotUpgrade changed the versions before this check, so the upgrade can be the cause; if the module resolved before the upgrade, pin the version it had then.

brightspotUpgrade then fails with brightspotDoctor failed on the upgraded build. The upgrade commits stay. Run ./gradlew dependencyInsight --configuration <configuration> --dependency <module> to see why the module does not resolve. If it resolved before the upgrade, add a pin at the version it had then, with a reason, commit it, and run brightspotDoctor again.

If there is nothing to upgrade, it shows Nothing to upgrade. and does not run the doctor. When a BOM of the main list is not on a release and no release within its level is newer, it stays, with a warning:

1
com.psddev:brightspot-bom, com.psddev:brightspot-dependencies stays at 5.0.9-rc.1, which is not a release: no release within the policy's level is newer.
OptionEffect
--module=<group:name>Upgrades only this module, to the level of the upgrade policy unless a level option follows. Repeat the option to name more modules. Any module that the check lists is allowed.
--patch, --minor, --majorUpgrades the modules named with --module to this level, not to their automatic version. Use one of them only, with --module.
--rcAlso upgrades to the release candidates of a newer version, within the level. A release that is newer than the release candidate wins.
--no-commitChanges the files but commits nothing. The doctor runs with --no-commit --allow-dirty.
--allow-dirtyRuns when the git working tree has changes. Files that had changes before the run are not committed.
--no-pluginKeeps the current release of the plugins: does not do step 2.
--skip-buildRuns brightspotDoctor with --skip-build, which skips the steps that compile or format the code.
1
./gradlew brightspotUpgrade --module=com.example.cms:bom --minor
2
./gradlew brightspotUpgrade --module=com.psddev:brightspot-bom --patch --rc

A --module that the check does not list fails with <module> is not a monitored dependency, followed by the modules that the check lists. A --module that a parent BOM manages at its version or above, after this upgrade, is not changed: a warning says that the doctor removes it.

Upgrade policy​

The plugins hold the policy that tells brightspotUpgrade which BOMs are in the main list, and how far to upgrade each module. The two settings are separate: the list a module is in does not change its level. A new release of the plugins can change the policy. A project cannot change it.

The main list, in the order that brightspotUpgrade moves them:

  1. com.psddev:brightspot-bom and com.psddev:brightspot-dependencies
  2. com.brightspot.go:bom and com.brightspot.go:go-dependencies
  3. com.psddev.component-lib:bom and com.psddev.component-lib:cl-dependencies
  4. com.brightspot.shared-tests:bom
  5. com.psddev.migration:bom and com.psddev.migration:dependencies
  6. The com.brightspot.dependencies BOMs whose name starts with bom-, such as bom-java21

The levels:

  • The Brightspot BOMs com.psddev:brightspot-bom and com.psddev:brightspot-dependencies of 4.8 and 5.0 get patch upgrades. Any other line, such as 4.7 or 5.1, also gets patch upgrades, and stays in the main list.
  • com.brightspot.go:bom and com.brightspot.go:go-dependencies get patch upgrades.
  • com.psddev.component-lib:bom and com.psddev.component-lib:cl-dependencies get patch upgrades.
  • com.psddev.migration:bom and com.psddev.migration:dependencies get patch upgrades.
  • Other modules whose group starts with com.brightspot get minor upgrades, and com.brightspot.cms-search-boost modules get major upgrades.
  • A module that the policy does not configure gets patch upgrades from brightspotUpgrade --module. The check shows its other levels: under "Upgrades you can choose" for a BOM of the main list, and in report.txt for the others.

Some BOMs always move together, to one version, in one commit:

  • com.psddev:brightspot-bom with com.psddev:brightspot-dependencies
  • com.brightspot.go:bom with com.brightspot.go:go-dependencies
  • com.psddev.component-lib:bom with com.psddev.component-lib:cl-dependencies
  • com.psddev.migration:bom with com.psddev.migration:dependencies

--module with one of them upgrades both. The version is the newest that both have.

Plugin projects​

warning

This section applies only to projects that publish libraries or plugins as JAR files to Artifactory. Do not set plugin = true in a delivery project, meaning a project that builds a WAR file to run on Tomcat.

plugin

Marks the build as a plugin project; defaults to false. Plugin projects require Gradle 8.11.1 or higher.

1
brightspot {
2
plugin = true
3
}

It applies the following:

  • Error Prone and NullAway, which inspect code marked with @NullMarked. WAR subprojects are skipped.
  • Spotless, which enforces formatting.
  • A Java 21 toolchain for compilation, and a Javadoc JAR.
  • The JUnit Platform for all test tasks.
  • Dependency analysis, as buildHealth in check. Any reported issue fails the build, and the advice at the end of the build says to run brightspotDoctor, which applies the analysis' advice.
  • The bundled Checkstyle configuration, in place of the project's etc/checkstyle/checkstyle.xml.
  • SonarQube and JaCoCo.
  • The bomOverlap check.

It changes these defaults:

  • versions.enforcePlatform is false, so BOM versions do not become hard requirements for the projects that consume the plugin.
  • versions.project is 9999-SNAPSHOT, so local subprojects win version conflicts against published artifacts.

It turns off these features, which are for delivery projects:

  • Shared tests
  • Git hash versioning
  • The versionConsistency, versionDowngradeCheck, enforcedBomDowngrade, and relocationDependencyCheck checks

Declare the BOMs in the dependencies block with platform, not enforcedPlatform. A published library must not force versions onto the projects that consume it.

1
brightspot {
2
plugin = true
3
projectGroup = 'com.brightspot.example'
4
5
versions {
6
java = 21
7
}
8
9
dependencies {
10
api platform('com.brightspot.dependencies:bom:2.0.1')
11
api platform('com.psddev:brightspot-bom:4.8.19')
12
api platform('org.junit:junit-bom:5.14.4')
13
14
constraints {
15
api 'org.apache.solr:solr-solrj:9.10.1'
16
}
17
}
18
}

testConfigFile

The config file to include in the JAR as brightspot-test-config.properties. The WAR's tests combine these files from the JARs on the runtime classpath. Relative paths start from <rootDir>/docker. Defaults to <project-name>.properties. If that default file does not exist, the plugin skips it. Applies only to com.brightspot.java-library subprojects.

1
brightspot {
2
testConfigFile = 'example.properties'
3
}

sonarProjectKey

The sonar.projectKey; defaults to perfectsense:<root project name>.

1
brightspot {
2
sonarProjectKey = 'perfectsense:example'
3
}

Formatting and static analysis

Spotless enforces import order, removes unused imports, applies the bundled Eclipse formatter configuration, trims trailing whitespace, and runs a set of CleanThat mutators. To apply the formatting:

1
./gradlew spotlessApply

After the Eclipse formatter, Spotless makes two more changes:

  • It keeps a jspecify @Nullable or @NonNull on the same line as the type it annotates, after the modifiers, such as public static @Nullable String find(). It changes only the jspecify annotations: those that the file imports from org.jspecify.annotations, or that it writes with that package.
  • It adds a blank line after an opening brace that is not on the line where its declaration or statement starts, such as the brace after a wrapped method signature or if condition. The body then does not line up with the last line of the header, which has the same indent. Lambdas, anonymous classes, and array initializers keep their braces as they are.

The formatter does not join consecutive line comments.

Plugin 3.14.0 added these rules, so the first spotlessApply after an upgrade to it changes many files. Until that runs, spotlessCheck fails the build. brightspotDoctor runs spotlessApply and commits the result.

Error Prone runs NullAway, which reports errors, not warnings. It inspects only code marked with @NullMarked.

To use either one in a build that does not set plugin = true, apply it in the subproject:

1
plugins {
2
id 'com.brightspot.spotless'
3
id 'com.brightspot.error-prone'
4
}

Publishing upgrade recipes​

A library can publish OpenRewrite recipes that change the code of the projects that use it, across a breaking change such as a renamed class or method. Those projects run the recipes with brightspotDoctor.

Put the recipes in the src/rewrite directory of a java-core, java-library, or war subproject. The plugins then do the following:

  • Add the rewrite source set, which compiles for Java 11 against org.openrewrite:rewrite-java. The plugins set the OpenRewrite version.
  • Add the rewriteTest source set for recipe tests, with org.openrewrite:rewrite-test and JUnit 5. The rewriteTest task runs the tests as part of check.
  • Publish the recipes in a jar with the rewrite classifier, and add the brightspot.rewrite property to the POM.
  • Add the list of recipes to the main jar, so that the brightspotRewriteCheck of a project finds them without running them.

The recipes run in a JVM that holds only the JDK, OpenRewrite, and the recipe jars. A recipe cannot use other libraries.

brightspotRewrite

Lists each entry recipe of the subproject, in the order that the recipes run; required. An entry recipe is a recipe in src/rewrite that no other recipe in src/rewrite lists.

1
brightspotRewrite {
2
recipe 'com.example.MigrateOldType', parseAgainst: ['com.example:example-lib:1.0.0']
3
recipe 'com.example.RenameMethod'
4
}

Give parseAgainst to a recipe that changes types that the new version of a library removed. Its values are the group:name:version of the artifacts that still have those types. The recipe then finds the old types in the code of a project that already uses the new version. Do not give parseAgainst to other recipes.

The build fails when this block and src/rewrite do not agree. If the block lists a recipe that src/rewrite does not define, correct or remove it. If src/rewrite defines an entry recipe that the block does not list, the build shows the block to use, with a placeholder for parseAgainst:

1
:example defines recipes that its brightspotRewrite block does not list: [com.example.RenameMethod].
2
3
List every recipe in the order they must run. Give each one that rewrites types a newer version removed the artifact that still has them, as parseAgainst, and leave parseAgainst out for the others. Then the build script of :example has:
4
5
brightspotRewrite {
6
recipe 'com.example.MigrateOldType', parseAgainst: ['com.example:example-lib:1.0.0']
7
recipe 'com.example.RenameMethod', parseAgainst: ['group:name:old-version']
8
}

Writing a migration recipe

  • Change only the files that use the old API. Do not include a recipe that changes every file, such as OrderImports or a formatter. brightspotRewrite sorts the imports of each file that a recipe changes.
  • Make sure that the recipe does not change code that is already migrated. A project without a ledger runs every recipe on its classpath.
  • Do not rename a published recipe. The ledger identifies a recipe by its name, so a recipe with a new name runs again in every project.
  • Test each recipe in src/rewriteTest.

requiredPluginVersion

The minimum version of these plugins that the projects that use the artifact need, as major.minor.patch. Set it in the build.gradle of the BOM subproject, so that every project that imports the BOM gets the requirement. For example, set it when the library publishes upgrade recipes.

1
plugins {
2
id 'java-platform'
3
}
4
5
javaPlatform {
6
allowDependencies()
7
}
8
9
brightspot {
10
requiredPluginVersion = '3.14.0'
11
}

A build with an older version of the plugins, or without the plugins, fails to resolve the BOM, with this reason:

1
com.example:bom:1.2.0 needs brightspot-gradle 3.14.0 or newer. In settings.gradle, set the version of the com.brightspot.gradle plugin to 3.14.0 or newer.

The requirement is a dependency on com.brightspot.gradle.requires:brightspot-gradle, which is never published. The plugins remove it from the BOM when their version is the same or newer. A pre-release, such as 3.14.0-rc.1, counts as the release it leads to. Do not resolve the BOM in the build that publishes it, for example with platform(project(':bom')), because there the build fails in the same way.

Bundle​

These settings go in each bundle's build.gradle file (typically under frontend/bundles/), in the bundle block.

yarnBuildCommand

The Yarn script that builds the bundle, from "scripts" in package.json; required. Typically 'build'.

styleguideOutputDir

The styleguide output directory, relative to the subproject's build directory; required. Typically 'styleguide'. The value usually comes from the build script in package.json.

zipOutputPath

The bundle .zip file, relative to the subproject's build directory; required. Typically 'theme.zip'. The value usually comes from the build script in package.json.

1
bundle {
2
yarnBuildCommand = 'build'
3
styleguideOutputDir = 'styleguide'
4
zipOutputPath = 'theme.zip'
5
}

cdnCssFiles

CSS files for CdnCssTest to test, relative to the root of the generated .zip file.

1
bundle {
2
cdnCssFiles = [
3
'styles/default/All.min.css'
4
]
5
}

testMode

The mode for ThemeCompatibilityTest: 'disable', 'error', or 'warn'; defaults to 'error'.

1
bundle {
2
testMode = 'warn'
3
}

compatibilityTestExcludedPaths

JSON files that ThemeCompatibilityTest skips, relative to the root of the generated .zip file. ThemeCompatibilityTest also skips all files that are not in the styleguide navigation.

1
bundle {
2
compatibilityTestExcludedPaths = [
3
'path/to/some/ignored/file.json'
4
]
5
}

Root styleguide dependency

The root styleguide that ThemeCompatibilityTest uses. Defaults to the single subproject that applies com.brightspot.viewgen. If the default does not work, examine your Gradle setup for an error.

1
dependencies {
2
rootStyleguide project(path: ':frontend', configuration: 'rootStyleguideDir')
3
}

Viewgen​

These settings go in frontend/build.gradle, in the viewgen block.

styleguideDir

The root styleguide directory, relative to the subproject directory; defaults to 'styleguide'.

1
viewgen {
2
styleguideDir = '../styleguide'
3
}

WAR​

These settings go in web/build.gradle (or site/build.gradle), in the brightspotWar block. Put a war { } block after the brightspotWar { } block.

applyDefaultExclusions

Whether to exclude the default set of JAR files that Tomcat provides; defaults to true. If false, you must exclude everything that Tomcat provides. Projects on Brightspot Cloud can use the default. Projects not on Brightspot Cloud must not exclude slf4j-api.

1
brightspotWar {
2
applyDefaultExclusions = false
3
}

The default exclusions are:

1
war {
2
rootSpec.exclude '**/javax.el-api'
3
rootSpec.exclude '**/javax.servlet-api-*.jar'
4
rootSpec.exclude '**/javax.servlet.jsp-api-*.jar'
5
rootSpec.exclude '**/mysql-connector-java-*.jar'
6
rootSpec.exclude '**/slf4j-api-*.jar'
7
rootSpec.exclude '**/slf4j-jdk14-*.jar'
8
}

cmsWarDestinationDirectory

The directory in the WAR file for the contents of the cms-tool-ui WAR file, which contains the Brightspot CMS interface; defaults to 'cms'. It must match the dari/routingFilter/applicationPath/cms setting in context.xml, if that setting exists.

1
brightspotWar {
2
cmsWarDestinationDirectory = 'customCmsLocation'
3
}

WAR file name

For regular builds, the WAR file name does not include the version, which keeps the local Docker Compose configuration simple. For release builds, the WAR file name includes the release version.

Jakarta EE substitution​

Tomcat 10.1 and higher require Jakarta EE in place of Java EE. The com.brightspot.jakarta-substitution plugin rewrites the javax namespace to jakarta in everything the WAR file contains, as a temporary measure until the code is migrated. Apply it in the same build.gradle file as com.brightspot.war, without a version:

1
plugins {
2
id 'com.brightspot.war'
3
id 'com.brightspot.jakarta-substitution'
4
}

The migration runs as the WAR file is packaged. Each dependency JAR is migrated once and cached by its content.

Tests​

In a plugin project, every Test task runs on the JUnit Platform; in other projects, the test task does. Every Test task has a heap of brightspot.test.maxHeapSize.

When the test runtime classpath has a JUnit Platform engine but no junit-platform-launcher, the plugins add the launcher at the version of the engine. Gradle 9 no longer supplies the launcher itself.

When the test runtime classpath has mockito-core, each test worker starts with that JAR as a Java agent, so Mockito does not attach itself at run time. Newer JDKs warn about, and will block, an agent that attaches at run time. Nothing is added when the JAR is not an agent, as in old Mockito versions, or when the task already names a Mockito agent in its JVM arguments. To turn off the agent, set brightspot.test.mockitoAgent=false.

Shared tests​

These settings go in any build.gradle that applies com.brightspot.shared-tests, in the sharedTests block.

scope

Which classes the shared tests examine; defaults to 'current'. With 'current', each subproject's shared tests examine only that subproject's classes. With 'project', the shared tests examine every class the subproject depends on in the build. Use 'project' on a subproject that aggregates others, such as a pack, to run one test task in place of one per subproject.

1
sharedTests {
2
scope = 'project'
3
}

classesDirs

The compiled classes to run shared tests against; defaults to the main source set output, or the enhanced-classes directory when class enhancement applies. Paths must be relative to the subproject directory, for cacheability.

1
sharedTests {
2
classesDirs = [
3
project.getProjectDir().toPath().relativize(project.getBuildDir().resolve('classes').resolve('java').resolve('main'))
4
]
5
}

allClassesDirs

The compiled classes for the whole build, from the runtimeClasspath configuration, filtered to the JARs of subprojects in the build.

Publishing​

These settings go in the gitHashVersion block of a subproject that uses BOM versioning.

commitCountOffset

A number to add to the commit count. Use it when a subproject moves to a different location in its Git repository, which resets its commit count.

commitCountPrefix

Text immediately before the commit count. A prefix of 14 and a commit count of 123 give a version such as 1.2.14123-xabcdef. Use it to keep a version line sorting above versions from an earlier numbering scheme.

additionalPaths

Directories whose commits count toward the subproject's version, for a subproject whose published artifact changes when another directory changes.

1
gitHashVersion {
2
commitCountOffset = 1
3
commitCountPrefix = '14'
4
additionalPaths.from(rootProject.file('shared'))
5
}

SonarQube​

com.brightspot.gradle configures SonarQube for every project. Do not declare anything.

For a delivery project, it applies com.brightspot.sonar, which configures:

  • The root project, with the sonar task and a sonar.projectKey of perfectsense:<root project name>.
  • Each java-core subproject, whose tests run with JaCoCo. Each test run writes the coverage report to build/reports/jacoco/test/jacocoTestReport.xml, which the analysis reads.
  • Each bundle subproject, whose sources are the subproject directory.

For a plugin project, see Plugin projects.

The build task does not run the analysis. Run it as a separate step, after the tests:

1
./gradlew build
2
./gradlew sonar

A settings.gradle that still declares com.brightspot.sonar builds without an error. Remove the declaration.

Do not declare the org.sonarqube plugin with a version in a build.gradle. The plugins already supply it, and Gradle rejects a version for a plugin that is already on the classpath.

Build scans​

The plugins apply Develocity and accept its terms of use for every project. A build publishes a scan only when you pass --scan. Scans go to the public gradle.com endpoint.

--scan requires Gradle 8.8 or higher. For --scan, lower versions of Gradle apply the older Gradle Enterprise plugin, which cannot run alongside the Develocity plugin. On those versions, a build with --scan stops with a message that states the requirement. Builds without --scan are not affected.

Do not declare the com.gradle.develocity or com.gradle.enterprise plugin. If the build declares com.gradle.enterprise, the plugins keep it, and brightspotGradleRewriteCheck advises brightspotDoctor, which removes it.

Configuration cache​

To use Gradle's configuration cache, use Gradle 8.14 or higher. On lower versions, the Checkstyle task's configuration cannot be read from the cache when org.gradle.parallel or org.gradle.priority is set. The build fails with Could not load the value of field 'aliasSet' of 'sun.nio.cs.UTF_8'.

The brightspotGradleRewrite task turns the configuration cache on or off in gradle.properties, from a test build of the project. brightspotDoctor commits that change before the recipe commits. These tasks work with the configuration cache on: brightspotDoctor, brightspotGradleUpgrade, brightspotGradleRewrite, brightspotRewrite, brightspotUpgrade, and the checks brightspotUpgradeCheck, brightspotGradleUpgradeCheck, brightspotGradleRewriteCheck, and brightspotRewriteCheck.

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.