diff --git a/Makefile b/Makefile index 38be3c7..68548e0 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ -.PHONY: default help clean build jar run-jar refresh versioncheck build-docker run-docker push-docker release upgrade-wrapper _require-version _require-gradle-version _require-image +.PHONY: default help clean build jar run-jar refresh versions build-docker run-docker \ + push-docker release upgrade-wrapper \ + _require-version _require-gradle-version _require-image -VERSION := $(shell awk -F'=' '/^version[[:space:]]*=/{gsub(/[[:space:]]/,"",$$2); print $$2; exit}' gradle.properties 2>/dev/null) -GRADLE_VERSION := $(shell awk -F'"' '/^gradle[[:space:]]*=/{gsub(/[[:space:]]/,"",$$2); print $$2; exit}' gradle/libs.versions.toml 2>/dev/null) +VERSION := $(shell sed -n 's/^version=\(.*\)/\1/p' gradle.properties) +GRADLE_VERSION := $(shell sed -n 's/^gradle-wrapper = "\(.*\)"/\1/p' gradle/libs.versions.toml) # Override on the command line: `IMAGE_NAME=myorg/vapi4k-template make release` IMAGE_NAME ?= docker_hub_username/vapi4k-template @@ -9,8 +11,9 @@ PLATFORMS := linux/amd64,linux/arm64/v8 default: help -help: ## Show this help message - @awk 'BEGIN {FS = ":.*?## "; printf "Targets (project v$(VERSION), gradle v$(GRADLE_VERSION)):\n\n"} /^[A-Za-z0-9_.-]+:.*?## / {printf " \033[36m%-16s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) +help: ## Show this help (list of targets) + @awk 'BEGIN {FS = ":.*?## "; printf "Usage: make \n\nTargets:\n"} \ + /^[a-zA-Z0-9_-]+:.*?## / {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) clean: ## Remove build artifacts ./gradlew clean @@ -27,7 +30,7 @@ run-jar: jar ## Build and run the fat JAR refresh: ## Refresh dependencies and check for updates ./gradlew --refresh-dependencies dependencyUpdates -versioncheck: ## Check for available dependency updates +versions: ## Check for available dependency updates ./gradlew dependencyUpdates --no-configuration-cache build-docker: _require-version _require-image jar ## Build a single-arch Docker image tagged with the project version @@ -43,7 +46,11 @@ push-docker: _require-version _require-image ## Build and push a multiarch image release: push-docker ## Build and push the multiarch Docker image (single buildx pass) -upgrade-wrapper: _require-gradle-version ## Upgrade the Gradle wrapper to the version pinned in libs.versions.toml +# Gradle's documented upgrade procedure: the first run rewrites +# gradle-wrapper.properties using the *old* wrapper jar; the second run +# regenerates the wrapper itself with the new version. +upgrade-wrapper: _require-gradle-version ## Upgrade the Gradle wrapper to the version pinned in libs.versions.toml + ./gradlew wrapper --gradle-version=$(GRADLE_VERSION) --distribution-type=bin ./gradlew wrapper --gradle-version=$(GRADLE_VERSION) --distribution-type=bin _require-version: diff --git a/build.gradle.kts b/build.gradle.kts index c1bbe84..b940877 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,25 +14,10 @@ val buildFatJarTask = "buildFatJar" val cleanTask = "clean" val stageTask = "stage" -val preReleaseSuffixes = listOf("-RC", "-BETA", "-ALPHA", "-M") - application { mainClass.set(mainClassName) } -ktor { - fatJar { - // Change this to whatever name you want - // It also has to be changed in the Dockerfile - archiveFileName.set(fatJarName) - } -} - -// This must match the version defined in system.properties -kotlin { - jvmToolchain(jvmVersion) -} - dependencies { implementation(libs.vapi4k.core) implementation(libs.vapi4k.dbms) @@ -51,8 +36,44 @@ tasks.named(buildFatJarTask) { mustRunAfter(cleanTask) } -tasks.withType { - rejectVersionIf { - preReleaseSuffixes.any { candidate.version.uppercase().contains(it) } +configureKotlin() +configureKtor() +configureVersions() + +fun Project.configureKotlin() { +// This must match the version defined in system.properties + kotlin { + jvmToolchain(jvmVersion) + } +} + +fun Project.configureKtor() { + ktor { + fatJar { + // Change this to whatever name you want + // It also has to be changed in the Dockerfile + archiveFileName.set(fatJarName) + } + } +} + +fun Project.configureVersions() { + // A pre-release qualifier is a `.` or `-` delimiter followed by a known unstable + // keyword. `m\d` matches milestones (`-M1`/`.M2`) without catching stable classifiers + // like `-macos`/`-MR1`, and the `[.-]` delimiter catches both dash-style (`-alpha`) + // and dot-style (Netty's `.Beta1`) qualifiers while leaving `-jre`/`.Final` stable. + val preReleaseQualifier = + Regex("""[.-](rc|beta|alpha|m\d|cr|snapshot|eap|dev|milestone|pre)""", RegexOption.IGNORE_CASE) + + fun isNonStable(version: String): Boolean = preReleaseQualifier.containsMatchIn(version) + + tasks.withType().configureEach { + notCompatibleWithConfigurationCache("the dependency updates plugin is not compatible with the configuration cache") + // Reject a pre-release candidate only when the current version is stable. For + // dependencies we intentionally track on a pre-release line (e.g. a detekt + // alpha), newer pre-releases are still surfaced as available updates. + rejectVersionIf { + isNonStable(candidate.version) && !isNonStable(currentVersion) + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d14c82f..c693ef3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] -gradle = "9.5.0" +gradle-wrapper = "9.6.1" jvm = "21" -kotlin = "2.3.21" -ktor = "3.4.3" +kotlin = "2.4.0" +ktor = "3.5.1" versions = "0.54.0" -vapi4k = "1.7.0" +vapi4k = "1.8.0" [libraries] vapi4k-core = { group = "com.vapi4k", name = "vapi4k-core", version.ref = "vapi4k" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d997cfc..b1b8ef5 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1a70468..a9db115 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,9 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip networkTimeout=10000 +retries=0 +retryBackOffMs=500 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 739907d..249efbb 100755 --- a/gradlew +++ b/gradlew @@ -20,7 +20,7 @@ ############################################################################## # -# Gradle start up script for POSIX generated by Gradle. +# gradlew start up script for POSIX generated by Gradle. # # Important for running: # @@ -29,7 +29,7 @@ # bash, then to run this script, type that shell name before the whole # command line, like: # -# ksh Gradle +# ksh gradlew # # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: @@ -57,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. diff --git a/gradlew.bat b/gradlew.bat index e509b2d..8508ef6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -19,12 +19,12 @@ @if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem -@rem Gradle startup script for Windows +@rem gradlew startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. @@ -51,7 +51,7 @@ echo. 1>&2 echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% @@ -65,29 +65,18 @@ echo. 1>&2 echo Please set the JAVA_HOME variable in your environment to match the 1>&2 echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :execute @rem Setup the command line -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL%