From ea5ac34205f6f88419457ce9d137dbb5f67324dd Mon Sep 17 00:00:00 2001 From: l-1sqared <30831153+l-1squared@users.noreply.github.com> Date: Thu, 13 Oct 2022 08:58:49 +0200 Subject: [PATCH] Issue-1003: do not force publication on every build also make sure that everything is published before adding the maven build Signed-off-by: l-1sqared <30831153+l-1squared@users.noreply.github.com> --- jgiven-maven-plugin/build.gradle | 39 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/jgiven-maven-plugin/build.gradle b/jgiven-maven-plugin/build.gradle index 6e9a9b4c65..175bc20b19 100644 --- a/jgiven-maven-plugin/build.gradle +++ b/jgiven-maven-plugin/build.gradle @@ -1,3 +1,5 @@ +import java.util.stream.Collectors + description = 'JGiven Maven Mojo' @@ -21,40 +23,39 @@ task generatePom(type: Copy, dependsOn: copyClasses) { } } -Set findPublishTask(String projectName){ - project.rootProject.findProject(projectName).getTasks().findAll {it instanceof PublishToMavenLocal} -} - -task generateMavenPlugin(type: CrossPlatformExec, dependsOn: [generatePom, findPublishTask("jgiven-core"), findPublishTask("jgiven-html5-report")]){ +task generateMavenPlugin(type: CrossPlatformExec, dependsOn: generatePom) { // currenlty it seems to be the more or less only clean solution // to generate a plugin.xml file to use maven directly // if anyone has a better solution please let us know! buildCommand 'mvn', '-nsu', '-U', '-f', 'build/maven/pom.xml', 'plugin:descriptor' } -generateMavenPlugin.onlyIf { - // as the generateMavenPlugin task requires mvn, it is only executed - // when actually uploading the archives - // that way the standard build stays maven-free - gradle.taskGraph.getAllTasks() - .findAll{task -> !findPublishTask("jgiven-core").contains(task)} - .findAll{ task -> !findPublishTask("jgiven-html5-report").contains(task) } - .any{it instanceof AbstractPublishToMaven} +generateMavenPlugin.configure { + List thisProjectsPublishTasks = getTasks().withType(PublishToMavenLocal).stream().collect(Collectors.toList()) + mustRunAfter(rootProject.getAllTasks(true).values().stream() + .flatMap(Set::stream) + .filter(task -> task instanceof PublishToMavenLocal) + .filter(task -> !thisProjectsPublishTasks.contains(task)) + .collect(Collectors.toList()) + ) + onlyIf { + gradle.taskGraph.getAllTasks().stream().anyMatch(thisProjectsPublishTasks::contains) + } } task copyMavenPlugin(type: Copy, dependsOn: generateMavenPlugin) { from('build/maven/target/classes') { - include '**/*.xml' + include '**/*.xml' } into 'build/classes/java/main' } task copyPom(type: Copy, dependsOn: generatePom) { from('build/maven') { - include '**/pom.*' - filter { line -> - line.replaceAll(".*","") - } + include '**/pom.*' + filter { line -> + line.replaceAll(".*", "") + } } into 'build/classes/main/META-INF/maven/com.tngtech.jgiven/jgiven-maven-plugin' includeEmptyDirs = false @@ -65,7 +66,7 @@ jar.dependsOn copyMavenPlugin, copyPom class CrossPlatformExec extends Exec { void buildCommand(String command, String... commandArgs) { - if(org.gradle.internal.os.OperatingSystem.current().isWindows()) { + if (org.gradle.internal.os.OperatingSystem.current().isWindows()) { executable = 'cmd' args = ['/c', command] } else {