Skip to content

Commit

Permalink
[Backport 2.x] ZIP publication groupId value is configurable (opensea…
Browse files Browse the repository at this point in the history
…rch-project#4156)

* This is backport of opensearch-project#4156 to 2.x
* It is cherry-picked from 7fe5830
* Resolving conflicts in CHANGELOG.md

Signed-off-by: Lukáš Vlček <lukas.vlcek@aiven.io>
  • Loading branch information
lukas-vlcek committed Oct 11, 2022
1 parent b55719c commit 769ceb8
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 156 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Change the version to remove deprecated code of adding node name into log pattern of log4j property file ([#4569](https://github.com/opensearch-project/OpenSearch/pull/4569))
- Update to Apache Lucene 9.4.0 ([#4661](https://github.com/opensearch-project/OpenSearch/pull/4661))
- Load the deprecated master role in a dedicated method instead of in setAdditionalRoles() ([#4582](https://github.com/opensearch-project/OpenSearch/pull/4582))
- Plugin ZIP publication groupId value is configurable ([#4156](https://github.com/opensearch-project/OpenSearch/pull/4156))

### Deprecated

Expand Down
44 changes: 23 additions & 21 deletions buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.publish.Publication;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
Expand All @@ -18,6 +19,9 @@
import org.gradle.api.Task;

public class Publish implements Plugin<Project> {

private static final Logger LOGGER = Logging.getLogger(Publish.class);

public final static String EXTENSION_NAME = "zipmavensettings";
public final static String PUBLICATION_NAME = "pluginZip";
public final static String STAGING_REPO = "zipStaging";
Expand All @@ -37,27 +41,25 @@ public static void configMaven(Project project) {
});
});
publishing.publications(publications -> {
final Publication publication = publications.findByName(PUBLICATION_NAME);
if (publication == null) {
publications.create(PUBLICATION_NAME, MavenPublication.class, mavenZip -> {
String zipGroup = "org.opensearch.plugin";
String zipArtifact = project.getName();
String zipVersion = getProperty("version", project);
mavenZip.artifact(project.getTasks().named("bundlePlugin"));
mavenZip.setGroupId(zipGroup);
mavenZip.setArtifactId(zipArtifact);
mavenZip.setVersion(zipVersion);
});
} else {
final MavenPublication mavenZip = (MavenPublication) publication;
String zipGroup = "org.opensearch.plugin";
String zipArtifact = project.getName();
String zipVersion = getProperty("version", project);
mavenZip.artifact(project.getTasks().named("bundlePlugin"));
mavenZip.setGroupId(zipGroup);
mavenZip.setArtifactId(zipArtifact);
mavenZip.setVersion(zipVersion);
MavenPublication mavenZip = (MavenPublication) publications.findByName(PUBLICATION_NAME);

if (mavenZip == null) {
mavenZip = publications.create(PUBLICATION_NAME, MavenPublication.class);
}

String groupId = mavenZip.getGroupId();
if (groupId == null) {
// The groupId is not customized thus we get the value from "project.group".
// See https://docs.gradle.org/current/userguide/publishing_maven.html#sec:identity_values_in_the_generated_pom
groupId = getProperty("group", project);
}

String artifactId = project.getName();
String pluginVersion = getProperty("version", project);
mavenZip.artifact(project.getTasks().named("bundlePlugin"));
mavenZip.setGroupId(groupId);
mavenZip.setArtifactId(artifactId);
mavenZip.setVersion(pluginVersion);
});
});
}
Expand Down
Loading

0 comments on commit 769ceb8

Please sign in to comment.