Skip to main content

Upgrading Brightspot Gradle Plugins

Goals​

  • Establish and maintain Gradle best practices for all Brightspot projects
  • Improve build performance
  • Simplify future upgrades

Automated upgrade​

The brightspotGradleRewrite task does most of the steps in this guide.

  1. In settings.gradle, set the com.brightspot.gradle version to 3.14.0 or higher, and remove the com.brightspot.sonar line.
  2. Fix the constructs below if the project has them. The build fails on them before the doctor can run.
    • A tasks.named('jakarta-substitution-war') { ... } block: delete it. The plugin has no such task, and the Jakarta migration already excludes *.zip files.
    • Version keys in brightspot.versions other than java and project: replace each one with its BOMs in the brightspot.dependencies block, at the same version <v>:
      1
      // versions.brightspot = '<v>'
      2
      implementation enforcedPlatform('com.psddev:brightspot-bom:<v>')
      3
      implementation enforcedPlatform('com.psddev:brightspot-dependencies:<v>')
      4
      5
      // versions.brightspotGo = '<v>'
      6
      implementation enforcedPlatform('com.brightspot.go:bom:<v>')
      7
      implementation enforcedPlatform('com.brightspot.go:go-dependencies:<v>')
      8
      9
      // versions.componentLib = '<v>'
      10
      implementation enforcedPlatform('com.psddev.component-lib:bom:<v>')
      11
      implementation enforcedPlatform('com.psddev.component-lib:cl-dependencies:<v>')
      12
      13
      // versions.sharedTests = '<v>'
      14
      sharedTest enforcedPlatform('com.brightspot.shared-tests:bom:<v>')
  3. Commit these changes.
  4. Run the doctor, and review its edits and its report:
    1
    ./gradlew brightspotGradleRewrite
    2
    git diff
  5. Do the items in the report that the doctor cannot do, and commit the changes.
  6. Run the upgrade recipes that the classpath brings. The doctor commits each recipe.
    1
    ./gradlew brightspotDoctor
  7. Verify the build.

Use the steps below for a project that the doctor cannot upgrade, or to understand the changes.

Later upgrades​

To upgrade the Brightspot BOMs after this upgrade, run ./gradlew brightspotUpgrade, and review the commits that it made. It sets the new versions and then runs brightspotDoctor. See brightspotUpgrade.

To upgrade a BOM or a dependency after this upgrade:

  1. Change the version by any means: by hand, or with Dependabot or Renovate.
  2. Run ./gradlew brightspotDoctor, and review the commits that it made.

To move the build to the latest release of the plugins, run ./gradlew brightspotUpgrade.

See Upgrade recipes.

Conventions​

Set $PROJECT to the project name​

Throughout this guide, $PROJECT will be used to refer to the project's normalized kebab-case name.

  • ✅ Right: PROJECT='example-co'
  • ❌ Wrong: PROJECT='Example Co, Inc.'
  • 🤡 Extra Wrong: PROJECT='$PROJECT'

In all cases, the string $PROJECT must be substituted for the project name in all file contents before committing changes to the file.

Before running any of the prescribed commands on your command line, export PROJECT='my-project-name'. This will automate the $PROJECT substitution in those cases.

Resolve // XXX comments​

Comments prefixed with XXX are there for you, the reader of this guide, to review, resolve, and remove before committing changes to the file.

  • ✅ Right: brightspotVersion = 4.5.15.8
  • ❌ Wrong: brightspotVersion = 4.5.15.8 // XXX Copy this version number from the legacy build.gradle
  • 🤡 Extra Wrong: brightspotVersion = 4.5.x // XXX Copy this version number from the legacy build.gradle

In all cases, any comment starting with // XXX must be deleted after satisfying the advice within.

Project Structure​

Projects sometimes have different module naming conventions. For example, older projects have a site module that generates the war file, while newer projects call that the web module. Throughout this guide, we will use the "new" conventions, but this table should help you to map these names to those found in your project:

NameNew PathOld Path
core./core./core
web./web./site
frontend./frontend./frontend
root styleguide./frontend/styleguide./styleguide
bundles./frontend/bundles./themes

Version Control Hygiene​

Each step in this guide should be committed to the git repository. Suggested commit messages are detailed inline. The suggested command git commit -a adds and commits all changes in the entire repo, so make sure there aren't any unintended changes included.

Command Line Working Directory​

The working directory for all command line operations detailed in this guide is assumed to be the root directory of the project unless otherwise noted.

Example​

Along with this guide, this pull request can be used as a reference.

0. Current build for verification​

tip

If a styleguide upgrade is necessary, do it first to simplify the verification of the gradle plugin upgrade.

Before changing anything, run a full build and set the gradle scan and war file aside for verification at the end.

The gradlew command will output a Gradle scan URL. Bookmark this URL to compare at the end.

If the current version of component-lib is before 4.2.188 or 4.5.23, upgrade to one of those versions before this step.

1
./gradlew clean build --no-build-cache --scan
2
cp web/build/libs/$PROJECT*.war /tmp/$PROJECT-before.war

1. Upgrade Gradle Wrapper​

Remove gradle or gradle/ from the .gitignore file in the project root, if present.

1
./gradlew wrapper --gradle-version=8.14.1
2
./gradlew wrapper --gradle-version=8.14.1
3
git commit -a -m "Upgrade Gradle Wrapper to 8.14.1"

Be sure to run the ./gradlew wrapper command twice so it downloads the latest files.

2. Delete /build.gradle​

Just set it aside for now, as we may need to copy some details from it later.

1
mv ./build.gradle /tmp/$PROJECT-build.gradle
2
git commit -a -m "Gradle plugin upgrade: Remove /build.gradle"
tip

Take special note of any forced dependency constraints, substitutions, or exclusions. These should be converted to dependencyConstraints, dependencySubstitutions, or dependencyExclusions - see Common overrides for details.

3. Update settings.gradle​

Edit settings.gradle to match the following.

The snippet below is annotated for an in-flight upgrade. For the configuration to aim for once the upgrade is done, see Recommended settings.gradle.

1
pluginManagement {
2
repositories {
3
gradlePluginPortal() {
4
content {
5
excludeGroupByRegex 'com\\.brightspot($|\\..+)'
6
excludeGroupByRegex 'com\\.psddev($|\\..+)'
7
}
8
}
9
maven {
10
url 'https://artifactory.psdops.com/public'
11
}
12
}
13
}
14
15
plugins {
16
id 'com.brightspot.gradle' version '3.14.0'
17
}
18
19
rootProject.name = '$PROJECT'
20
21
brightspot {
22
projectGroup = 'com.$PROJECT' // XXX This is probably already set in the existing build.gradle. If so, use that value here.
23
24
versions {
25
java = 21 // XXX Use the project's current Java version if it cannot move to 21 yet
26
}
27
28
dependencies {
29
// XXX Copy the versions for these from existing build.gradle, if present.
30
implementation enforcedPlatform('com.psddev:brightspot-bom:4.5.15.19')
31
implementation enforcedPlatform('com.psddev:brightspot-dependencies:4.5.15.19')
32
33
sharedTest enforcedPlatform('com.brightspot.shared-tests:bom:1.0.1')
34
35
// XXX If BSP Go isn't in the existing build.gradle, leave these two lines out.
36
implementation enforcedPlatform('com.brightspot.go:bom:1.4.6')
37
implementation enforcedPlatform('com.brightspot.go:go-dependencies:1.4.6')
38
39
// XXX If Component Lib isn't in the existing build.gradle, leave these two lines out.
40
// XXX If on version 4.2.188 or lower, or 4.5.23 or lower, you will need to upgrade to at least one of those versions.
41
implementation enforcedPlatform('com.psddev.component-lib:bom:4.5.26')
42
implementation enforcedPlatform('com.psddev.component-lib:cl-dependencies:4.5.26')
43
44
// XXX Only include these if "com.psddev.migration:bom" is already included.
45
// XXX (not "com.psddev:migration-bom" or "com.psddev.migration:migration-bom")
46
// XXX Note that it may be in another build.gradle such as migration/build.gradle
47
implementation enforcedPlatform('com.psddev.migration:bom:4.7.0.4')
48
implementation enforcedPlatform('com.psddev.migration:dependencies:4.7.0.4')
49
}
50
}
51
52
// XXX Project-specific lines similar to the following (until XXX END) should already be present in the
53
// XXX existing settings.gradle. Leave them alone.
54
55
include(':core')
56
include(':web')
57
include(':frontend')
58
include(':bundle-default')
59
60
project(':bundle-default').projectDir = file('frontend/bundles/bundle-default')
61
62
// XXX END
63
tip

The plugins apply Develocity, accept its terms of use, and publish a scan only when you pass --scan. A com.gradle.develocity or com.gradle.enterprise plugin declaration and a develocity or gradleEnterprise block are not needed. The plugins also configure SonarQube, so a com.brightspot.sonar plugin declaration is not needed. Remove them if the existing settings.gradle has them. If the existing settings.gradle has a brightspotLibs version catalog, remove it; the dependencies block replaces it. See Build scans.

tip

Most common dependency substitutions are now managed by the Brightspot Gradle plugins, so remove any of the project's own substitutions that match a default. Custom substitutions can still be added. See the default substitutions.

tip

Set the org.apache.solr:solr-solrj constraint like the example below. If your project is moving to cloud and a SOLR upgrade has been applied to the cluster, set the value to 8.11.1, otherwise use the value forced in {site/web}/build.gradle (likely 8.6.1). Any forced dependency constraints from the now-deleted /build.gradle must be added to dependencyConstraints in settings.gradle as well.

1
brightspot {
2
dependencyConstraints = [
3
'org.apache.solr:solr-solrj': '8.11.1', // XXX or forced value in {site/web}/build.gradle
4
]
5
}
6
1
git commit -a -m "Gradle plugin upgrade: Update settings.gradle"

4. Update core/build.gradle​

Add the brightspot java plugin to the very top of the file:

1
plugins {
2
id 'com.brightspot.java-core'
3
}

Standardize on using api rather than compile for all dependencies in core/build.gradle. Either use a text editor to find and replace, or do it on the command line like so:

1
sed -i '' 's/ compile / api /; s/constraints.compile(/constraints.api(/;' core/build.gradle

Check the file to ensure the changes are what you expect: All compile lines are changed to api.

Similarly, runtime should be replaced with runtimeOnly, testCompile with testImplementation, and testRuntime with testRuntimeOnly. compileOnly and testCompileOnly should remain as-is. More on deprecated configurations in the Gradle documentation

Testing dependencies have been updated. Remove these dependencies and run a build of the core project to ensure that no custom test work relied on these.

1
dependencies {
2
testImplementation 'com.psddev.component-lib:test-utils'
3
testImplementation 'com.psddev.component-lib:shared-unit-tests'
4
}

Assuming no build failures from the previous step, add shared unit tests to the dependencies to replace the old tests:

1
dependencies {
2
sharedTest 'com.brightspot.shared-tests:pack-standard-backend-unit-tests'
3
}

Remove the com.psddev.component-lib:materialize dependency, if present.

Remove any lines like this:

1
project.afterEvaluate {
2
jar.dependsOn(test)
3
}

If core/host.gradle exists and it is included into core/build.gradle via apply from: file("host.gradle"), remove the include and move the dependencies from core/host.gradle into the dependencies in core/build.gradle. Be sure to remove the core/host.gradle file as well.

Any instances of force = true in core/build.gradle need to be converted into dependency constraints in settings.gradle.

For projects using com.brightspot.gradle at version 1.1.1 or later, any dependency exclusions should be moved into settings.gradle. See exclusions for the syntax.

If the build fails with javadoc parsing errors, you can either fix them or skip javadoc processing like so:

1
tasks.withType(Javadoc).configureEach { enabled = false }
1
git commit -a -m "Gradle plugin upgrade: Update core/build.gradle"

5. Update frontend/build.gradle​

frontend/build.gradle should only contain the following lines; anything else in this file can be deleted:

1
plugins {
2
id 'com.brightspot.viewgen'
3
}
4
5
description = '$PROJECT: Frontend'

If the root styleguide directory is in the project root (rather than under the frontend/ directory), add the following to frontend/build.gradle:

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

Any files in frontend/src/main/webapp must be moved to web/src/main/webapp (or site/src/main/webapp). For example, frontend/src/main/webapp/WEB-INF/web.xml to web/src/main/webapp/WEB-INF/web.xml

Please pay special attention to web.xml. It is imperative that this file is located within the web (or site) directory listed above. If you encounter any errors pertaining to org.apache.jasper.JasperException or com.psddev.dari.web.NoCurrentWebRequestException please ensure that web.xml is in the correct location before troubleshooting further.

1
git commit -a -m "Gradle plugin upgrade: Update frontend/build.gradle"

6. Update each bundle's build.gradle​

Each frontend bundle's build.gradle should contain the following:

1
plugins {
2
id 'com.brightspot.bundle'
3
}
4
5
description = 'bundle-default' // XXX Just leave this description alone if it's set already,
6
// XXX otherwise set it to match the bundle directory name
7
8
bundle {
9
yarnBuildCommand = 'build'
10
styleguideOutputDir = 'styleguide'
11
zipOutputPath = 'theme.zip'
12
13
// for CdnCssTest
14
cdnCssFiles = [
15
'styles/default/All.min.css' // XXX Change this to the correct path(s) of All.min.css
16
]
17
}
18
19
node {
20
yarnVersion = '1.22.19' // XXX Copy these versions from the existing /build.gradle
21
version = '18.17.1' // XXX If the existing node version is earlier than 14, you'll also need to upgrade styleguide.
22
download = true
23
}
24
25
dependencies {
26
sharedTest 'com.brightspot.shared-tests:pack-standard-frontend-unit-tests'
27
}

If the bundle/theme's build.gradle contains a test {} block that sets maxHeapSize, remove it and set the heap size in the project's gradle.properties:

1
brightspot.test.maxHeapSize=4g
1
git commit -a -m "Gradle plugin upgrade: Update bundle build.gradle"

7. Update web/build.gradle​

The build.gradle file that generates the war file should contain the following:

tip

Some additional api, compile, or implementation dependencies, such as org.apache.solr:solr-solrj may be present in the existing web/build.gradle. These must be removed and added to core/build.gradle! Additionally, any instances of force = true in web/build.gradle need to be converted into dependency constraints in settings.gradle (see Update settings.gradle above for an example).

1
plugins {
2
id 'com.brightspot.war'
3
}
4
5
description = '$PROJECT: Web'
6
7
dependencies {
8
// XXX Project-specific lines similar to the following three lines should already be present in the
9
// XXX existing web/build.gradle. Make sure they're using implementation instead of api, and otherwise leave them alone.
10
implementation project(':frontend')
11
implementation project(':core')
12
implementation project(':bundle-default')
13
14
// for expansion into the war
15
compileOnly 'com.psddev:cms-tool-ui'
16
17
// Tests
18
sharedTest 'com.brightspot.go:lib-util-gradle-dynamic-test' // XXX Only if this is already present
19
sharedTest 'com.brightspot.shared-tests:pack-standard-backend-integration-tests'
20
}
1
git commit -a -m "Gradle plugin upgrade: Update web/build.gradle"

8. Update any other subproject build.gradle files​

An example of one of these would be a migration/build.gradle file.

These must be treated on a case-by-case basis but can probably follow the same process as core/build.gradle.

9. Verify the build​

As before, run the build, bookmark the gradle scan, and set the war file aside for comparison.

1
./gradlew clean build --no-build-cache --scan
2
cp web/build/libs/$PROJECT*.war /tmp/$PROJECT-after.war

We're going to execute a very simple test that compares the filenames in the "before" war file to the filenames in the "after" war file. This isn't a perfect test, as the file contents could differ, but this simple test is sufficient for the purpose of this upgrade.

1
diff <(unzip -l /tmp/$PROJECT-before.war) <(unzip -l /tmp/$PROJECT-after.war)

The expected output from this command is something like this:

1
1c1
2
< Archive: /tmp/$PROJECT-before.war
3
---
4
> Archive: /tmp/$PROJECT-after.war

Anything else indicates that one or more files have been added or removed. The steps to remediate depend on the file that has changed, and are outside the scope of this document.

The build scans taken in the first and last steps may be useful in troubleshooting this or other issues.

10. Other Configuration Changes​

Move ignore test files after gradle upgrade​

If the ignore files for the below tests are under site/src/test/resources/brightspot/, they need to move to core/src/test/resources/brightspot/ so those tests can continue to be ignored

1
AlterationClassAnnotationProcessorTest.ignored.txt
2
AlterationFieldAnnotationProcessorTest.ignored.txt
3
NoAlterationMethodsExistTest.ignored.txt
4
ModificationFieldInternalNamePrefixTest.ignored.txt
5
NoAfterCreateOutsideModificationsTest.ignored.txt
6
NoFinalFieldsInRecordsTest.ignored.txt
7
JobStatusTest.ignored.txt
8
RecordableHasNullaryConstructorTest.ignored.txt

docker-compose.yml​

The war file name has changed as part of this update, so you'll need to change docker-compose.yml to reflect this.

1
services: // XXX lines omitted for brevity
2
tomcat:
3
environment:
4
- ROOT_WAR=/code/web/build/libs/${PROJECT}-web.war

gradle.properties​

Double-check the file gradle.properties to ensure it contains a property like org.gradle.caching=true.

Further Reading​

Was this page helpful?

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