diff --git a/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java index 2a0521b17d5..a28015784c4 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/PublishPlugin.java @@ -135,11 +135,11 @@ public class PublishPlugin implements Plugin { publication.artifact(project.getTasks().getByName("sourcesJar")); publication.artifact(project.getTasks().getByName("javadocJar")); } - - generatePomTask.configure( - t -> t.dependsOn(String.format("generatePomFileFor%sPublication", Util.capitalize(publication.getName()))) - ); } + + generatePomTask.configure( + t -> t.dependsOn(String.format("generatePomFileFor%sPublication", Util.capitalize(publication.getName()))) + ); }); } diff --git a/buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java b/buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java index e8b4ecec7a5..0a3b198b4d3 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/pluginzip/Publish.java @@ -14,6 +14,7 @@ import org.gradle.api.publish.PublishingExtension; import org.gradle.api.publish.maven.MavenPublication; import org.gradle.api.publish.maven.plugins.MavenPublishPlugin; import java.nio.file.Path; +import org.gradle.api.Task; public class Publish implements Plugin { private Project project; @@ -63,12 +64,19 @@ public class Publish implements Plugin { @Override public void apply(Project project) { this.project = project; - project.afterEvaluate(evaluatedProject -> { configMaven(project); }); - project.getGradle().getTaskGraph().whenReady(graph -> { - if (graph.hasTask(LOCALMAVEN)) { - project.getTasks().getByName(PLUGIN_ZIP_PUBLISH_POM_TASK).setEnabled(false); + project.afterEvaluate(evaluatedProject -> { + configMaven(project); + Task validatePluginZipPom = project.getTasks().findByName("validatePluginZipPom"); + if (validatePluginZipPom != null) { + project.getTasks().getByName("validatePluginZipPom").dependsOn("generatePomFileForNebulaPublication"); + } + Task publishPluginZipPublicationToZipStagingRepository = project.getTasks() + .findByName("publishPluginZipPublicationToZipStagingRepository"); + if (validatePluginZipPom != null) { + project.getTasks() + .getByName("publishPluginZipPublicationToZipStagingRepository") + .dependsOn("generatePomFileForNebulaPublication"); } - }); } } diff --git a/buildSrc/src/test/java/org/opensearch/gradle/pluginzip/PublishTests.java b/buildSrc/src/test/java/org/opensearch/gradle/pluginzip/PublishTests.java index ae94ace55e6..f5a00d795c0 100644 --- a/buildSrc/src/test/java/org/opensearch/gradle/pluginzip/PublishTests.java +++ b/buildSrc/src/test/java/org/opensearch/gradle/pluginzip/PublishTests.java @@ -28,6 +28,8 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.FileReader; import org.gradle.api.tasks.bundling.Zip; +import java.util.List; +import java.util.ArrayList; public class PublishTests extends GradleUnitTestCase { @@ -56,6 +58,7 @@ public class PublishTests extends GradleUnitTestCase { writeString(new File(projectDir, "settings.gradle"), ""); // Generate the build.gradle file String buildFileContent = "apply plugin: 'maven-publish' \n" + + "apply plugin: 'java' \n" + "publishing {\n" + " repositories {\n" + " maven {\n" @@ -74,10 +77,13 @@ public class PublishTests extends GradleUnitTestCase { + "}"; writeString(new File(projectDir, "build.gradle"), buildFileContent); // Execute the task publishPluginZipPublicationToZipStagingRepository + List allArguments = new ArrayList(); + allArguments.add("build"); + allArguments.add(zipPublishTask); GradleRunner runner = GradleRunner.create(); runner.forwardOutput(); runner.withPluginClasspath(); - runner.withArguments(zipPublishTask); + runner.withArguments(allArguments); runner.withProjectDir(projectDir); BuildResult result = runner.build(); // Check if task publishMavenzipPublicationToZipstagingRepository has ran well @@ -87,6 +93,7 @@ public class PublishTests extends GradleUnitTestCase { new File("build/functionalTest/local-staging-repo/org/opensearch/plugin/sample-plugin/2.0.0.0/sample-plugin-2.0.0.0.zip") .exists() ); + assertEquals(SUCCESS, result.task(":" + "build").getOutcome()); // Parse the maven file and validate the groupID to org.opensearch.plugin MavenXpp3Reader reader = new MavenXpp3Reader(); Model model = reader.read(