LUCENE-10510: Check module access prior to running gjf/spotless tasks (#802)

This commit is contained in:
Dawid Weiss 2022-04-10 20:35:45 +02:00 committed by GitHub
parent ab1394e840
commit ba1062620c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 4 deletions

View File

@ -22,6 +22,30 @@
def hasDefaults = rootProject.file("gradle.properties").exists()
configure(rootProject) {
// Add a task verifying that gradle process has access to JVM internals.
// this is occasionally needed for certain tasks.
task checkJdkInternalsExportedToGradle() {
doFirst {
def jdkCompilerModule = ModuleLayer.boot().findModule("jdk.compiler").orElseThrow()
def gradleModule = getClass().module
def internalsExported = [
"com.sun.tools.javac.api",
"com.sun.tools.javac.file",
"com.sun.tools.javac.parser",
"com.sun.tools.javac.tree",
"com.sun.tools.javac.util"
].stream()
.allMatch(pkg -> jdkCompilerModule.isExported(pkg, gradleModule))
if (!internalsExported) {
throw new GradleException(
"Certain gradle tasks and plugins require access to jdk.compiler" +
" internals, your gradle.properties might have just been generated or could be" +
" out of sync (see help/localSettings.txt)")
}
}
}
task localSettings() {
doFirst {
// If we don't have the defaults yet, create them.
@ -43,7 +67,7 @@ systemProp.file.encoding=UTF-8
# Set up gradle JVM defaults.
# The heap seems huge but gradle runs out of memory on lower values (don't know why).
#
# We also open up internal compiler modules for spotless/ google jaa format.
# We also open up internal compiler modules for spotless/ google java format.
org.gradle.jvmargs=-Xmx3g \\
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \\

View File

@ -22,7 +22,7 @@ if (rootProject.usesAltJvm && rootProject.runtimeJavaVersion > JavaVersion.VERSI
}
if (!Boolean.parseBoolean(propertyOrDefault("tests.nightly", "false"))) {
skipReason = "skipped on non-nightly runs, pass -Dtests.nightly=true to run"
skipReason = "skipped on non-nightly runs, pass -Ptests.nightly=true to run"
}
if (skipReason) {
@ -58,6 +58,8 @@ allprojects { prj ->
}
tasks.withType(JavaCompile) { task ->
task.dependsOn ":checkJdkInternalsExportedToGradle"
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.errorproneArgs = [
'-Xep:InlineMeSuggester:OFF', // We don't use this annotation

View File

@ -103,9 +103,11 @@ configure(project(":lucene").subprojects) { prj ->
tasks.matching { task -> task.name == "spotlessApply" }.configureEach { v ->
tidy.dependsOn v
v.dependsOn ":checkJdkInternalsExportedToGradle"
}
tasks.matching { task -> task.name == "spotlessCheck" }.configureEach { v ->
check.dependsOn v
v.dependsOn ":checkJdkInternalsExportedToGradle"
}
}

View File

@ -4,9 +4,14 @@ Local developer settings
The first invocation of any task in Lucene's gradle build will generate
and save a project-local 'gradle.properties' file. This file contains
the defaults you may (but don't have to) tweak for your particular hardware
(or taste).
(or taste). Note there are certain settings in that file that may
be _required_ at runtime for certain plugins (an example is the spotless/
google java format plugin, which requires adding custom exports to JVM modules). Gradle
build only generates this file if it's not already present (it never overwrites
the defaults) -- occasionally you may have to manually delete (or move) this
file and regenerate from scratch.
This is an overview of some of these settings.
This is an overview of some settings present in gradle.properties.
Parallelism
-----------