Commit 9640881f authored by Andy Wilkinson's avatar Andy Wilkinson

Fix BuildInfo up-to-date check when group, name, or version changes

Previously, if the project's group, name, or version changed the
BuildInfo task would still be considered up-to-date as the values of
the project's properties were not reflected in the fields of the
BuildInfo instance.

This commit updates BuildInfo to copy the value of the project's
property to the corresponding BuildInfo field when the property is
read using its getter method on BuildInfo.

Closes gh-12266
parent 3e4da3cc
......@@ -57,7 +57,10 @@ public class BuildInfoProperties implements Serializable {
* @return the group
*/
public String getGroup() {
return this.group != null ? this.group : this.project.getGroup().toString();
if (this.group == null) {
this.group = this.project.getGroup().toString();
}
return this.group;
}
/**
......@@ -94,7 +97,10 @@ public class BuildInfoProperties implements Serializable {
* @return the version
*/
public String getVersion() {
return this.version != null ? this.version : this.project.getVersion().toString();
if (this.version == null) {
this.version = this.project.getVersion().toString();
}
return this.version;
}
/**
......@@ -113,7 +119,10 @@ public class BuildInfoProperties implements Serializable {
* @return the name
*/
public String getName() {
return this.name != null ? this.name : this.project.getName();
if (this.name == null) {
this.name = this.project.getName();
}
return this.name;
}
/**
......
......@@ -21,6 +21,7 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.Rule;
import org.junit.Test;
......@@ -84,6 +85,16 @@ public class BuildInfoIntegrationTests {
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
}
@Test
public void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() {
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
BuildResult result = this.gradleBuild.build("buildInfo", "-PnullTime",
"-PprojectVersion=0.2.0");
System.out.println(result.getOutput());
assertThat(result.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
private Properties buildInfoProperties() {
File file = new File(this.gradleBuild.getProjectDir(),
"build/build-info.properties");
......
......@@ -8,13 +8,17 @@ def property(String name, Object defaultValue) {
project.hasProperty(name) ? project.getProperty(name) : defaultValue
}
version = property('projectVersion', '0.1.0')
task buildInfo(type: org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) {
destinationDir file(property('buildInfoDestinationDir', project.buildDir))
properties {
artifact = property('buildInfoArtifact', 'foo')
version = property('buildInfoVersion', '1.0')
group = property('buildInfoGroup', 'foo')
name = property('buildInfoName', 'foo')
if (!project.hasProperty('projectVersion')) {
version = property('buildInfoVersion', '1.0')
}
additional = ['additional': property('buildInfoAdditional', 'foo')]
if (project.hasProperty('nullTime')) {
time = null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment