diff --git a/README.md b/README.md index 4d8dc1f..83f3b58 100644 --- a/README.md +++ b/README.md @@ -238,11 +238,24 @@ new piece is wanted rather than a repaint of an existing one. ## Building ```sh -./gradlew build +./build.sh ``` -Needs nothing but NeoForge - Truly Modular is a runtime dependency only, since -this mod talks to it purely through datapack JSON. +The jar lands in `build/libs/`. Needs nothing but NeoForge - Truly Modular is a +runtime dependency only, since this mod talks to it purely through datapack +JSON. + +`./gradlew build` does the same thing, and is fine if the java on your path is +one Gradle can run on. Gradle 8.12 cannot run on a JDK newer than 23, which a +distro's default java may well be by now, and the failure when it is says +`Could not create task ':test'` and `Type T not present` without ever mentioning +Java. `build.sh` exists to pick a JDK between 17 and 23 - honouring `JAVA_HOME` +if it already points at one - and to say what is wrong in as many words when +there is none to pick. Extra arguments are passed straight through, so +`./build.sh clean build` and `./build.sh --info` work. + +None of this touches what the mod is compiled against: the toolchain in +`build.gradle` is Java 21 either way, and Gradle provisions it if it is missing. ## Regenerating materials diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..386b333 --- /dev/null +++ b/build.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Builds the mod jar into build/libs/. +# +# Gradle 8.12 cannot run on a JDK newer than 23, and a distro's default java is +# often newer than that, so this picks a JDK Gradle can run on rather than +# leaving you to read the "Type T not present" failure that comes of not doing +# so. The build itself still compiles against Java 21 either way - that is the +# toolchain in build.gradle, and Gradle provisions it if it is missing. +set -euo pipefail + +cd "$(dirname "$0")" + +# Major version of the java at $1/bin/java, or nothing if it will not run. +java_major() { + local out + out=$("$1/bin/java" -version 2>&1) || return 0 + sed -n 's/^[^"]*"\([0-9]*\).*/\1/p' <<<"$out" | head -1 +} + +usable() { + local major + [ -x "$1/bin/java" ] || return 1 + major=$(java_major "$1") + [ -n "$major" ] && [ "$major" -ge 17 ] && [ "$major" -le 23 ] +} + +if [ -z "${JAVA_HOME:-}" ] || ! usable "$JAVA_HOME"; then + for candidate in /usr/lib/jvm/java-{21,17}-openjdk /usr/lib/jvm/java-{21,17}-openjdk-amd64; do + if usable "$candidate"; then + export JAVA_HOME="$candidate" + break + fi + done +fi + +if [ -z "${JAVA_HOME:-}" ] || ! usable "$JAVA_HOME"; then + echo "build.sh: no JDK between 17 and 23 found - Gradle 8.12 cannot run on anything newer." >&2 + echo "Install one (e.g. pacman -S jdk17-openjdk) or point JAVA_HOME at it." >&2 + exit 1 +fi + +echo "build.sh: using JDK $(java_major "$JAVA_HOME") at $JAVA_HOME" +./gradlew build "$@" + +# Name the jar this run produced. Old versions linger in build/libs/, so listing +# the whole directory would be ambiguous about which one is current. +prop() { sed -n "s/^$1=//p" gradle.properties; } +jar="build/libs/$(prop mod_id)-$(prop mod_version).jar" + +echo +if [ -f "$jar" ]; then + echo "Built: $jar" +else + echo "build.sh: expected $jar, but it is not there." >&2 + exit 1 +fi