huxi
(Jörn Huxhorn)
February 19, 2016, 10:23am
1
How can I find out, programmatically, whether the currently executing build is a continuous build?
Context to this question:
I’d like to disable my PushoverAnnouncer in case of continuous build, i.e. only send a notification in case of a normal, non-continuous build.
Chapter 9. Continuous build does not mention a way to do this. Since this is still incubating, I rather ask than searching for a way to do this in the current implementation. That way the answer could be incorporated into the documentation.
Lance_Java
(Lance Java)
February 19, 2016, 10:31am
2
if (project.gradle.startParameter.continuous) {
// do stuff
}
```
1 Like
huxi
(Jörn Huxhorn)
February 19, 2016, 10:50am
3
Thanks.
I tried it like this (instead of this ):
println 'continuous:' + gradle.startParameter.continuous
if(!gradle.startParameter.continuous) {
PushoverAnnouncer announcer = new PushoverAnnouncer(pushoverAppToken, pushoverUser)
AnnouncingBuildListener listener = new AnnouncingBuildListener(announcer)
gradle.addListener(listener)
}
and it’s printing
Waiting for changes to input files of tasks… (ctrl-d to exit)
Change detected, executing build…
continuous:true
continuous:false
It works, partially, because it no longer sends a notification for the project.
But it is still sending a notification for buildSrc
. Can I somehow find out if the current build is a “real” project or just buildSrc
?
Lance_Java
(Lance Java)
February 19, 2016, 11:24am
4
I think this is because you are putting the script in init.d
. Are you able to change it to an explicit apply plugin: Pushover
in your root project?
Rene
(René Groeschke)
February 19, 2016, 11:38am
5
I think there is no public api for this. Your best option is to go after the project name / directory i think.
Lance_Java
(Lance Java)
February 19, 2016, 11:49am
6
This should work
if (gradle.rootProject.rootDir.name != "buildSrc") {
// do stuff
}
huxi
(Jörn Huxhorn)
February 19, 2016, 12:16pm
7
It doesn’t, unfortunately.
What went wrong:
A problem occurred evaluating initialization script.
The root project is not yet available for build.
The idea is that this should always work for all Gradle builds and not just for those which apply a plugin.
Lance_Java
(Lance Java)
February 19, 2016, 12:23pm
8
Stick your logic inside a gradle.projectsEvaluated {}
closure
(note that if your AnnouncingBuildListener also needs this event you might need to fire it manually)