Skip to content

Commit 1459ea9

Browse files
committed
Upgrade to Elasticsearch 9.1.4. As part of this:
- Upgrade Java to JVM 21 - Upgrade Gradle to 8.11 - Fix all deprecations - Fix integrations tests on Elasticsearch and re-enable them
1 parent a756a23 commit 1459ea9

File tree

20 files changed

+256
-38
lines changed

20 files changed

+256
-38
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
es-version:
17+
- 'es:9.1.4'
1718
- 'es:8.15.2'
1819
- 'es:8.14.3'
1920
- 'es:8.13.4'
@@ -46,7 +47,7 @@ jobs:
4647
- 'os:2.7.0'
4748
- 'os:2.6.0'
4849
env:
49-
mainJob: ${{ matrix.es-version == 'es:8.15.2' }}
50+
mainJob: ${{ matrix.es-version == 'es:9.1.4' }}
5051
sudachiVersion: 20241021
5152
sudachiKind: core
5253
continue-on-error: true

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ Check [changelog](./CHANGELOG.md) for more.
1818

1919
1. Build analysis-sudachi.
2020
```
21-
$ ./gradlew -PengineVersion=es:8.15.2 build
21+
$ ./gradlew -PengineVersion=es:9.1.4 build
2222
```
2323

2424
Use `-PengineVersion=os:2.18.0` for OpenSearch.
2525

2626
## Supported ElasticSearch versions
2727

28-
1. 8.0.* until 8.15.* supported, integration tests in CI
29-
2. 7.17.* (latest patch version) - supported, integration tests in CI
30-
3. 7.11.* until 7.16.* - best effort support, not tested in CI
31-
4. 7.10.* integration tests for the latest patch version
32-
5. 7.9.* and below - not tested in CI at all, may be broken
33-
6. 7.3.* and below - broken, not supported
28+
1. 9.0.* until 9.1.* supported, integration tests in CI
29+
2. 8.0.* until 8.15.* supported, integration tests in CI
30+
3. 7.17.* (latest patch version) - supported, integration tests in CI
31+
4. 7.11.* until 7.16.* - best effort support, not tested in CI
32+
5. 7.10.* integration tests for the latest patch version
33+
6. 7.9.* and below - not tested in CI at all, may be broken
34+
7. 7.3.* and below - broken, not supported
3435

3536
## Supported OpenSearch versions
3637

@@ -43,11 +44,11 @@ Use `-PengineVersion=os:2.18.0` for OpenSearch.
4344

4445
a. Using the release package
4546
```
46-
$ bin/elasticsearch-plugin install https://github.com/WorksApplications/elasticsearch-sudachi/releases/download/v3.1.1/analysis-sudachi-8.13.4-3.1.1.zip
47+
$ bin/elasticsearch-plugin install https://github.com/WorksApplications/elasticsearch-sudachi/releases/download/v3.1.1/analysis-sudachi-9.1.4-3.1.1.zip
4748
```
4849
b. Using self-build package
4950
```
50-
$ bin/elasticsearch-plugin install file:///path/to/analysis-sudachi-8.13.4-3.1.1.zip
51+
$ bin/elasticsearch-plugin install file:///path/to/analysis-sudachi-9.1.4-3.1.1.zip
5152
```
5253
(Specify the absolute path in URI format)
5354
3. Download sudachi dictionary archive from https://github.com/WorksApplications/SudachiDict

build.gradle

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22

33
plugins {
44
id 'java-library'
5-
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
6-
id "org.jetbrains.kotlin.plugin.serialization" version "1.8.0"
7-
id 'com.diffplug.spotless' version '6.16.0'
5+
id 'org.jetbrains.kotlin.jvm' version '2.0.0'
6+
id "org.jetbrains.kotlin.plugin.serialization" version '2.0.0'
7+
id 'com.diffplug.spotless' version '6.25.0'
88
id 'org.sonarqube' version '4.0.0.2929'
99
id("org.jetbrains.kotlinx.kover") version "0.7.0"
1010
id 'com.worksap.nlp.sudachi.esc'
@@ -13,15 +13,20 @@ plugins {
1313
}
1414

1515
group = 'com.worksap.nlp'
16-
archivesBaseName = 'analysis-sudachi'
16+
base.archivesName.set('analysis-sudachi')
1717
version = properties["pluginVersion"]
1818

19+
java {
20+
sourceCompatibility = JavaVersion.VERSION_21
21+
targetCompatibility = JavaVersion.VERSION_21
22+
}
23+
1924
compileKotlin {
20-
compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
25+
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
2126
}
2227

2328
compileTestKotlin {
24-
compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
29+
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
2530
}
2631

2732
configurations {
@@ -84,7 +89,7 @@ def packageSpiJars = tasks.register('packageSpiJars', Copy) {
8489
def distZip = tasks.register('distZip', Zip) {
8590
var esKind = sudachiEs.kind.get()
8691
dependsOn embedVersion, packageJars, packageSpiJars
87-
archiveBaseName.set("${esKind.engine.kind}-${esKind.version}-$archivesBaseName")
92+
archiveBaseName.set("${esKind.engine.kind}-${esKind.version}-${base.archivesName.get()}")
8893
from("build/package/${version}/${esKind.engine.kind}-${esKind.version}", 'LICENSE', 'README.md')
8994
}
9095

buildSrc/src/main/groovy/com/worksap/nlp/tools/EsConventions.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class EsConventions implements Plugin<Project> {
88
@Override
99
void apply(Project target) {
1010
target.tasks.withType(JavaCompile).configureEach {
11-
options.release.set(11)
11+
options.release.set(21)
1212
options.encoding = 'UTF-8'
1313
}
1414

buildSrc/src/main/groovy/com/worksap/nlp/tools/EsTestEnvPlugin.groovy

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class StringProvider implements Provider<String>, Serializable {
103103
throw new IllegalStateException("not implemented")
104104
}
105105

106+
@Override
107+
Provider<String> filter(org.gradle.api.specs.Spec<? super String> spec) {
108+
throw new IllegalStateException("not implemented")
109+
}
106110

107111
@Override
108112
String toString() {
@@ -153,9 +157,10 @@ class EsTestEnvPlugin implements Plugin<Project> {
153157
target.gradle.taskGraph.whenReady {
154158
boolean shouldRun = false
155159
if (target.plugins.findPlugin(EsSudachiPlugin.class) != null) {
156-
shouldRun = shouldTestsRun(target.extensions.getByType(EsExtension).kind.get())
160+
def kind = target.extensions.getByType(EsExtension).kind.get()
161+
shouldRun = shouldTestsRun(kind)
157162
}
158-
target.tasks.findAll().forEach { Task task ->
163+
target.tasks.withType(Test).forEach { Test task ->
159164
task.onlyIf { shouldRun }
160165
}
161166
}

buildSrc/src/main/groovy/com/worksap/nlp/tools/engines.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum EsSupport implements EngineSupport {
1313
Es84("es-8.04"),
1414
Es810("es-8.10"),
1515
Es812("es-8.12"),
16+
Es90("es-9.00"),
1617

1718
String tag
1819
List<String> keys
@@ -41,6 +42,8 @@ enum EsSupport implements EngineSupport {
4142
return Es810
4243
} else if (vers.ge(8, 12) && vers.lt(9, 0)) {
4344
return Es812
45+
} else if (vers.ge(9, 0)) {
46+
return Es90
4447
} else {
4548
throw new IllegalArgumentException("unsupported ElasticSearch version: " + vers.raw)
4649
}

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# elasticsearch versions: 8.15.2, 8.14.3, 8.13.4, 8.12.2, 8.11.4, 8.10.4, 8.9.2,
1+
# elasticsearch versions: 9.1.4, 8.15.2, 8.14.3, 8.13.4, 8.12.2, 8.11.4, 8.10.4, 8.9.2,
22
# 8.8.1, 8.6.2, 8.5.3, 8.4.3, 8.2.3, 7.17.24, 7.14.2, 7.10.2
3-
# opensearch version: 2.18.0, 2.17.1, 2.16.0, 2.15.0, 2.14.0, 2.13.0, 2.12.0, 2.11.1,
3+
# opensearch version: 2.18.0, 2.17.1, 2.16.0, 2.15.0, 2.14.0, 2.13.0, 2.12.0, 2.11.1,
44
# 2.10.0, 2.9.0, 2.8.0, 2.7.0, 2.6.0
5-
engineVersion=es:8.15.2
5+
engineVersion=es:9.1.4
66
org.gradle.jvmargs=-XX:MaxMetaspaceSize=350m \
77
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
88
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

integration/build.gradle

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,33 @@ plugins {
1313

1414
version = properties["pluginVersion"]
1515

16+
java {
17+
sourceCompatibility = JavaVersion.VERSION_21
18+
targetCompatibility = JavaVersion.VERSION_21
19+
}
20+
1621
compileKotlin {
17-
compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
22+
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
1823
}
1924

2025
compileTestKotlin {
21-
compilerOptions.jvmTarget.set(JvmTarget.JVM_11)
26+
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
2227
}
2328

2429
configurations { buildSudachiDict }
2530

2631
dependencies {
2732
buildSudachiDict (project(':spi'))
28-
compileOnly(project(':'))
29-
compileOnly(project(':spi'))
30-
testCompileOnly(project(':testlib'))
31-
testCompileOnly(project(':subplugin'))
33+
testImplementation(project(':'))
34+
testImplementation(project(':spi'))
35+
testImplementation(project(':testlib'))
36+
testImplementation(project(':subplugin'))
37+
// Add ICU plugin JARs for ES 9.x dynamic loading
38+
testRuntimeOnly files({
39+
fileTree(dir: new File(project.buildDir, "cache/icu-plugin-extracted"), include: '**/*.jar')
40+
}) {
41+
builtBy 'extractIcuPlugin'
42+
}
3243
testImplementation('junit:junit:4.13.1') {
3344
transitive = false
3445
}
@@ -65,6 +76,12 @@ def downloadIcuPlugin = tasks.register('downloadIcuPlugin', Download.class) {
6576
overwrite(false)
6677
}
6778

79+
def extractIcuPlugin = tasks.register('extractIcuPlugin', Copy) {
80+
dependsOn downloadIcuPlugin
81+
from zipTree(downloadIcuPlugin.get().dest)
82+
into new File(project.buildDir, "cache/icu-plugin-extracted")
83+
}
84+
6885
esTestEnv {
6986
def esKind = sudachiEs.kind.get()
7087
def packageDir = rootDir.toPath().resolve("build/package/${version}/${esKind.engine.kind}-${esKind.version}")
@@ -77,7 +94,6 @@ esTestEnv {
7794
}
7895

7996
test {
80-
onlyIf { ! (sudachiEs.isEs() && sudachiEs.kind.get().parsedVersion().ge(8, 9)) }
8197
dependsOn(
8298
':packageJars',
8399
':packageSpiJars',
@@ -86,6 +102,7 @@ test {
86102
compileSystemDictionary,
87103
':testlib:jar',
88104
downloadIcuPlugin,
105+
extractIcuPlugin,
89106
':subplugin:distZip'
90107
)
91108
systemProperty("tests.security.manager", true)
@@ -94,7 +111,7 @@ test {
94111

95112
def distZip = tasks.register('distZip', Zip) {
96113
var esKind = sudachiEs.kind.get()
97-
archiveBaseName.set("${esKind.engine.kind}-${esKind.version}-$archivesBaseName")
114+
archiveBaseName.set("${esKind.engine.kind}-${esKind.version}-${project.name}")
98115
from(
99116
project(':subplugin').packageJars.outputs.files,
100117
project(':subplugin').embedVersion.outputs.files,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2022-2025 Works Applications Co., Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.worksap.nlp.elasticsearch.sudachi
18+
19+
import org.elasticsearch.indices.analysis.AnalysisModule
20+
import org.elasticsearch.plugins.AnalysisPlugin
21+
import org.elasticsearch.plugins.scanners.StablePluginsRegistry
22+
23+
// For ES 9.x tests, we manually instantiate plugins since PluginsService API changed
24+
class TestPluginsService(private val plugins: List<AnalysisPlugin>) {
25+
fun <T> filterPlugins(clazz: Class<T>): List<T> = plugins.filterIsInstance(clazz)
26+
}
27+
28+
typealias PluginsServiceAlias = TestPluginsService
29+
30+
private fun loadTestPlugins(): List<AnalysisPlugin> {
31+
return listOfNotNull(
32+
tryLoadPlugin("com.worksap.nlp.elasticsearch.sudachi.plugin.AnalysisSudachiPlugin", true),
33+
tryLoadPlugin("org.elasticsearch.plugin.analysis.icu.AnalysisICUPlugin", false))
34+
}
35+
36+
private fun tryLoadPlugin(className: String, requiresSettings: Boolean): AnalysisPlugin? {
37+
return try {
38+
val clazz = Class.forName(className)
39+
if (requiresSettings) {
40+
clazz.getConstructor(org.elasticsearch.common.settings.Settings::class.java).newInstance(null)
41+
as AnalysisPlugin
42+
} else {
43+
clazz.getDeclaredConstructor().newInstance() as AnalysisPlugin
44+
}
45+
} catch (e: Exception) {
46+
null // Plugin not available or failed to load
47+
}
48+
}
49+
50+
fun SudachiInSearchEngineEnv.makePluginService() = TestPluginsService(loadTestPlugins())
51+
52+
fun SudachiInSearchEngineEnv.makeAnalysisModule() =
53+
AnalysisModule(environment(), loadTestPlugins(), StablePluginsRegistry())

0 commit comments

Comments
 (0)