Skip to content

Commit e1ed677

Browse files
committed
Build MR JAR and prepare compilation with Gradle toolchains
1 parent 26f062e commit e1ed677

17 files changed

Lines changed: 591 additions & 136 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ext {
7272
}
7373

7474
// Minimum Java version required to compile and run Lucene.
75-
minJavaVersion = JavaVersion.VERSION_19
75+
minJavaVersion = JavaVersion.VERSION_17
7676

7777
// snapshot build marker used in scripts.
7878
snapshotBuild = version.contains("SNAPSHOT")

gradle/generation/local-settings.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ org.gradle.workers.max=${maxWorkers}
9898
# Maximum number of test JVMs forked per test task.
9999
tests.jvms=${testsJvms}
100100
101-
# Disable auto JVM provisioning (we don't use toolchains yet but want no surprises).
102-
org.gradle.java.installations.auto-download=false
103-
104101
# Set these to enable automatic JVM location discovery.
105102
org.gradle.java.installations.fromEnv=JDK11,JDK12,JDK13,JDK14,JDK15,JDK16,JDK17
106103
org.gradle.java.installations.paths=(custom paths)

gradle/java/javac.gradle

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ allprojects {
5555
"-Xlint:-path",
5656
"-Xlint:processing",
5757
"-Xlint:rawtypes",
58-
"-Xlint:-removal",
58+
"-Xlint:removal",
5959
"-Xlint:requires-automatic",
6060
"-Xlint:requires-transitive-automatic",
6161
"-Xlint:-serial",
@@ -66,18 +66,66 @@ allprojects {
6666
"-Xlint:try",
6767
"-Xlint:unchecked",
6868
"-Xlint:varargs",
69-
"-Xlint:-preview",
69+
"-Xlint:preview",
7070
"-Xdoclint:all/protected",
7171
"-Xdoclint:-missing",
7272
"-Xdoclint:-accessibility",
7373
"-proc:none", // proc:none was added because of LOG4J2-1925 / JDK-8186647
74-
75-
"--enable-preview"
7674
]
7775

7876
if (propertyOrDefault("javac.failOnWarnings", true).toBoolean()) {
79-
// disabled in this branch: options.compilerArgs += "-Werror"
77+
options.compilerArgs += "-Werror"
78+
}
79+
}
80+
}
81+
}
82+
83+
configure(project(":lucene:core")) {
84+
plugins.withType(JavaPlugin) {
85+
sourceSets {
86+
main19 {
87+
java {
88+
srcDirs = ['src/java19']
89+
}
90+
}
91+
}
92+
93+
configurations {
94+
// Inherit any dependencies from the main source set.
95+
main19Implementation.extendsFrom implementation
96+
}
97+
98+
dependencies {
99+
// We need the main classes to compile our Java 19 pieces.
100+
main19Implementation sourceSets.main.output
101+
}
102+
103+
tasks.named('compileMain19Java').configure {
104+
/* This will work when JDK 19 comes out:
105+
106+
// select EA build:
107+
javaCompiler = javaToolchains.compilerFor {
108+
languageVersion = JavaLanguageVersion.of(19)
109+
vendor = JvmVendorSpec.ADOPTOPENJDK
110+
}
111+
112+
// undo alternative JDK support:
113+
options.forkOptions.javaHome = null
114+
*/
115+
116+
sourceCompatibility = 19
117+
targetCompatibility = 19
118+
options.compilerArgs += ["--release", 19 as String, "--enable-preview"]
119+
}
120+
121+
tasks.named('jar').configure {
122+
into('META-INF/versions/19') {
123+
from sourceSets.main19.output
80124
}
125+
126+
manifest.attributes(
127+
'Multi-Release': 'true'
128+
)
81129
}
82130
}
83131
}

gradle/validation/ecj-lint.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ allprojects {
3434
// Create a [sourceSetName]EcjLint task for each source set
3535
// with a non-empty java.srcDirs. These tasks are then
3636
// attached to project's "ecjLint" task.
37-
def lintTasks = sourceSets.collect { sourceSet ->
37+
def lintTasks = sourceSets.findAll { it.name != 'main19' }.collect { sourceSet ->
3838
def srcDirs = sourceSet.java.sourceDirectories
3939
.filter { dir -> dir.exists() }
4040

gradle/validation/forbidden-apis.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ allprojects { prj ->
115115
inputs.dir(file(resources))
116116
}
117117

118+
tasks.matching { it.name == "forbiddenApisMain19" }.all {
119+
enabled = false
120+
}
121+
118122
// We rely on resolved configurations to compute the relevant set of rule
119123
// files for forbiddenApis. Since we don't want to resolve these configurations until
120124
// the task is executed, we can't really use them as task inputs properly. This is a

lucene/core.tests/src/test/org/apache/lucene/core/tests/TestMMap.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class TestMMap extends LuceneTestCase {
2424
public void testUnmapSupported() {
2525
final Module module = MMapDirectory.class.getModule();
2626
Assert.assertTrue("Lucene Core is not loaded as module", module.isNamed());
27+
Assert.assertTrue(
28+
"Lucene Core can't read 'jdk.unsupported' module",
29+
module.getLayer().findModule("jdk.unsupported").map(module::canRead).orElse(false));
2730

2831
// check that MMapDirectory can unmap by running the autodetection logic:
2932
Assert.assertTrue(MMapDirectory.UNMAP_NOT_SUPPORTED_REASON, MMapDirectory.UNMAP_SUPPORTED);

lucene/core/src/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@SuppressWarnings("module") // the test framework is compiled after the core...
2323
module org.apache.lucene.core {
2424
requires java.logging;
25+
requires static jdk.unsupported; // this is optional but without it MMapDirectory won't be enabled
2526
requires static jdk.management; // this is optional but explicit declaration is recommended
2627

2728
exports org.apache.lucene.analysis;

0 commit comments

Comments
 (0)