diff --git a/build.gradle b/build.gradle index a7541a896b1..78bbb8ba9a4 100644 --- a/build.gradle +++ b/build.gradle @@ -20,12 +20,12 @@ import java.time.format.DateTimeFormatter plugins { id "base" - id "com.palantir.consistent-versions" version "1.28.0" + id "com.palantir.consistent-versions" version "2.0.0" id "org.owasp.dependencycheck" version "5.3.0" id 'de.thetaphi.forbiddenapis' version '3.1' apply false id "de.undercouch.download" version "4.1.1" apply false id "net.ltgt.errorprone" version "1.2.1" apply false - id 'com.diffplug.spotless' version "5.8.2" apply false + id 'com.diffplug.spotless' version "5.14.3" apply false } apply from: file('gradle/globals.gradle') diff --git a/gradle/documentation/render-javadoc.gradle b/gradle/documentation/render-javadoc.gradle index d0e756a13c3..411d83a5643 100644 --- a/gradle/documentation/render-javadoc.gradle +++ b/gradle/documentation/render-javadoc.gradle @@ -1,3 +1,5 @@ +import org.gradle.internal.jvm.Jvm + import javax.annotation.Nullable /* @@ -287,7 +289,7 @@ class RenderJavadocTask extends DefaultTask { @Input @Optional - Property luceneDocUrl = project.objects.property(String) + final Property luceneDocUrl = project.objects.property(String) // default is to require full javadocs @Input @@ -305,10 +307,10 @@ class RenderJavadocTask extends DefaultTask { @Optional ListProperty extraOpts = project.objects.listProperty(String) - @Nullable @Optional @Input - def executable + final Property executable = project.objects.property(String).convention( + project.provider { Jvm.current().javadocExecutable.toString() }) @Input def taskResources @@ -443,16 +445,7 @@ class RenderJavadocTask extends DefaultTask { } }) - def javadocCmd = { - if (executable == null) { - JavaInstallationRegistry registry = project.extensions.getByType(JavaInstallationRegistry) - JavaInstallation currentJvm = registry.installationForCurrentVirtualMachine.get() - return currentJvm.jdk.get().javadocExecutable.asFile - } else { - return project.file(executable) - } - }() - + def javadocCmd = project.file(executable.get()) logger.info("Javadoc executable used: ${javadocCmd}") project.quietExec { diff --git a/gradle/generation/javacc.gradle b/gradle/generation/javacc.gradle index fc51dae6ec6..b639d01a37c 100644 --- a/gradle/generation/javacc.gradle +++ b/gradle/generation/javacc.gradle @@ -269,6 +269,8 @@ class JavaCCTask extends DefaultTask { * Apply closures to all generated files before they're copied back * to mainline code. */ + // A subtle bug here is that this makes it not an input... should be a list of replacements instead? + @Internal List> afterGenerate = new ArrayList<>() @OutputFiles diff --git a/gradle/generation/jflex.gradle b/gradle/generation/jflex.gradle index aa60d7fa9e2..02e8da940cb 100644 --- a/gradle/generation/jflex.gradle +++ b/gradle/generation/jflex.gradle @@ -222,7 +222,7 @@ class JFlexTask extends DefaultTask { @InputFile File skeleton - @Optional + @Internal String heapSize @OutputFile diff --git a/gradle/generation/local-settings.gradle b/gradle/generation/local-settings.gradle index 806049f43f4..bc6cbab2503 100644 --- a/gradle/generation/local-settings.gradle +++ b/gradle/generation/local-settings.gradle @@ -53,7 +53,14 @@ configure(rootProject) { "org.gradle.workers.max=${maxWorkers}", "", "# Maximum number of test JVMs forked per test task.", - "tests.jvms=${testsJvms}" + "tests.jvms=${testsJvms}", + "", + "# Disable auto JVM provisioning", + "org.gradle.java.installations.auto-download=false", + "", + "# Set these to enable automatic JVM location discovery.", + "# org.gradle.java.installations.fromEnv=JDK11,JDK12,JDK13,JDK14,JDK15,JDK16,JDK17", + "# org.gradle.java.installations.paths=(custom paths)", ].join("\n"), "UTF-8") logger.log(LogLevel.WARN, "\nIMPORTANT. This is the first time you ran the build. " + diff --git a/gradle/testing/alternative-jdk-support.gradle b/gradle/testing/alternative-jdk-support.gradle index 2b252afe3f0..d12a39d96dc 100644 --- a/gradle/testing/alternative-jdk-support.gradle +++ b/gradle/testing/alternative-jdk-support.gradle @@ -1,3 +1,9 @@ + +import org.gradle.internal.jvm.JavaInfo +import org.gradle.internal.jvm.Jvm +import org.gradle.internal.jvm.inspection.JvmInstallationMetadata +import org.gradle.internal.jvm.inspection.JvmMetadataDetector + /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -16,62 +22,68 @@ */ // This adds support for compiling and testing against a different Java runtime. -// This is the only way to build against JVMs not yet supported by Gradle itself. +// +// I failed to set it up leveraging Gradle's toolchains because +// a toolchain spec is not flexible enough to provide an exact location of the JVM to be used; +// if you have two identical JVM lang. versions in auto-discovered JVMs, an arbitrary one is used (?). +// This situation is not uncommon when debugging low-level stuff (hand-compiled JVM binaries). +// +// The code below is a workaround using internal gradle classes. It may stop working in the future +// but for now it's fine. -JavaInstallationRegistry registry = extensions.getByType(JavaInstallationRegistry) - -JavaInstallation currentJvm = registry.installationForCurrentVirtualMachine.get() - -JavaInstallation altJvm = { +JavaInfo jvmGradle = Jvm.current(); +JavaInfo jvmCurrent = { def runtimeJavaHome = propertyOrDefault("runtime.java.home", System.getenv('RUNTIME_JAVA_HOME')) - if (!runtimeJavaHome) { - return currentJvm + if (runtimeJavaHome != null) { + return Jvm.forHome(file(runtimeJavaHome)) } else { - return registry.installationForDirectory( - layout.projectDirectory.dir(runtimeJavaHome)).get() + return jvmGradle } }() -// Set up root project's property. -rootProject.ext.runtimeJava = altJvm -rootProject.ext.runtimeJavaVersion = altJvm.javaVersion - -if (!currentJvm.javaExecutable.equals(altJvm.javaExecutable)) { - // Set up java toolchain tasks to use the alternative Java. - // This is a related Gradle issue for the future: - // https://github.com/gradle/gradle/issues/1652 +JvmMetadataDetector jvmDetector = project.services.get(JvmMetadataDetector) +if (jvmGradle != jvmCurrent) { configure(rootProject) { task altJvmWarning() { doFirst { + + def jvmInfo = { JavaInfo javaInfo -> + JvmInstallationMetadata jvmMetadata = jvmDetector.getMetadata(javaInfo.javaHome) + return "${jvmMetadata.languageVersion} (${jvmMetadata.displayName} ${jvmMetadata.runtimeVersion}, home at: ${jvmMetadata.javaHome})" + } + logger.warn("""NOTE: Alternative java toolchain will be used for compilation and tests: - Project will use Java ${altJvm.javaVersion} from: ${altJvm.installationDirectory} - Gradle runs with Java ${currentJvm.javaVersion} from: ${currentJvm.installationDirectory} + Project will use ${jvmInfo(jvmCurrent)} + Gradle runs with ${jvmInfo(jvmGradle)} """) } } } - // Set up toolchain-dependent tasks to use the alternative JVM. allprojects { // Any tests tasks.withType(Test) { dependsOn ":altJvmWarning" - executable = altJvm.javaExecutable + executable = jvmCurrent.javaExecutable } // Any javac compilation tasks tasks.withType(JavaCompile) { dependsOn ":altJvmWarning" options.fork = true - options.forkOptions.javaHome = altJvm.installationDirectory.asFile + options.forkOptions.javaHome = jvmCurrent.javaHome } // Javadoc compilation. - def javadocExecutable = altJvm.jdk.get().javadocExecutable.asFile + def javadocExecutable = jvmCurrent.javadocExecutable tasks.matching { it.name == "renderJavadoc" || it.name == "renderSiteJavadoc" }.all { dependsOn ":altJvmWarning" - executable = javadocExecutable + executable = javadocExecutable.toString() } } } + +// Set up root project's properties. +rootProject.ext.runtimeJavaHome = jvmCurrent.javaHome +rootProject.ext.runtimeJavaVersion = jvmDetector.getMetadata(jvmCurrent.javaHome).languageVersion diff --git a/gradle/validation/check-environment.gradle b/gradle/validation/check-environment.gradle index 79350362290..7694f8d5d43 100644 --- a/gradle/validation/check-environment.gradle +++ b/gradle/validation/check-environment.gradle @@ -22,7 +22,7 @@ import org.gradle.util.GradleVersion configure(rootProject) { ext { - expectedGradleVersion = '6.8.3' + expectedGradleVersion = '7.2' } wrapper { diff --git a/gradle/validation/rat-sources.gradle b/gradle/validation/rat-sources.gradle index 96a57c81e93..0f9dff1059e 100644 --- a/gradle/validation/rat-sources.gradle +++ b/gradle/validation/rat-sources.gradle @@ -126,18 +126,16 @@ allprojects { */ class RatTask extends DefaultTask { @InputFiles - ListProperty inputFileTrees = project.objects.listProperty(ConfigurableFileTree) + final ListProperty inputFileTrees = project.objects.listProperty(ConfigurableFileTree) @OutputFile - RegularFileProperty xmlReport = project.objects.fileProperty().convention( + final RegularFileProperty xmlReport = project.objects.fileProperty().convention( project.layout.buildDirectory.file("rat/rat-report.xml")) def generateReport(File reportFile) { // Set up ant rat task. - def uri = 'antlib:org.apache.rat.anttasks' def ratClasspath = project.rootProject.configurations.ratDeps.asPath - ant.taskdef(resource: 'org/apache/rat/anttasks/antlib.xml', uri: uri, classpath: ratClasspath) - def rat = NamespaceBuilder.newInstance(ant, uri) + ant.taskdef(resource: 'org/apache/rat/anttasks/antlib.xml', classpath: ratClasspath) // Collect all output files for debugging. String inputFileList = inputFileTrees.get().collectMany { fileTree -> @@ -146,7 +144,7 @@ class RatTask extends DefaultTask { project.file(reportFile.path.replaceAll('.xml$', '-filelist.txt')).setText(inputFileList, "UTF-8") // Run rat via ant. - rat.report(format: 'xml', reportFile: reportFile, addDefaultLicenseMatchers: true) { + ant.report(format: 'xml', reportFile: reportFile, addDefaultLicenseMatchers: true) { // Pass all gradle file trees to the ant task (Gradle's internal adapters are used). inputFileTrees.get().each { fileTree -> fileTree.addToAntBuilder(ant, 'resources', FileCollection.AntType.ResourceCollection) diff --git a/gradle/wrapper/gradle-wrapper.jar.sha256 b/gradle/wrapper/gradle-wrapper.jar.sha256 index e85f20f9fe4..168e29f1961 100644 --- a/gradle/wrapper/gradle-wrapper.jar.sha256 +++ b/gradle/wrapper/gradle-wrapper.jar.sha256 @@ -1 +1 @@ -e996d452d2645e70c01c11143ca2d3742734a28da2bf61f25c82bdc288c9e637 +33ad4583fd7ee156f533778736fa1b4940bd83b433934d1cc4e9f608e99a6a89 diff --git a/gradle/wrapper/gradle-wrapper.jar.version b/gradle/wrapper/gradle-wrapper.jar.version index 021c9405b1d..0ee843cc604 100644 --- a/gradle/wrapper/gradle-wrapper.jar.version +++ b/gradle/wrapper/gradle-wrapper.jar.version @@ -1 +1 @@ -6.8.3 +7.2.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8cf6eb5ad22..a0f7639f7d3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew.bat b/gradlew.bat index 7ff625a13fb..fe7be72c567 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -42,7 +45,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -56,7 +59,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -66,21 +69,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem LUCENE-9266: verify and download the gradle wrapper jar if we don't have one. @@ -96,7 +84,7 @@ SET GRADLE_DAEMON_CTRL= IF NOT EXIST "%DIRNAME%\gradle.properties" SET GRADLE_DAEMON_CTRL=--no-daemon @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %GRADLE_DAEMON_CTRL% %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %GRADLE_DAEMON_CTRL% %* :end @rem End local scope for the variables with windows NT shell diff --git a/lucene/misc/native/build.gradle b/lucene/misc/native/build.gradle index 2e75a653908..664410ed903 100644 --- a/lucene/misc/native/build.gradle +++ b/lucene/misc/native/build.gradle @@ -41,10 +41,9 @@ library { } tasks.withType(CppCompile).configureEach { - def javaHome = rootProject.ext.runtimeJava.getInstallationDirectory().getAsFile().getPath() + def javaHome = rootProject.ext.runtimeJavaHome - // Assume standard openjdk layout. This means only one architecture-specific include folder - // is present. + // Assume standard openjdk layout. This means only one architecture-specific include folder is present. systemIncludes.from file("${javaHome}/include") for (def path : [file("${javaHome}/include/win32")]) {