plugins { id "java" } // Overridable per-build: ES classic plugins install only on the exact ES // version stamped in plugin-descriptor.properties, so the release workflow // builds one zip per supported ES version via -PesVersion=X.Y.Z. // (Captured before the ext assignment: afterwards findProperty("esVersion") // would always resolve to the ext value.) def esVersionOverride = findProperty("esVersion") ext.esVersion = esVersionOverride ?: "8.17.0" ext.luceneVersion = "9.12.0" group = "io.github.darkhanakh" // Must match [workspace.package].version in the root Cargo.toml (single // source of truth for the release version). version = "2.3.0" java { toolchain { languageVersion = JavaLanguageVersion.of(21) } } repositories { mavenCentral() } dependencies { compileOnly "org.elasticsearch:elasticsearch:${esVersion}" compileOnly "org.apache.lucene:lucene-analysis-common:${luceneVersion}" testImplementation "org.elasticsearch:elasticsearch:${esVersion}" testImplementation "org.apache.lucene:lucene-analysis-common:${luceneVersion}" testImplementation "junit:junit:4.13.2" } def nativeResourcesDir = file("src/main/resources/native") def lexiconFile = file("../../data/tsearch_data/kaz_stems.dict") // Optional verb-lemma sibling; kazsearch-core auto-loads it when it sits // next to the lexicon, enabling verb-root reductions. def lexiconVerbsFile = file("../../data/tsearch_data/kaz_stems.dict.verbs") tasks.withType(JavaCompile).configureEach { options.encoding = "UTF-8" } // Native libraries are shipped as platform directories in the plugin zip and // loaded by absolute path (NativeLibraryLoader); keep them out of the jar. processResources { exclude "native/**" } // Unit tests load the native library straight from the resources tree. tasks.withType(Test).configureEach { systemProperty "kazsearch.native.dir", nativeResourcesDir.absolutePath } // Preflight: never ship a plugin zip without a native library or the lexicon. tasks.register("checkBundleContents") { description = "Fails if no native library / lexicon is available for bundling" def nativeDir = nativeResourcesDir def lexicon = lexiconFile doLast { def libs = fileTree(nativeDir) { include "**/*.so" include "**/*.dylib" }.files if (libs.isEmpty()) { throw new GradleException( "No native library (.so/.dylib) found under ${nativeDir}.\n" + "Run 'just es-native' (or scripts/build_elastic_native.sh) first — " + "a plugin zip without the native library cannot load.") } if (!lexicon.isFile()) { throw new GradleException( "Lexicon not found: ${lexicon}.\n" + "Run 'python3 scripts/build_lexicon.py' first so data/kaz_stems.dict " + "can be bundled into the plugin zip.") } } } tasks.register("bundlePlugin", Zip) { archiveBaseName = "analysis-kazsearch" archiveVersion = provider { project.version } // Suffix the zip with the target ES version when one was requested // explicitly, e.g. analysis-kazsearch-2.3.0-es8.18.8.zip. The default // build keeps the plain name for local dev and the docker image. if (esVersionOverride) { archiveClassifier = "es" + esVersion } from(jar) from("src/main/plugin-metadata") { include "plugin-descriptor.properties" include "plugin-security.policy" include "entitlement-policy.yaml" // Stamp the build version and target ES version into // plugin-descriptor.properties (anchored so java.version is // untouched). filter { line -> line.replaceAll("^version=.*", "version=" + project.version) .replaceAll("^elasticsearch\\.version=.*", "elasticsearch.version=" + esVersion) } } from("src/main/resources/native") { include "**/*.so" include "**/*.dylib" includeEmptyDirs = false } from(lexiconFile) { into "data" } from(lexiconVerbsFile) { into "data" } } bundlePlugin.dependsOn(jar) bundlePlugin.dependsOn(checkBundleContents) // Also stamp the version into the jar's archive name jar { archiveVersion = provider { project.version } }