From 4e00a3906c2254eb6e32af034a2ba9105bd9c590 Mon Sep 17 00:00:00 2001 From: John Mazanec Date: Tue, 4 Oct 2022 10:15:29 -0700 Subject: [PATCH] Add dependency on k-NN in build.gradle Adds dependency on k-NN in the build.gradle file. The dependency resolution will work by first pulling the opensearch-knn zip from Maven and then unzipping it and adding it to the classpath. Added a unit test to confirm that it works. Signed-off-by: John Mazanec --- build.gradle | 18 ++++++++++++++++++ .../neuralsearch/plugin/NeuralSearchTests.java | 10 ++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 614131f33..6c29f7cc2 100644 --- a/build.gradle +++ b/build.gradle @@ -124,12 +124,30 @@ repositories { maven { url "https://plugins.gradle.org/m2/" } } +configurations { + zipArchive +} + +def knnJarDirectory = "$buildDir/dependencies/opensearch-knn" + dependencies { api "org.opensearch:opensearch:${opensearch_version}" + zipArchive group: 'org.opensearch.plugin', name:'opensearch-knn', version: "${opensearch_build}" + api fileTree(dir: knnJarDirectory, include: '*.jar') api group: 'org.opensearch', name:'opensearch-ml-client', version: "${opensearch_build}" } +// From maven, we can get the k-NN plugin as a zip. In order to add the jar to the classpath, we need to unzip the +// k-NN zip and then copy it into a directory that we specify as a dependency. +task unzip(type: Copy) { + configurations.zipArchive.asFileTree.each { + from(zipTree(it)) + } + into knnJarDirectory +} + compileJava { + dependsOn unzip options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor']) } compileTestJava { diff --git a/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java b/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java index f40942d49..a3eddd3c8 100644 --- a/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java +++ b/src/test/java/org/opensearch/neuralsearch/plugin/NeuralSearchTests.java @@ -5,15 +5,13 @@ package org.opensearch.neuralsearch.plugin; -import org.junit.Assert; +import org.opensearch.knn.common.KNNConstants; +import org.opensearch.knn.index.util.KNNEngine; import org.opensearch.test.OpenSearchTestCase; public class NeuralSearchTests extends OpenSearchTestCase { - /** - * Dummy test case for passing the build. - */ - public void testDemo() { - Assert.assertTrue(true); + public void testValidateKNNDependency() { + assertEquals(KNNConstants.LUCENE_NAME, KNNEngine.LUCENE.getName()); } }