Skip to content

More accurately document the effects of the buildInfo task never being up-to-date by default #13152

@jnizet

Description

@jnizet

The documentation of the gradle plugin says:

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 slightly longer as more tasks will have to be executed.

This is correct, except for the "slightly longer" part. Since it affects the resources of the project, and since the resources are an input of the test task, using buildInfo() forces all the tests to be executed at each build, which makes it quite more than "slightly" longer :-)

Of course, as documented, we can set the time to null, but then we lose valuable information.

I managed to improve things by using the following trick: declare a task of type BuildInfo, make it a dependency of the bootJar task, and include its produced properties file into the jar file:

task buildInfo(type: org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) {
    destinationDir = file("$buildDir/buildInfo")
}

bootJar {
    dependsOn buildInfo

    into('BOOT-INF/classes/META-INF') {
        from buildInfo.destinationDir
    }
}

This makes the build much faster, since it only has to recreate the jar file, instead of having to re-run all the tests and recreate the jar file.

Couldn't this be the default behavior of the buildInfo() call inside the springBoot closure? You would lose the ability to load the build-info properties file inside tests, but my guess is that no one does that. There might of course be other side-effects that I could miss (on bootRun, maybe).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions