Consider time in BuildInfo up-to-date checks and allow it to be set
Closes gh-12111 Closes gh-12266
This commit is contained in:
@@ -38,6 +38,9 @@ By default, the generated build information is derived from the project:
|
||||
| `build.version`
|
||||
| The version of the project
|
||||
|
||||
| `build.time`
|
||||
| The time at which the project is being built
|
||||
|
||||
|===
|
||||
|
||||
The properties can be customized using the DSL:
|
||||
@@ -47,6 +50,13 @@ The properties can be customized using the DSL:
|
||||
include::../gradle/integrating-with-actuator/build-info-custom-values.gradle[tags=custom-values]
|
||||
----
|
||||
|
||||
The default value for `build.time` is the instant at which the project is being built. A
|
||||
side-effect of this is that the task will never be up-to-date and, therefore, builds will
|
||||
take slighly longer as more tasks will have to be executed. Another side-effect is that
|
||||
the task's output will always change and, therefore, the build will not be truly
|
||||
repeatable. If you value build performance or repeatability more highly than the accuracy
|
||||
of the `build.time` property, set `time` to `null` or a fixed value.
|
||||
|
||||
Additional properties can also be added to the build information:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim"]
|
||||
|
||||
@@ -61,7 +61,8 @@ public class BuildInfo extends ConventionTask {
|
||||
? "unspecified"
|
||||
: this.properties.getArtifact(),
|
||||
this.properties.getVersion(),
|
||||
this.properties.getName(), coerceToStringValues(
|
||||
this.properties.getName(), this.properties.getTime(),
|
||||
coerceToStringValues(
|
||||
this.properties.getAdditional())));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.gradle.tasks.buildinfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,10 +41,13 @@ public class BuildInfoProperties implements Serializable {
|
||||
|
||||
private String name;
|
||||
|
||||
private Instant time;
|
||||
|
||||
private Map<String, Object> additionalProperties = new HashMap<>();
|
||||
|
||||
BuildInfoProperties(Project project) {
|
||||
this.project = project;
|
||||
this.time = Instant.now();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,6 +125,23 @@ public class BuildInfoProperties implements Serializable {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value used for the {@code build.time} property. Defaults to
|
||||
* {@link Instant#now} when the {@code BuildInfoProperties} instance was created.
|
||||
* @return the time
|
||||
*/
|
||||
public Instant getTime() {
|
||||
return this.time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value used for the {@code build.time} property.
|
||||
* @param time the build time
|
||||
*/
|
||||
public void setTime(Instant time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the additional properties that will be included. When written, the name of
|
||||
* each additional property is prefixed with {@code build.}.
|
||||
@@ -152,6 +173,7 @@ public class BuildInfoProperties implements Serializable {
|
||||
result = prime * result + ((this.group == null) ? 0 : this.group.hashCode());
|
||||
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
|
||||
result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());
|
||||
result = prime * result + ((this.time == null) ? 0 : this.time.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -207,6 +229,14 @@ public class BuildInfoProperties implements Serializable {
|
||||
else if (!this.version.equals(other.version)) {
|
||||
return false;
|
||||
}
|
||||
if (this.time == null) {
|
||||
if (other.time != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!this.time.equals(other.time)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user