diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index b19599e5..a979ae63 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -6,6 +6,7 @@ - [Build](#build) - [Building from the command line](#building-from-the-command-line) - [Debugging](#debugging) + - [Publish zips to maven](#to-publish-generated-plugin-zips-to-maven-repo) - [Using IntelliJ IDEA](#using-intellij-idea) - [Submitting Changes](#submitting-changes) @@ -53,6 +54,16 @@ opensearch-plugin install file:///path/to/target/releases/opensearch-job-schedul ``` to install the JobScheduler plugin to your OpenSearch. +## To Publish generated plugin zips to maven repo +The generated plugin zip `opensearch-job-scheduler-.zip` after the build, inside the folder `build/distributions` can be published to maven repo. This can be done by including the project `pluginZips` inside `settings.gradle` file. Once added the generated plugin zip will be published to maven repo with following maven coordinates +``` + org.opensearch.plugin + opensearch-job-scheduler + + zip +``` +To skip the publish, while this sub-project is still included, pass the flag as ` ext.publish = 'skip'` to file `build.gradle` inside `maven/plugin-zips/` folder. + ## Develop a plugin that extends JobScheduler JobScheduler plugin provides a SPI for other plugins to implement. Essentially, you need to 1. Define your *JobParameter* type by implementing `ScheduledJobParameter` interface diff --git a/build.gradle b/build.gradle index 6c807111..cac94f44 100644 --- a/build.gradle +++ b/build.gradle @@ -184,4 +184,4 @@ afterEvaluate { doLast { delete file("$buildDir/distributions/$archiveName") } } } -} +} \ No newline at end of file diff --git a/maven/plugin-zips/build.gradle b/maven/plugin-zips/build.gradle new file mode 100644 index 00000000..12386b1e --- /dev/null +++ b/maven/plugin-zips/build.gradle @@ -0,0 +1,102 @@ +plugins { + id 'maven-publish' +} + +ext { + isSnapshot = "true" == System.getProperty("build.snapshot", "true") + opensearch_version = System.getProperty("opensearch.version", "2.0.0-alpha1-SNAPSHOT") + buildVersionQualifier = System.getProperty("build.version_qualifier", "alpha1") + // 2.0.0-alpha1-SNAPSHOT -> 2.0.0.0-alpha1-SNAPSHOT + version_tokens = opensearch_version.tokenize('-') + opensearch_build = version_tokens[0] + '.0' + if (buildVersionQualifier) { + opensearch_build += "-${buildVersionQualifier}" + opensearch_build_nosnapshot = opensearch_build + } + if (isSnapshot) { + opensearch_build += "-SNAPSHOT" + } +} + + +allprojects { + // Default to the apache license + project.ext.licenseName = 'The Apache Software License, Version 2.0' + project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + publishing { + repositories { + maven { + name = 'staging' + url = "${rootProject.buildDir}/local-staging-repo" + } + } + publications { + // add license information to generated poms + all { + pom.withXml { XmlProvider xml -> + Node node = xml.asNode() + node.appendNode('inceptionYear', '2021') + + Node license = node.appendNode('licenses').appendNode('license') + license.appendNode('name', project.licenseName) + license.appendNode('url', project.licenseUrl) + + Node developer = node.appendNode('developers').appendNode('developer') + developer.appendNode('name', 'OpenSearch') + developer.appendNode('url', 'https://github.com/opensearch-project/job-scheduler') + } + } + } + } +} + +def group = "org.opensearch.plugin" +def pluginversion = opensearch_build +def component = "opensearch-job-scheduler" +def description = "OpenSearch Job Scheduler Zip" +def zipFile = "${component}-${pluginversion}.zip" +def zipArtifact = "${rootProject.buildDir}/distributions/${zipFile}" + + +publishing { + publications { + maven(MavenPublication) { + //Add ext.publish = 'skip' to skip publishing skip to maven staging repo + groupId = "${group}" + artifactId = "${component}" + version = "${pluginversion}" + // Add extension, to get zip as in pom file + artifact(zipArtifact) { + extension 'zip' + } + pom { + name = "${component}" + description = "${description}" + } + } + } +} + +task printZipsPublishProperty { + doLast { + tasks.withType(PublishToMavenRepository).all { publishTask -> + if (publication.hasProperty('publish')) { + println(publication.publish) + }else { + println("null") + } + } + } +} + +afterEvaluate { + tasks.withType(PublishToMavenRepository).all { publishTask -> + publishTask.onlyIf { task -> + if (publication.hasProperty('publish') && publication.publish == 'skip') { + return false + } + return true + } + } +} + diff --git a/scripts/build.sh b/scripts/build.sh index 40a856a2..f7ffb095 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -67,12 +67,12 @@ fi [[ "$SNAPSHOT" == "true" ]] && VERSION=$VERSION-SNAPSHOT [ -z "$OUTPUT" ] && OUTPUT=artifacts -./gradlew publishToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER -./gradlew publishAllPublicationsToStagingRepository -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 - ./gradlew assemble --no-daemon --refresh-dependencies -DskipTests=true -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER [ -z "$OUTPUT" ] && OUTPUT=artifacts mkdir -p $OUTPUT/plugins cp ./build/distributions/*.zip $OUTPUT/plugins + +./gradlew publishToMavenLocal -Dopensearch.version=$VERSION -Dbuild.snapshot=$SNAPSHOT -Dbuild.version_qualifier=$QUALIFIER +./gradlew publishAllPublicationsToStagingRepository -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 diff --git a/settings.gradle b/settings.gradle index e70743c2..f4ba8b93 100644 --- a/settings.gradle +++ b/settings.gradle @@ -9,4 +9,8 @@ include "spi" project(":spi").name = rootProject.name + "-spi" include "sample-extension-plugin" -project(":sample-extension-plugin").name = rootProject.name + "-sample-extension" \ No newline at end of file +project(":sample-extension-plugin").name = rootProject.name + "-sample-extension" + +//Adding pluginZips project under maven folder, this is to publish generated plugin zips to maven repo +include 'pluginZips' +project(':pluginZips').projectDir = file('maven/plugin-zips')