Skip to content

Commit

Permalink
Switch publication to shadow JAR and add build script
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis committed Jan 8, 2025
1 parent 116c164 commit d513846
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
export SONATYPE_PASSWORD=$(aws secretsmanager get-secret-value --secret-id maven-snapshots-password --query SecretString --output text)
echo "::add-mask::$SONATYPE_USERNAME"
echo "::add-mask::$SONATYPE_PASSWORD"
./gradlew publishMavenJavaPublicationToSnapshotsRepository
./gradlew publishShadowPublicationToSnapshotsRepository
11 changes: 11 additions & 0 deletions aos-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ dependencies {
implementation("software.amazon.awssdk:url-connection-client")
implementation("software.amazon.awssdk:utils")
}

shadowJar {
dependsOn(':opensearch-remote-metadata-sdk-core:shadowJar',
':opensearch-remote-metadata-sdk-remote-client:shadowJar')
from(project(':opensearch-remote-metadata-sdk-core').shadowJar.outputs.files) {
into 'META-INF/lib'
}
from(project(':opensearch-remote-metadata-sdk-remote-client').shadowJar.outputs.files) {
into 'META-INF/lib'
}
}
24 changes: 20 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ allprojects {

subprojects {
apply plugin: 'java-library'
apply plugin: 'com.github.johnrengelman.shadow'

dependencies {
// Common dependencies for all subprojects
Expand All @@ -98,6 +99,8 @@ subprojects {

configurations {
testImplementation.extendsFrom testFixtures
implementation.extendsFrom shadowImplementation
runtimeOnly.extendsFrom shadowRuntimeOnly
}

test {
Expand Down Expand Up @@ -136,6 +139,11 @@ subprojects {
withJavadocJar()
}

shadowJar {
archiveClassifier.set(null)
from sourceSets.main.output
}

checkstyle {
toolVersion = "10.21.1"
}
Expand All @@ -147,18 +155,26 @@ subprojects {

publishing {
publications {
mavenJava(MavenPublication) {
shadow(MavenPublication) {
from components.java

// These are for unpublished test classes
suppressPomMetadataWarningsFor('testFixturesApiElements')
suppressPomMetadataWarningsFor('testFixturesRuntimeElements')
project.shadow.component(it)

// Customize artifact ID for core project
if (project.name == 'opensearch-remote-metadata-sdk-core') {
artifactId = 'opensearch-remote-metadata-sdk'
}

artifacts.clear()

artifact shadowJar
artifact sourcesJar
artifact javadocJar

// These are for unpublished test classes
suppressPomMetadataWarningsFor('testFixturesApiElements')
suppressPomMetadataWarningsFor('testFixturesRuntimeElements')

pom {
name = project.name == 'opensearch-remote-metadata-sdk-core'
? "OpenSearch Remote Metadata SDK for Java"
Expand Down
15 changes: 15 additions & 0 deletions ddb-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ dependencies {
implementation(platform("software.amazon.awssdk:bom:${aws_sdk_version}"))
implementation "software.amazon.awssdk:dynamodb"
}

shadowJar {
dependsOn(':opensearch-remote-metadata-sdk-core:shadowJar',
':opensearch-remote-metadata-sdk-remote-client:shadowJar',
':opensearch-remote-metadata-sdk-aos-client:shadowJar')
from(project(':opensearch-remote-metadata-sdk-core').shadowJar.outputs.files) {
into 'META-INF/lib'
}
from(project(':opensearch-remote-metadata-sdk-remote-client').shadowJar.outputs.files) {
into 'META-INF/lib'
}
from(project(':opensearch-remote-metadata-sdk-aos-client').shadowJar.outputs.files) {
into 'META-INF/lib'
}
}
7 changes: 7 additions & 0 deletions remote-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ dependencies {

implementation "org.opensearch.client:opensearch-java:${opensearch_java_version}"
}

shadowJar {
dependsOn(':opensearch-remote-metadata-sdk-core:shadowJar')
from(project(':opensearch-remote-metadata-sdk-core').shadowJar.outputs.files) {
into 'META-INF/lib'
}
}
71 changes: 71 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash

# Copyright OpenSearch Contributors.
# SPDX-License-Identifier: Apache-2.0

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

./gradlew build -x test -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
./gradlew publishShadowPublicationToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER
./gradlew publishShadowPublicationToStagingRepository -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

0 comments on commit d513846

Please sign in to comment.