This works:

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

bootBuildImage {
    jar = bootWar.archiveFile
}

This doesn't work:

bootBuildImage {
    jar = bootWar.archiveFile
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

The customization of the task causes targetCompatibilty to be read and at that point it hasn't been set so the default value is used. It needs to be configured using a provider so that the configured targetCompatibility isn't read until bootBuildImage needs it.