Skip to content

Commit

Permalink
fixes(#5439): Build should enforce a required jdk version
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiesler committed Apr 30, 2024
1 parent ec37c06 commit 2c4bc8d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/modules/ROOT/pages/contributing/developers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ In order to build the project, you need to comply with the following requirement

* **Go version 1.16+**: needed to compile and test the project. Refer to the https://golang.org/[Go website] for the installation.
* **GNU Make**: used to define composite build actions. This should be already installed or available as a package if you have a good OS (https://www.gnu.org/software/make/).
* **JDK version 17+**: the build requires JDK version 17 or above. This corresponds to the JDK version of the integration base image.
* **Maven version 3.8+**: the build requires Maven 3.8 or above. This corresponds to the version defined in the `build/Dockerfile`.
* **MinGW**: needed to compile the project on Windows. Refer to the https://www.mingw-w64.org/[MinGW website] for the installation.
* **Windows Subsystem for Linux (WSL)**: for running Linux binary executables natively on Windows. Refer to https://docs.microsoft.com/en-us/windows/wsl/install[WSL Website] for installation. Alternatively, you can use https://www.cygwin.com/[Cygwin] or https://www.educative.io/edpresso/how-to-install-git-bash-in-windows[Git Bash].

Expand Down
5 changes: 4 additions & 1 deletion script/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ build-platform: build build-kamel-platform

ci-build: clean codegen set-version check-licenses dir-licenses build-kamel cross-compile

do-build: gotestfmt-install
check_jdk_version:
@go run ./script/check_jdk_version.go

do-build: gotestfmt-install check_jdk_version
ifeq ($(DO_TEST_PREBUILD),true)
TEST_PREBUILD = build
else
Expand Down
33 changes: 33 additions & 0 deletions script/check_jdk_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
"os/exec"
"regexp"
"strconv"
)

func main() {

cmd := exec.Command("java", "-version")
output, err := cmd.CombinedOutput()
if err != nil {
panic(fmt.Sprintf("Error: %v\n", err))
}

versionStr := string(output)
versionRegex := regexp.MustCompile(`(.*) version "([1-9]+)(\.([0-9]+)){2,3}" (.*)`)
matches := versionRegex.FindStringSubmatch(versionStr)
if len(matches) < 3 {
panic(fmt.Sprintf("Unable to determine Java version: %s\n", versionStr))
}

majorVersion, err := strconv.Atoi(matches[2])
if err != nil {
panic(fmt.Sprintf("Error parsing Java version: %s - %v\n", versionStr, err))
}

if majorVersion < 17 {
panic(fmt.Sprintf("JDK version is below 17: %s\n", versionStr))
}
}

0 comments on commit 2c4bc8d

Please sign in to comment.