Skip to content

Commit db4e85f

Browse files
authored
Update gradle run to be able to fetch and run external plugins (opensearch-project#19428)
* Update installedPlugins in run.gradle to fetch plugins from maven. This change allows us to install plugins not shipped with core with gradlew run. It supports simply specifying the plugin name or adding a specific version. Example: ./gradlew run -PinstalledPlugins['opensearch-job-scheduler'] or ./gradlew run -PinstalledPlugins['opensearch-job-scheduler:3.2.x.x] Signed-off-by: Marc Handalian <[email protected]> * Add support for third party plugins Signed-off-by: Marc Handalian <[email protected]> --------- Signed-off-by: Marc Handalian <[email protected]>
1 parent 5962128 commit db4e85f

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

DEVELOPER_GUIDE.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ Fork [opensearch-project/OpenSearch](https://github.com/opensearch-project/OpenS
7676

7777
#### JDK
7878

79-
OpenSearch recommends building with the [Temurin/Adoptium](https://adoptium.net/temurin/releases/) distribution. JDK 11 is the minimum supported, and JDK-24 is the newest supported. You must have a supported JDK installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-21`.
79+
OpenSearch recommends building with the [Temurin/Adoptium](https://adoptium.net/temurin/releases/) distribution. JDK 11 is the minimum supported, and JDK-24 is the newest supported. You must have a supported JDK installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-21`.
8080

81-
Download Java 11 from [here](https://adoptium.net/releases.html?variant=openjdk11).
81+
Download Java 11 from [here](https://adoptium.net/releases.html?variant=openjdk11).
8282

8383

8484
In addition, certain backward compatibility tests check out and compile the previous major version of OpenSearch, and therefore require installing [JDK 11](https://adoptium.net/temurin/releases/?version=11) and [JDK 17](https://adoptium.net/temurin/releases/?version=17) and setting the `JAVA11_HOME` and `JAVA17_HOME` environment variables. More to that, since 8.10 release, Gradle has deprecated the usage of the any JDKs below JDK-16. For smooth development experience, the recommendation is to install at least [JDK 17](https://adoptium.net/temurin/releases/?version=17) or [JDK 21](https://adoptium.net/temurin/releases/?version=21). If you still want to build with JDK-11 only, please add `-Dorg.gradle.warning.mode=none` when invoking any Gradle build task from command line, for example:
@@ -178,6 +178,23 @@ Run OpenSearch using `gradlew run`.
178178
./gradlew run -PinstalledPlugins="['plugin1', 'plugin2']"
179179
```
180180

181+
External plugins may also be fetched and installed from maven snapshots:
182+
183+
```bash
184+
./gradlew run -PinstalledPlugins="['opensearch-job-scheduler', 'opensearch-sql-plugin']"
185+
```
186+
187+
You can specify a plugin version to pull to test a specific version in the org.opensearch.plugin groupId:
188+
```bash
189+
./gradlew run -PinstalledPlugins="['opensearch-job-scheduler:3.3.x.x']"
190+
```
191+
192+
or install with fully qualified maven coordinates:
193+
```bash
194+
./gradlew run -PinstalledPlugins="['com.example:my-cool-plugin:3.3.x.x']"
195+
```
196+
197+
181198
That will build OpenSearch and start it, writing its log above Gradle's status message. We log a lot of stuff on startup, specifically these lines tell you that OpenSearch is ready.
182199

183200
```

gradle/run.gradle

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* under the License.
2929
*/
3030
import org.opensearch.gradle.testclusters.RunTask
31+
import org.opensearch.gradle.VersionProperties
3132

3233
apply plugin: 'opensearch.testclusters'
3334

@@ -41,8 +42,45 @@ testClusters {
4142
if (numNodes > 1) numberOfNodes = numNodes
4243
if (findProperty("installedPlugins")) {
4344
installedPlugins = Eval.me(installedPlugins)
45+
46+
def resolveMavenPlugin = { coords ->
47+
// Add default groupId if not fully qualified (less than 2 colons)
48+
String[] parts = coords.split(':')
49+
if (parts.length == 2 && parts[0].contains('.')) {
50+
throw new IllegalArgumentException("version is required if groupdId is specified '${coords}' Use format: groupId:artifactId:version")
51+
}
52+
String fullCoords = parts.length < 3 ? 'org.opensearch.plugin:' + coords : coords
53+
def config = project.configurations.detachedConfiguration(
54+
project.dependencies.create(fullCoords)
55+
)
56+
config.resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
57+
plugin(project.layout.file(project.provider { config.singleFile }))
58+
}
59+
4460
for (String p : installedPlugins) {
45-
plugin('plugins:'.concat(p))
61+
// check if its a local plugin first
62+
if (project.findProject(':plugins:' + p) != null) {
63+
plugin('plugins:' + p)
64+
} else {
65+
// attempt to fetch it from maven
66+
project.repositories.mavenLocal()
67+
project.repositories {
68+
maven {
69+
name = 'OpenSearch Snapshots'
70+
url = 'https://central.sonatype.com/repository/maven-snapshots/'
71+
}
72+
}
73+
if (p.contains(':')) {
74+
// Maven coordinates with version specified
75+
String coords = p.contains('@') ? p : (p + '@zip')
76+
resolveMavenPlugin(coords)
77+
} else {
78+
// Not found locally, try Maven with current OS version + 0
79+
String version = VersionProperties.getOpenSearch().replace('-SNAPSHOT', '.0-SNAPSHOT')
80+
String coords = p + ':' + version + '@zip'
81+
resolveMavenPlugin(coords)
82+
}
83+
}
4684
if (p.equals("arrow-flight-rpc")) {
4785
// Add system properties for Netty configuration
4886
systemProperty 'io.netty.allocator.numDirectArenas', '1'

0 commit comments

Comments
 (0)