diff --git a/.java-version b/.java-version index 2dbc24b3..5f39e914 100644 --- a/.java-version +++ b/.java-version @@ -1 +1 @@ -11.0 +21.0 diff --git a/build.gradle b/build.gradle index 78f559e1..3e6fce5d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,21 @@ import java.nio.file.Files buildscript { + ext { + opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT") + is_snapshot = "true" == System.getProperty("build.snapshot", "true") + build_version_qualifier = System.getProperty("build.version_qualifier", "") + + version_tokens = opensearch_version.tokenize('-') + opensearch_build = version_tokens[0] + '.0' + if (build_version_qualifier) { + opensearch_build += "-${build_version_qualifier}" + } + if (is_snapshot) { + opensearch_build += "-SNAPSHOT" + } + } + repositories { mavenLocal() maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } @@ -9,25 +24,23 @@ buildscript { } dependencies { - classpath "org.opensearch.gradle:build-tools:${opensearchVersion}" + classpath "org.opensearch.gradle:build-tools:${opensearch_version}" } } plugins { - id "co.riiid.gradle" version "0.4.2" + id 'java' + id 'idea' + id 'maven-publish' } +group = 'org.opensearch' +version = opensearch_build -group = 'com.o19s' -version = "${ltrVersion}-os${opensearchVersion}" - -apply plugin: 'java' -apply plugin: 'idea' apply plugin: 'opensearch.opensearchplugin' apply plugin: 'opensearch.java-rest-test' apply plugin: 'opensearch.rest-resources' -//apply plugin: 'opensearch.yaml-rest-test' - +apply plugin: 'opensearch.pluginzip' idea { module { @@ -46,7 +59,7 @@ noticeFile = rootProject.file('NOTICE.txt') //uploadArchives.enabled = false opensearchplugin { - name 'ltr' + name 'opensearch-ltr' description 'Learning to Rank Query w/ RankLib Models' classname 'com.o19s.es.ltr.LtrQueryParserPlugin' // license of the plugin, may be different than the above license @@ -55,6 +68,44 @@ opensearchplugin { noticeFile = rootProject.file('NOTICE.txt') } +publishing { + publications { + pluginZip(MavenPublication) { publication -> + pom { + name = "opensearch-ltr" + description = "Learning to Rank Query w/ RankLib Models" + licenses { + license { + name = "The Apache License, Version 2.0" + url = "http://www.apache.org/licenses/LICENSE-2.0.txt" + } + } + developers { + developer { + name = "OpenSearch" + url = "https://github.com/opensearch-project/opensearch-learning-to-rank-base" + } + } + } + } + } + + repositories { + maven { + name = 'staging' + url = layout.buildDirectory.dir('local-staging-repo') + } + maven { + name = "Snapshots" + url = "https://aws.oss.sonatype.org/content/repositories/snapshots" + credentials { + username "$System.env.SONATYPE_USERNAME" + password "$System.env.SONATYPE_PASSWORD" + } + } + } +} + // In this section you declare the dependencies for your production and test code // OpenSearch dependency is included due to the build-tools, test-framework as well repositories { @@ -79,9 +130,6 @@ dependencies { runtimeOnly 'org.apache.logging.log4j:log4j-core:2.21.0' } - - - // see https://github.com/opensearch-project/OpenSearch/blob/0ba0e7cc26060f964fcbf6ee45bae53b3a9941d0/buildSrc/src/main/java/org/opensearch/gradle/precommit/DependencyLicensesTask.java dependencyLicenses { mapping from: /lucene-.*/, to: 'lucene' @@ -99,8 +147,10 @@ sourceSets { } java { - withJavadocJar() + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 withSourcesJar() + withJavadocJar() } @@ -123,30 +173,6 @@ validateNebulaPom.enabled = false // https://github.com/elastic/opensearch/issues/65247 loggerUsageCheck.enabled = false -githubRelease.doFirst { - if (!System.getProperty('GITHUB_TOKEN', '')) { - throw new Exception('Missing property GITHUB_TOKEN') - } - - // check if zip file is there - assert file("build/distributions/ltr-${version}.zip").exists() - - // rename zip file - def currentVersion = version.replace('-SNAPSHOT', '') - def filename = "build/distributions/ltr-${currentVersion}.zip" - Files.copy(file("build/distributions/ltr-${version}.zip").toPath(), file(filename).toPath()) - - // configuration - github { - owner = 'gsingers' - repo = 'opensearch-learning-to-rank-base' - token = System.getProperty('GITHUB_TOKEN') - tagName = currentVersion - assets = [ filename ] - targetCommitish = 'main' - } -} - tasks.withType(Test).configureEach { task -> if (JavaVersion.current().compareTo(JavaVersion.VERSION_17) > 0 && JavaVersion.current().compareTo(JavaVersion.VERSION_21) < 0) { def policyFile = file("${projectDir}/src/main/plugin-metadata/plugin-security.policy").absolutePath diff --git a/gradle.properties b/gradle.properties index bdb9c888..3a57b106 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,3 @@ -ltrVersion = 3.0.0-SNAPSHOT -opensearchVersion = 3.0.0-SNAPSHOT luceneVersion = 9.7.0 ow2Version = 9.6 antlrVersion=4.11.1 diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 00000000..1e27d557 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# Copyright OpenSearch Contributors +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. + +set -ex + +function usage() { + echo "Usage: $0 [args]" + echo "" + echo "Arguments:" + echo -e "-v VERSION\t[Required] OpenSearch version." + echo -e "-q QUALIFIER\t[Optional] Version qualifier." + echo -e "-s SNAPSHOT\t[Optional] Build a snapshot, default is 'false'." + echo -e "-p PLATFORM\t[Optional] Platform, ignored." + echo -e "-a ARCHITECTURE\t[Optional] Build architecture, ignored." + echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'." + echo -e "-h help" +} + +while getopts ":h:v:q:s:o:p:a:" arg; do + case $arg in + h) + usage + exit 1 + ;; + v) + VERSION=$OPTARG + ;; + q) + QUALIFIER=$OPTARG + ;; + s) + SNAPSHOT=$OPTARG + ;; + o) + OUTPUT=$OPTARG + ;; + p) + PLATFORM=$OPTARG + ;; + a) + ARCHITECTURE=$OPTARG + ;; + :) + echo "Error: -${OPTARG} requires an argument" + usage + exit 1 + ;; + ?) + echo "Invalid option: -${arg}" + exit 1 + ;; + esac +done + +if [ -z "$VERSION" ]; then + echo "Error: You must specify the OpenSearch version" + usage + exit 1 +fi + +[[ ! -z "$QUALIFIER" ]] && VERSION=$VERSION-$QUALIFIER +[[ "$SNAPSHOT" == "true" ]] && VERSION=$VERSION-SNAPSHOT +[ -z "$OUTPUT" ] && OUTPUT=artifacts + +mkdir -p $OUTPUT + +./gradlew assemble --no-daemon --refresh-dependencies -DskipTests=true -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER + +zipPath=$(find . -path \*build/distributions/*.zip) +distributions="$(dirname "${zipPath}")" + +echo "COPY ${distributions}/*.zip" +mkdir -p $OUTPUT/plugins +cp ${distributions}/*.zip ./$OUTPUT/plugins + +# Publish plugin zips to maven +./gradlew publishPluginZipPublicationToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER +./gradlew publishPluginZipPublicationToZipStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER +./gradlew publishPluginZipPublicationToStagingRepository -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER +mkdir -p $OUTPUT/maven/org/opensearch +cp -r ./build/local-staging-repo/org/opensearch/. $OUTPUT/maven/org/opensearch \ No newline at end of file