diff --git a/README.md b/README.md index ce8d0b2..a81fc1a 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ See the README in [consuming-a-maven-bom/](consuming-a-maven-bom/). ### `multi-module/` -This subproject illustrates a multi-module Gradle project. +A **poorly configured** multi-module Gradle project. See the README in [multi-module/](multi-module/). diff --git a/multi-module/README.md b/multi-module/README.md index 917be85..7b605a3 100644 --- a/multi-module/README.md +++ b/multi-module/README.md @@ -1,6 +1,6 @@ # multi-module -This subproject illustrates a multi-module Gradle project. +A **poorly configured** multi-module Gradle project. ## Overview @@ -8,13 +8,18 @@ This subproject illustrates a multi-module Gradle project. This project is me learning how to configure multi-module Gradle projects. Read more about Gradle's support for multi-project builds at the [official doc site](https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:multi_project_builds). +This project is a poor configuration of a multi-module Gradle project because it uses "cross-configuring" from the root +`build.gradle.kts` file. This is not recommend. See the extensive note in that file. Instead, you should use a +combination of pre-compiled script plugins and keeping subproject-specific configuration in the subproject instead of +trying to "control it from afar" in the root `build.gradle.kts`. + ## Instructions The interesting part of this project is the Gradle configuration. So, read the `build.gradle.kts` files. But still, it's useful to execute the example applications to prove that it works. Follow the below steps to build and run the programs: -1. Use Java 17 +1. Pre-requisite: Java 21 2. Run `module-a`: * ```shell ./gradlew :module-a:run @@ -22,7 +27,7 @@ useful to execute the example applications to prove that it works. Follow the be * It should print something like the following. * ```text > Task :module-a:run - [main] INFO dgroomes.MainA - Hello world from 'module-a'! + [main] INFO dgroomes.multi_module.module_a.MainA - Hello world from 'module-a'! ``` 3. Run `module-b`: * ```shell @@ -31,7 +36,7 @@ useful to execute the example applications to prove that it works. Follow the be * It should print something like the following. * ```text > Task :module-b:run - [main] INFO dgroomes.MainB - Hello world from 'module-b'! + [main] INFO dgroomes.multi_module.module_b.MainB - Hello world from 'module-b'! ``` diff --git a/multi-module/build.gradle.kts b/multi-module/build.gradle.kts index 9652aac..d52b81a 100644 --- a/multi-module/build.gradle.kts +++ b/multi-module/build.gradle.kts @@ -41,7 +41,7 @@ subprojects { */ val moduleA = project(":module-a") { configure { - mainClass.set("dgroomes.MainA") + mainClass.set("dgroomes.multi_module.module_a.MainA") } } diff --git a/multi-module/gradle/wrapper/gradle-wrapper.jar b/multi-module/gradle/wrapper/gradle-wrapper.jar index 249e583..033e24c 100644 Binary files a/multi-module/gradle/wrapper/gradle-wrapper.jar and b/multi-module/gradle/wrapper/gradle-wrapper.jar differ diff --git a/multi-module/gradle/wrapper/gradle-wrapper.properties b/multi-module/gradle/wrapper/gradle-wrapper.properties index 84a0b92..09523c0 100644 --- a/multi-module/gradle/wrapper/gradle-wrapper.properties +++ b/multi-module/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/multi-module/gradlew b/multi-module/gradlew index a69d9cb..fcb6fca 100755 --- a/multi-module/gradlew +++ b/multi-module/gradlew @@ -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/. @@ -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 @@ -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 @@ -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 diff --git a/multi-module/gradlew.bat b/multi-module/gradlew.bat index f127cfd..93e3f59 100644 --- a/multi-module/gradlew.bat +++ b/multi-module/gradlew.bat @@ -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% diff --git a/multi-module/module-a/src/main/java/dgroomes/MainA.java b/multi-module/module-a/src/main/java/dgroomes/multi_module/module_a/MainA.java similarity index 86% rename from multi-module/module-a/src/main/java/dgroomes/MainA.java rename to multi-module/module-a/src/main/java/dgroomes/multi_module/module_a/MainA.java index d424d6c..e79c60a 100644 --- a/multi-module/module-a/src/main/java/dgroomes/MainA.java +++ b/multi-module/module-a/src/main/java/dgroomes/multi_module/module_a/MainA.java @@ -1,4 +1,4 @@ -package dgroomes; +package dgroomes.multi_module.module_a; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/multi-module/module-b/build.gradle.kts b/multi-module/module-b/build.gradle.kts index 042c537..d7c2843 100644 --- a/multi-module/module-b/build.gradle.kts +++ b/multi-module/module-b/build.gradle.kts @@ -1,3 +1,3 @@ application { - mainClass.set("dgroomes.MainB") + mainClass.set("dgroomes.multi_module.module_b.MainB") } diff --git a/multi-module/module-b/src/main/java/dgroomes/MainB.java b/multi-module/module-b/src/main/java/dgroomes/multi_module/module_b/MainB.java similarity index 86% rename from multi-module/module-b/src/main/java/dgroomes/MainB.java rename to multi-module/module-b/src/main/java/dgroomes/multi_module/module_b/MainB.java index 6b31dc4..db16030 100644 --- a/multi-module/module-b/src/main/java/dgroomes/MainB.java +++ b/multi-module/module-b/src/main/java/dgroomes/multi_module/module_b/MainB.java @@ -1,4 +1,4 @@ -package dgroomes; +package dgroomes.multi_module.module_b; import org.slf4j.Logger; import org.slf4j.LoggerFactory;