Gradle任务取决于bootRun

时间:2019-04-14 16:06:05

标签: java spring gradle

我有两个互斥的任务,都应在完成后启动bootRun

我提到它们是互斥的,因为我不希望bootRun依赖它们中的任何一个。相反,我正在寻找类似于以下内容的流:

task A() {
   // setup for task A
   // runs bootRun on completion
}

task B() {
   // Does some things
   // runs bootRun on completion
}

我尝试了以下方法,

task C() {
 // Performs the task A setup
}

task A() {
 dependsOn 'C'
 dependsOn 'bootRun'
}

,以便gradle A将启动安装程序(task C)和bootRun(对于task B具有类似的设置)。结果为Task with path 'bootRun' not found in project ':x'

我还尝试将A / B任务声明为: task A(type: org.springframework.boot.gradle.run.BootRunTask),但会导致错误Could not get unknown property 'org' for project ':x' of type org.gradle.api.Project

如何在gradle中编写一个任务,该任务将在完成后启动bootRun?

编辑:

这是一个多模块设置,看起来像:

settings.gradle
build.gradle
Application module
   build.gradle (spring boot plugin lives here)
   main() lives here
Service module
   build.gradle (this is where tasks A and B live)

Spring Boot插件通过以下方式在应用程序模块的build.gradle中提供:

plugins {
   id 'org.springframework.boot' version '2.0.0.RELEASE'
}

我也可以将相同的插件添加到Service模块,尽管它不知道主类是什么。

1 个答案:

答案 0 :(得分:1)

您需要finalizedBy(https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:finalizer_tasks

A.finalizedBy bootRun
B.finalizedBy bootRun