How to get a Date
object representing the time of start of the build process in Gradle?
In a plugin I am writing, I need to store the date and time of the build in the constructed archive (it's mainly used to display the date along with build number in the title bar of the application, to make QA life easier).
I want to have the same date for multiple subprojects that are being built, so ideally I would like to just use the start of build. As a workaround, I hold the date in a static field, but it hurts my eyes. I've seen in the source that there are multiple org.gradle.util.Clock
instances that hold such information, but I cannot find a way to retrieve one from a plugin.
gradle, if you have minifyEnabled for debug, remove it. I had it in my project and it took ~2-3 minutes to build. After looking at build progress, I found this as culprit, so deleting the commented line below, my issue was fixed.
In the command prompt, enter Gradle -version. It will display the current version of Gradle just installed on the screen.
Class ProcessResourcesCopies resources from their source to their target directory, potentially processing them. Makes sure no stale resources remain in the target directory.
> gradle -q test Adding test task to project ':project-a' Running tests for project ':project-a' This example uses method Project. afterEvaluate() to add a closure which is executed after the project is evaluated. It is also possible to receive notifications when any project is evaluated.
Your plugin could just set/get a dynamic property on the root project:
def root = project.rootProject
if (!root.hasProperty("startTime")) {
root.startTime = new Date()
}
// do whatever necessary with root.startTime
I've managed to retrieve the build time clock with following code:
Clock clock = project.gradle.services.get(BuildRequestMetaData.class).buildTimeClock
Date startDate = new Date(clock.getStartTime())
Still, it's far from being ideal, since it uses Gradle internal API: getServices()
method is defined in org.gradle.api.internal.GradleInternal
interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With