|
| 1 | +JDK_VERSIONS := 11 17 21 |
| 2 | + |
| 3 | +.PHONY: help |
| 4 | +help: |
| 5 | + @echo "Usage:" |
| 6 | + @echo " make test - Run full tests (clean verify) on all supported JDKs ($(JDK_VERSIONS))" |
| 7 | + @echo " make compile - Run clean compile on all supported JDKs ($(JDK_VERSIONS))" |
| 8 | + @echo " make version - Show current project version" |
| 9 | + @echo " make test-jdk-XX - Run tests on a specific JDK version (e.g., make test-jdk-11)" |
| 10 | + |
| 11 | +.PHONY: version |
| 12 | +version: |
| 13 | + @mvn help:evaluate -Dexpression=project.version -q -DforceStdout |
| 14 | + @echo |
| 15 | + |
| 16 | +.PHONY: test |
| 17 | +test: $(addprefix test-jdk-,$(JDK_VERSIONS)) |
| 18 | + |
| 19 | +.PHONY: compile |
| 20 | +compile: $(addprefix compile-jdk-,$(JDK_VERSIONS)) |
| 21 | + |
| 22 | +test-jdk-%: |
| 23 | + @echo "------------------------------------------------------------" |
| 24 | + @echo "Testing with JDK $*..." |
| 25 | + @actual_home=$$(/usr/libexec/java_home -v $* 2>/dev/null); \ |
| 26 | + actual_version=$$([ -n "$$actual_home" ] && "$$actual_home/bin/java" -XshowSettings:properties -version 2>&1 | grep "java.specification.version" | awk '{print $$3}' | tr -d '"'); \ |
| 27 | + if [ "$$actual_version" != "$*" ]; then \ |
| 28 | + brew_path=$$(brew --prefix openjdk@$* 2>/dev/null); \ |
| 29 | + if [ -n "$$brew_path" ] && [ -d "$$brew_path/libexec/openjdk.jdk/Contents/Home" ]; then \ |
| 30 | + actual_home="$$brew_path/libexec/openjdk.jdk/Contents/Home"; \ |
| 31 | + actual_version=$$("$$actual_home/bin/java" -XshowSettings:properties -version 2>&1 | grep "java.specification.version" | awk '{print $$3}' | tr -d '"'); \ |
| 32 | + fi; \ |
| 33 | + fi; \ |
| 34 | + if [ "$$actual_version" != "$*" ]; then \ |
| 35 | + echo "ERROR: JDK $* not found or not active."; \ |
| 36 | + echo "To install it, run: brew install openjdk@$*"; \ |
| 37 | + exit 1; \ |
| 38 | + fi; \ |
| 39 | + export JAVA_HOME="$$actual_home"; \ |
| 40 | + mvn -version; \ |
| 41 | + mvn clean verify -Dgpg.skip |
| 42 | + |
| 43 | +compile-jdk-%: |
| 44 | + @echo "------------------------------------------------------------" |
| 45 | + @echo "Compiling with JDK $*..." |
| 46 | + @actual_home=$$(/usr/libexec/java_home -v $* 2>/dev/null); \ |
| 47 | + actual_version=$$([ -n "$$actual_home" ] && "$$actual_home/bin/java" -XshowSettings:properties -version 2>&1 | grep "java.specification.version" | awk '{print $$3}' | tr -d '"'); \ |
| 48 | + if [ "$$actual_version" != "$*" ]; then \ |
| 49 | + brew_path=$$(brew --prefix openjdk@$* 2>/dev/null); \ |
| 50 | + if [ -n "$$brew_path" ] && [ -d "$$brew_path/libexec/openjdk.jdk/Contents/Home" ]; then \ |
| 51 | + actual_home="$$brew_path/libexec/openjdk.jdk/Contents/Home"; \ |
| 52 | + actual_version=$$("$$actual_home/bin/java" -XshowSettings:properties -version 2>&1 | grep "java.specification.version" | awk '{print $$3}' | tr -d '"'); \ |
| 53 | + fi; \ |
| 54 | + fi; \ |
| 55 | + if [ "$$actual_version" != "$*" ]; then \ |
| 56 | + echo "ERROR: JDK $* not found or not active."; \ |
| 57 | + echo "To install it, run: brew install openjdk@$*"; \ |
| 58 | + exit 1; \ |
| 59 | + fi; \ |
| 60 | + export JAVA_HOME="$$actual_home"; \ |
| 61 | + mvn -version; \ |
| 62 | + mvn clean compile |
0 commit comments