【问题标题】:How to run additional task at the end of gradle bootRun如何在 gradle bootRun 结束时运行附加任务
【发布时间】:2018-05-04 10:19:33
【问题描述】:

我有使用 gradle bootRun 运行的服务器应用程序。

我还有脚本 runUpdate.sh,我需要在应用程序启动后从终端命令行运行。

我创建了运行此脚本的 gradle 任务:

task runUpdate(type: Exec) {
    commandLine './runUpdate.sh'
}

现在我想从 bootRun 自动运行这个脚本。无需手动执行其他步骤。我该怎么做?

【问题讨论】:

    标签: java spring-boot gradle bootrun


    【解决方案1】:

    我正在使用命令 shouldRunAfter 来定义我的任务在 bootRun 之前运行

    task runUpdate(type: Exec) {
        commandLine './runUpdate.sh'
    }
    
    // This will set te bootRun to wait your task run first
    bootRun.configure {
        shouldRunAfter runUpdate
    }
    

    【讨论】:

      【解决方案2】:

      https://docs.gradle.org/current/userguide/more_about_tasks.html

      你可以使用 gradle 依赖 这是一个示例代码

      bootRun{
        dependsOn runUpdate
      }
      task runUpdate(type: Exec) {
          commandLine './runUpdate.sh'
      }
      

      【讨论】:

      • 在这种情况下 runUpdate 将首先运行。正确的?我需要它在服务器启动时运行。我可以将dependsOn bootRun 放入runUpdate 中吗?
      • 是的,runUpdate 将首先运行。 @Jacob,你需要的是finalizedBy
      猜你喜欢
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-22
      • 2018-08-29
      • 1970-01-01
      • 1970-01-01
      • 2014-06-30
      相关资源
      最近更新 更多