Skip to content

Commit

Permalink
Add dependency on k-NN in build.gradle (#10)
Browse files Browse the repository at this point in the history
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 <jmazane@amazon.com>
  • Loading branch information
jmazanec15 authored Oct 6, 2022
1 parent 2ad9bd3 commit 34f358d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 34f358d

Please sign in to comment.