如何知道你是否在一个gradle守护进程中运行 [英] How to know whether you are running inside a gradle daemon

查看:94
本文介绍了如何知道你是否在一个gradle守护进程中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



然而,当我们在一个gradle守护进程中运行时,这个失败相当严重:我们完全没有摆脱Jetty实例,所以它必须与gradle进程本身一起死掉。 (但是,这并不是真正的大问题,因为我们不希望在这个CI集成测试案例中使用gradle守护进程)。

因此,我们想知道当前任务是否在gradle守护进程中运行 - 以便我们可以抛出异常或以其他方式通知用户这是错误的方法,请运行此未守护程序。

解决方案

Gradle命名其一个线程守护线程,所以如果你允许黑客攻击,
$ b

  def isDaemon = Thread.allStackTraces.keySet.any {it.name.containsDaemon}; 


We have a situation where we take up a Jetty instance inside the VM that runs gradle.

However, this fails pretty badly when we are running inside a gradle daemon: We don't get rid of the Jetty instance totally, so it have to die with the gradle process itself. (However, that is not really of a big concern, since we do not want the gradle daemon in this CI integration tests case anyway).

So, we would like to know whether the current task is running inside a gradle daemon, or not - so that we can throw an exception or otherwise inform the user that this is the wrong approach, please run this un-daemonized.

解决方案

Gradle names one of its thread "Daemon thread" so if you allow a hack, this could work:

def isDaemon = Thread.allStackTraces.keySet.any { it.name.contains "Daemon" };

这篇关于如何知道你是否在一个gradle守护进程中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆