diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java index 322686b18c..a7df83bfc4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoProperties.java @@ -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; } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.java index e18ffcc8d2..d68f075c6e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.java @@ -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"); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.gradle index e97674aee0..11b31a26d4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/buildinfo/BuildInfoIntegrationTests.gradle @@ -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