Skip to content

Commit 07fe680

Browse files
authored
Update gradle to 8.13 to fix command exec on java 21 (#2571)
Updates gradle version to fix command execution for java 21. With that, it simplifies overall gradle script and not having to locate dependencies. The environment is inherited from the path. Signed-off-by: John Mazanec <jmazane@amazon.com>
1 parent 0d06b23 commit 07fe680

File tree

9 files changed

+42
-102
lines changed

9 files changed

+42
-102
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
### Documentation
1919
### Maintenance
2020
* Update package name to fix compilation issue [#2513](https://github.com/opensearch-project/k-NN/pull/2513)
21+
* Update gradle to 8.13 to fix command exec on java 21 [#2571](https://github.com/opensearch-project/k-NN/pull/2571)
2122
### Refactoring
2223
* Small Refactor Post Lucene 10.0.1 upgrade [#2541](https://github.com/opensearch-project/k-NN/pull/2541)
2324
* Refactor codec to leverage backwards_codecs [#2546](https://github.com/opensearch-project/k-NN/pull/2546)

build.gradle

+15-78
Original file line numberDiff line numberDiff line change
@@ -329,50 +329,9 @@ task windowsPatches(type:Exec) {
329329
commandLine 'cmd', '/c', "Powershell -File $rootDir\\scripts\\windowsScript.ps1"
330330
}
331331

332-
def findExecutable(String executableName, List<String> additionalPaths = []) {
333-
// Print the task's environment before setting it
334-
// Print PATH specifically
335-
logger.lifecycle("\nSystem PATH:")
336-
logger.lifecycle(System.getenv("PATH"))
337-
338-
def commonBasePaths = [
339-
"/opt/homebrew/bin",
340-
"/usr/local/bin",
341-
"/usr/bin"
342-
]
343-
344-
// Start with just the executable name (will use system PATH)
345-
def execPath = executableName
346-
347-
if (Os.isFamily(Os.FAMILY_MAC)) {
348-
def searchPaths = []
349-
// Add common paths
350-
commonBasePaths.each { basePath ->
351-
searchPaths.add("${basePath}/${executableName}")
352-
}
353-
// Add any additional specific paths
354-
searchPaths.addAll(additionalPaths)
355-
356-
for (path in searchPaths) {
357-
if (new File(path).exists()) {
358-
logger.lifecycle("Found ${executableName} at: ${path}")
359-
execPath = path
360-
break
361-
}
362-
}
363-
}
364-
365-
return execPath
366-
}
367-
368332
tasks.register('cmakeJniLib', Exec) {
369-
def cmakePath = findExecutable("cmake")
370-
logger.lifecycle("Using cmake at: ${cmakePath}")
371-
// Inherit the current environment
372-
environment System.getenv()
373-
374333
def args = []
375-
args.add(cmakePath)
334+
args.add("cmake")
376335
args.add("-S jni") // CMakelists.txt directory
377336
args.add("-B jni/build") // Build directory
378337
args.add("-DKNN_PLUGIN_VERSION=${opensearch_version}")
@@ -383,9 +342,6 @@ tasks.register('cmakeJniLib', Exec) {
383342
args.add("-DAPPLY_LIB_PATCHES=${apply_lib_patches}")
384343
def javaHome = Jvm.current().getJavaHome()
385344
logger.lifecycle("Java home directory used by gradle: $javaHome")
386-
if (Os.isFamily(Os.FAMILY_MAC)) {
387-
environment('JAVA_HOME', javaHome)
388-
}
389345
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
390346
dependsOn windowsPatches
391347
args.add("-G")
@@ -394,10 +350,6 @@ tasks.register('cmakeJniLib', Exec) {
394350
args.add("-DLAPACK_LIBRARIES=$rootDir\\src\\main\\resources\\windowsDependencies\\libopenblas.dll")
395351
}
396352

397-
// Print the task's environment after setting it
398-
logger.lifecycle("\nTask Environment PATH:")
399-
logger.lifecycle(environment.get('PATH'))
400-
401353
// Print the command that will be executed
402354
logger.lifecycle("CMake command: ${args.join(' ')}")
403355
def outputStream = new ByteArrayOutputStream()
@@ -411,38 +363,25 @@ tasks.clean.doFirst {
411363
delete "${projectDir}/jni/build"
412364
}
413365

414-
task buildNmslib(type:Exec) {
366+
tasks.register('buildJniLib', Exec) {
415367
dependsOn cmakeJniLib
416-
def cmakePath = findExecutable("cmake")
417-
logger.lifecycle("Using cmake at: ${cmakePath}")
418-
419-
if (cmakePath.isEmpty()) {
420-
throw new GradleException("CMake not found in PATH. Please install CMake.")
421-
}
422-
423-
commandLine cmakePath,
424-
'--build', 'jni/build',
425-
'--target', 'opensearchknn_nmslib',
426-
'--parallel', "${nproc_count}"
427-
}
428-
429-
task buildJniLib(type:Exec) {
430-
dependsOn cmakeJniLib
431-
def cmakePath = findExecutable("cmake")
432-
logger.lifecycle("Using cmake at: ${cmakePath}")
433-
434-
if (cmakePath.isEmpty()) {
435-
throw new GradleException("CMake not found in PATH. Please install CMake.")
368+
def args = []
369+
args.add("cmake")
370+
args.add("--build")
371+
args.add("jni/build")
372+
args.add("--target")
373+
def knn_libs = ['opensearchknn_faiss', 'opensearchknn_common', 'opensearchknn_nmslib']
374+
if (project.hasProperty('knn_libs')) {
375+
knn_libs = ['opensearchknn_common'] + project.knn_libs.split(',').collect { it.trim() }
436376
}
437-
438-
commandLine cmakePath,
439-
'--build', 'jni/build',
440-
'--target', 'opensearchknn_faiss', 'opensearchknn_common',
441-
'--parallel', "${nproc_count}"
377+
args.addAll(knn_libs)
378+
args.add("--parallel")
379+
args.add("${nproc_count}")
380+
logger.lifecycle("Build command: ${args.join(' ')}")
381+
commandLine args
442382
}
443383

444384
test {
445-
dependsOn buildNmslib
446385
dependsOn buildJniLib
447386
systemProperty 'tests.security.manager', 'false'
448387
systemProperty "java.library.path", "$rootDir/jni/build/release"
@@ -457,7 +396,6 @@ test {
457396
def _numNodes = findProperty('numNodes') as Integer ?: 1
458397
integTest {
459398
if (integTestDependOnJniLib) {
460-
dependsOn buildNmslib
461399
dependsOn buildJniLib
462400
}
463401
systemProperty 'tests.security.manager', 'false'
@@ -564,7 +502,6 @@ task integTestRemote(type: RestIntegTestTask) {
564502

565503
run {
566504
useCluster project.testClusters.integTest
567-
dependsOn buildNmslib
568505
dependsOn buildJniLib
569506
doFirst {
570507
// There seems to be an issue when running multi node run or integ tasks with unicast_hosts

gradle/wrapper/gradle-wrapper.jar

-19.5 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
distributionBase=GRADLE_USER_HOME
77
distributionPath=wrapper/dists
8-
distributionSha256Sum=2ab88d6de2c23e6adae7363ae6e29cbdd2a709e992929b48b6530fd0c7133bd6
9-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
8+
distributionSha256Sum=fba8464465835e74f7270bbf43d6d8a8d7709ab0a43ce1aa3323f73e9aa0c612
9+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
1010
networkTimeout=10000
1111
validateDistributionUrl=true
1212
zipStoreBase=GRADLE_USER_HOME

gradlew

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# See the License for the specific language governing permissions and
2020
# limitations under the License.
2121
#
22+
# SPDX-License-Identifier: Apache-2.0
23+
#
2224

2325
##############################################################################
2426
#
@@ -59,7 +61,7 @@
5961
# Darwin, MinGW, and NonStop.
6062
#
6163
# (3) This script is generated from the Groovy template
62-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
64+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
6365
# within the Gradle project.
6466
#
6567
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -88,7 +90,7 @@ done
8890
# shellcheck disable=SC2034
8991
APP_BASE_NAME=${0##*/}
9092
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
91-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
93+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
9294

9395
# Use the maximum available, or set MAX_FD != -1 to use that value.
9496
MAX_FD=maximum
@@ -207,7 +209,7 @@ fi
207209
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
208210

209211
# Collect all arguments for the java command:
210-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
212+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
211213
# and any embedded shellness will be escaped.
212214
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
213215
# treated as '${Hostname}' itself on the command line.

gradlew.bat

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@rem
21
@rem Copyright OpenSearch Contributors
32
@rem SPDX-License-Identifier: Apache-2.0
43
@rem
54
@rem
5+
@rem
66
@rem Copyright 2015 the original author or authors.
77
@rem
88
@rem Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +17,8 @@
1717
@rem See the License for the specific language governing permissions and
1818
@rem limitations under the License.
1919
@rem
20+
@rem SPDX-License-Identifier: Apache-2.0
21+
@rem
2022

2123
@if "%DEBUG%"=="" @echo off
2224
@rem ##########################################################################
@@ -47,11 +49,11 @@ set JAVA_EXE=java.exe
4749
%JAVA_EXE% -version >NUL 2>&1
4850
if %ERRORLEVEL% equ 0 goto execute
4951

50-
echo.
51-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
52-
echo.
53-
echo Please set the JAVA_HOME variable in your environment to match the
54-
echo location of your Java installation.
52+
echo. 1>&2
53+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
54+
echo. 1>&2
55+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
56+
echo location of your Java installation. 1>&2
5557

5658
goto fail
5759

@@ -61,11 +63,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
6163

6264
if exist "%JAVA_EXE%" goto execute
6365

64-
echo.
65-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
66-
echo.
67-
echo Please set the JAVA_HOME variable in your environment to match the
68-
echo location of your Java installation.
66+
echo. 1>&2
67+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
68+
echo. 1>&2
69+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
70+
echo location of your Java installation. 1>&2
6971

7072
goto fail
7173

qa/restart-upgrade/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ testClusters {
135135
// All nodes are upgraded to latest version and run the tests
136136
task testRestartUpgrade(type: StandaloneRestIntegTestTask) {
137137
dependsOn "testAgainstOldCluster"
138-
dependsOn rootProject.tasks.buildNmslib
139138
dependsOn rootProject.tasks.buildJniLib
140139
dependsOn rootProject.tasks.assemble
141140
useCluster testClusters."${baseName}"

qa/rolling-upgrade/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ task testAgainstOldCluster(type: StandaloneRestIntegTestTask) {
5252
// This results in a mixed cluster with 2 nodes on the old version and 1 upgraded node.
5353
task testAgainstOneThirdUpgradedCluster(type: StandaloneRestIntegTestTask) {
5454
useCluster testClusters."${baseName}"
55-
dependsOn rootProject.tasks.buildNmslib
5655
dependsOn rootProject.tasks.buildJniLib
5756
dependsOn rootProject.tasks.assemble
5857
dependsOn "testAgainstOldCluster"

scripts/build.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,27 @@ fi
130130
# Build k-NN lib and plugin through gradle tasks
131131
cd $work_dir
132132
./gradlew build --no-daemon --refresh-dependencies -x integTest -x test -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER -Dbuild.lib.commit_patches=false
133-
./gradlew :buildJniLib -Davx512.enabled=false -Davx512_spr.enabled=false -Davx2.enabled=false -Dbuild.lib.commit_patches=false -Dnproc.count=${NPROC_COUNT:-1}
133+
./gradlew :buildJniLib -Pknn_libs=opensearchknn_faiss -Davx512.enabled=false -Davx512_spr.enabled=false -Davx2.enabled=false -Dbuild.lib.commit_patches=false -Dnproc.count=${NPROC_COUNT:-1}
134134

135135
if [ "$PLATFORM" != "windows" ] && [ "$ARCHITECTURE" = "x64" ]; then
136136
echo "Building k-NN library nmslib with gcc 10 on non-windows x64"
137137
rm -rf jni/CMakeCache.txt jni/CMakeFiles
138-
env CC=gcc10-gcc CXX=gcc10-g++ FC=gcc10-gfortran ./gradlew :buildNmslib -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
138+
env CC=gcc10-gcc CXX=gcc10-g++ FC=gcc10-gfortran ./gradlew :buildJniLib -Pknn_libs=opensearchknn_nmslib -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
139139

140140
echo "Building k-NN library after enabling AVX2"
141141
# Skip applying patches as patches were applied already from previous :buildJniLib task
142142
# If we apply patches again, it fails with conflict
143143
rm -rf jni/CMakeCache.txt jni/CMakeFiles
144-
./gradlew :buildJniLib -Davx2.enabled=true -Davx512.enabled=false -Davx512_spr.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
144+
./gradlew :buildJniLib -Pknn_libs=opensearchknn_faiss -Davx2.enabled=true -Davx512.enabled=false -Davx512_spr.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
145145

146146
echo "Building k-NN library after enabling AVX512"
147-
./gradlew :buildJniLib -Davx512.enabled=true -Davx512_spr.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
147+
./gradlew :buildJniLib -Pknn_libs=opensearchknn_faiss -Davx512.enabled=true -Davx512_spr.enabled=false -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
148148

149149
echo "Building k-NN library after enabling AVX512_SPR"
150-
./gradlew :buildJniLib -Davx512_spr.enabled=true -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
150+
./gradlew :buildJniLib -Pknn_libs=opensearchknn_faiss -Davx512_spr.enabled=true -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
151151

152152
else
153-
./gradlew :buildNmslib -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
153+
./gradlew :buildJniLib -Pknn_libs=opensearchknn_nmslib -Dbuild.lib.commit_patches=false -Dbuild.lib.apply_patches=false
154154
fi
155155

156156
./gradlew publishPluginZipPublicationToZipStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER

0 commit comments

Comments
 (0)