Skip to content

Commit

Permalink
[consuming-a-maven-bom] Upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
dgroomes committed Aug 3, 2024
1 parent d4b6899 commit 38809c4
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 48 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,43 @@ re-using the code.

The subprojects include:


### `java-preview-features/`

This subproject shows how to configure Gradle to build and run a project that uses Java [_Preview Features_](https://openjdk.java.net/jeps/12).

See the README in [java-preview-features/](java-preview-features/).


### `java-early-access-via-toolchain/`

This subproject illustrates how to leverage Gradle's [Toolchains for JVM projects](https://docs.gradle.org/current/userguide/toolchains.html)
to use an early-access version of Java in a Gradle project.

See the README in [java-early-access-via-toolchain/](java-early-access-via-toolchain/).


### `consuming-a-maven-bom/`

This subproject shows how to consume a Maven BOM in a Gradle project and *strictly* override a BOM dependency.
Consume a Maven BOM in a Gradle project and *strictly* override a BOM dependency.

See the README in [consuming-a-maven-bom/](consuming-a-maven-bom/).


### `multi-module/`

This subproject illustrates a multi-module Gradle project.

See the README in [multi-module/](multi-module/).


### `plugin/`

This subproject shows how to write and apply a custom Gradle plugin. It also showcases [Gradle's `buildSrc` feature](https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources).

See the README in [plugin/](plugin/).


### `java-modules/`

An example Gradle project that uses the Java Platform Module System (JPMS).
Expand Down
14 changes: 7 additions & 7 deletions consuming-a-maven-bom/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# consuming-a-maven-bom

This subproject shows how to consume a Maven BOM in a Gradle project and *strictly* override a BOM dependency.
Consume a Maven BOM in a Gradle project and *strictly* override a BOM dependency.


# Description
## Overview

In particular, this project imports the [Jackson project](https://github.com/FasterXML/jackson) BOM dependency: <https://github.com/FasterXML/jackson-bom>.
This allows Jackson dependencies defined in the BOM to be declared in the Gradle project *without* a version because
Expand All @@ -14,11 +14,11 @@ We can make sense of the final dependency tree if we look at the `gradle.lockfil
Gradle's [dependency locking](https://docs.gradle.org/current/userguide/dependency_locking.html) feature.


# Instructions
## Instructions

Follow these instructions to resolve and inspect the dependencies.

1. Use Java 17
1. Pre-requisite: Java 21
2. Read the `build.gradle.kts` file
* This file has code comments that describe the core concepts. Read the file in detail.
3. Trigger dependency resolution and lock the dependencies
Expand All @@ -28,9 +28,9 @@ Follow these instructions to resolve and inspect the dependencies.
* Note: Using the `dependencies` task is arbitrary. Any task that resolves dependencies will work.
* Running a dependency-resolving task with `--write-locks` only has an effect on this project when there is a newer
version of the Jackson BOM available than there was when this task was last run. The project declares a dynamic
version dependency on the Jackson BOM. For example, if the project declares `2.15.+` then if `2.15.2` is the latest
version of the Jackson BOM but the project was last built when `2.15.1` was the latest version, then this task will
update the `gradle.lockfile` to use `2.15.2`.
version dependency on the Jackson BOM. For example, if the project declares `2.17.+` then if `2.17.2` is the latest
version of the Jackson BOM but the project was last built when `2.17.1` was the latest version, then this task will
update the `gradle.lockfile` to use `2.17.2`.
4. Make some dependency observations
* Study the `gradle.lock` file. This is a convenient way to get a holistic view of the resolved dependencies in the
project. Alternatively, use any of the following commands to inspect the resolved dependencies in the project.
Expand Down
62 changes: 37 additions & 25 deletions consuming-a-maven-bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ repositories {
mavenCentral()
}

val jacksonBomVersion = "2.15.+" // Jackson releases: https://github.com/FasterXML/jackson/wiki/Jackson-Releases
val jacksonDatabindVersion = "2.15.1" // let's try to force a downgrade to a specific version of jackson-databind which is different from what is defined in the BOM
// Jackson releases: https://github.com/FasterXML/jackson/wiki/Jackson-Releases
// Usually, we don't like to code to a dynamic version ("+" sign), but because we are using a lock file, we still have
// a complete understading of the resolved dependencies. The lock file is version controlled and should be reviewed
// before committing changes.
val jacksonBomVersion = "2.17.+"

// Let's try to force a downgrade to a specific version of jackson-databind which is different from what is defined in the BOM
val jacksonDatabindVersion = "2.17.1"

dependencies {
/*
Expand Down Expand Up @@ -53,29 +59,35 @@ dependencies {
------------------------------------------------------------
compileClasspath - Compile classpath for source set 'main'.
+--- com.fasterxml.jackson:jackson-bom:2.15.2
| +--- com.fasterxml.jackson.core:jackson-annotations:2.15.2 (c)
| +--- com.fasterxml.jackson.core:jackson-core:2.15.2 (c)
| +--- com.fasterxml.jackson.core:jackson-databind:2.15.2 -> 2.15.1 (c)
| +--- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.15.2 (c)
| \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.15.2 (c)
+--- com.fasterxml.jackson.core:jackson-annotations -> 2.15.2
| \--- com.fasterxml.jackson:jackson-bom:2.15.2 (*)
+--- com.fasterxml.jackson.core:jackson-core -> 2.15.2
| \--- com.fasterxml.jackson:jackson-bom:2.15.2 (*)
+--- com.fasterxml.jackson.module:jackson-module-parameter-names -> 2.15.2
| +--- com.fasterxml.jackson.core:jackson-core:2.15.2 (*)
| +--- com.fasterxml.jackson.core:jackson-databind:2.15.2 -> 2.15.1
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.15.1 -> 2.15.2 (*)
| | +--- com.fasterxml.jackson.core:jackson-core:2.15.1 -> 2.15.2 (*)
| | \--- com.fasterxml.jackson:jackson-bom:2.15.1 -> 2.15.2 (*)
| \--- com.fasterxml.jackson:jackson-bom:2.15.2 (*)
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-csv -> 2.15.2
| +--- com.fasterxml.jackson.core:jackson-databind:2.15.2 -> 2.15.1 (*)
| +--- com.fasterxml.jackson.core:jackson-annotations:2.15.2 (*)
| +--- com.fasterxml.jackson.core:jackson-core:2.15.2 (*)
| \--- com.fasterxml.jackson:jackson-bom:2.15.2 (*)
\--- com.fasterxml.jackson.core:jackson-databind:{strictly 2.15.1} -> 2.15.1 (*)
+--- com.fasterxml.jackson:jackson-bom:2.17.+ -> 2.17.2
| +--- com.fasterxml.jackson.core:jackson-annotations:2.17.2 (c)
| +--- com.fasterxml.jackson.core:jackson-core:2.17.2 (c)
| +--- com.fasterxml.jackson.core:jackson-databind:2.17.2 -> 2.17.1 (c)
| +--- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.17.2 (c)
| \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.17.2 (c)
+--- com.fasterxml.jackson.core:jackson-annotations -> 2.17.2
| \--- com.fasterxml.jackson:jackson-bom:2.17.2 (*)
+--- com.fasterxml.jackson.core:jackson-core -> 2.17.2
| \--- com.fasterxml.jackson:jackson-bom:2.17.2 (*)
+--- com.fasterxml.jackson.module:jackson-module-parameter-names -> 2.17.2
| +--- com.fasterxml.jackson.core:jackson-core:2.17.2 (*)
| +--- com.fasterxml.jackson.core:jackson-databind:2.17.2 -> 2.17.1
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.17.1 -> 2.17.2 (*)
| | +--- com.fasterxml.jackson.core:jackson-core:2.17.1 -> 2.17.2 (*)
| | \--- com.fasterxml.jackson:jackson-bom:2.17.1 -> 2.17.2 (*)
| \--- com.fasterxml.jackson:jackson-bom:2.17.2 (*)
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-csv -> 2.17.2
| +--- com.fasterxml.jackson.core:jackson-databind:2.17.2 -> 2.17.1 (*)
| +--- com.fasterxml.jackson.core:jackson-annotations:2.17.2 (*)
| +--- com.fasterxml.jackson.core:jackson-core:2.17.2 (*)
| \--- com.fasterxml.jackson:jackson-bom:2.17.2 (*)
+--- com.fasterxml.jackson.core:jackson-databind:{strictly 2.17.1} -> 2.17.1 (*)
+--- com.fasterxml.jackson.core:jackson-databind:{strictly 2.17.1} -> 2.17.1 (c)
+--- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:{strictly 2.17.2} -> 2.17.2 (c)
+--- com.fasterxml.jackson.core:jackson-core:{strictly 2.17.2} -> 2.17.2 (c)
+--- com.fasterxml.jackson.module:jackson-module-parameter-names:{strictly 2.17.2} -> 2.17.2 (c)
+--- com.fasterxml.jackson:jackson-bom:{strictly 2.17.2} -> 2.17.2 (c)
\--- com.fasterxml.jackson.core:jackson-annotations:{strictly 2.17.2} -> 2.17.2 (c)
(c) - A dependency constraint, not a dependency. The dependency affected by the constraint occurs elsewhere in the tree.
(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.
Expand Down
12 changes: 6 additions & 6 deletions consuming-a-maven-bom/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
com.fasterxml.jackson.core:jackson-annotations:2.15.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.15.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.15.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.15.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.module:jackson-module-parameter-names:2.15.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.15.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-annotations:2.17.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-core:2.17.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.core:jackson-databind:2.17.1=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.17.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson.module:jackson-module-parameter-names:2.17.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
com.fasterxml.jackson:jackson-bom:2.17.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
empty=annotationProcessor,testAnnotationProcessor
Binary file modified consuming-a-maven-bom/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
24 changes: 16 additions & 8 deletions consuming-a-maven-bom/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions consuming-a-maven-bom/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down

0 comments on commit 38809c4

Please sign in to comment.