From 4d8bc5e784f2493462f36f219b70750a7c8d7c71 Mon Sep 17 00:00:00 2001 From: "radoslaw.panuszewski" Date: Wed, 4 Sep 2024 22:22:04 +0200 Subject: [PATCH] Use Tooling API to start new build --- .../build/axion/release/ReleaseTask.groovy | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy index 702e27fc..33a1a470 100644 --- a/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy +++ b/src/main/groovy/pl/allegro/tech/build/axion/release/ReleaseTask.groovy @@ -1,6 +1,9 @@ package pl.allegro.tech.build.axion.release + +import org.gradle.api.Task import org.gradle.api.tasks.TaskAction +import org.gradle.tooling.GradleConnector import pl.allegro.tech.build.axion.release.domain.Releaser import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResult import pl.allegro.tech.build.axion.release.domain.scm.ScmPushResultOutcome @@ -10,6 +13,8 @@ import java.nio.file.Files import java.nio.file.Paths import java.nio.file.StandardOpenOption +import static java.util.stream.Collectors.toList + abstract class ReleaseTask extends BaseAxionTask { @TaskAction @@ -40,6 +45,32 @@ abstract class ReleaseTask extends BaseAxionTask { StandardOpenOption.APPEND ) } + def projectConnection = GradleConnector + .newConnector() + .forProjectDirectory(layout.projectDirectory.asFile) + .connect() + + def tasksExceptCurrentOne = project.gradle.taskGraph.allTasks - this + + tasksExceptCurrentOne.forEach { task -> + if (!task.state.executed) { + task.actions.clear() + } + } + + def taskNames = tasksExceptCurrentOne + .stream() + .map(Task::getName) + .collect(toList()) + + def buildLauncher = projectConnection + .newBuild() + .forTasks(*taskNames) + .addArguments('-Prelease.localOnly', '-Prelease.disableChecks') + .setStandardInput(System.in) + .setStandardOutput(System.out) + .setStandardError(System.err) + buildLauncher.run() } } }