Skip to content

Commit

Permalink
Merge pull request #1004 from TNG/fix/make-maven-plugin-dependent-on-…
Browse files Browse the repository at this point in the history
…everything

Issue-1003: do not force publication on every build
  • Loading branch information
l-1squared authored Oct 14, 2022
2 parents be650b6 + ea5ac34 commit 07a6eb4
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions jgiven-maven-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.stream.Collectors

description = 'JGiven Maven Mojo'


Expand All @@ -21,40 +23,39 @@ task generatePom(type: Copy, dependsOn: copyClasses) {
}
}

Set<Task> 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<Task> 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("<version>.*</version>","")
}
include '**/pom.*'
filter { line ->
line.replaceAll("<version>.*</version>", "")
}
}
into 'build/classes/main/META-INF/maven/com.tngtech.jgiven/jgiven-maven-plugin'
includeEmptyDirs = false
Expand All @@ -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 {
Expand Down

0 comments on commit 07a6eb4

Please sign in to comment.