Skip to content

Commit

Permalink
Make updated JARs reproducible across time zones
Browse files Browse the repository at this point in the history
Issue: #3690
  • Loading branch information
marcphilipp committed May 3, 2024
1 parent 5870c3b commit f21a9c7
Showing 1 changed file with 14 additions and 1 deletion.
Expand Up @@ -8,18 +8,31 @@ import org.gradle.api.provider.Property
import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.process.ExecOperations
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZoneOffset
import javax.inject.Inject

abstract class UpdateJarAction @Inject constructor(private val operations: ExecOperations): Action<Task> {

companion object {
// Since ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES is in the default time zone (see its Javadoc),
// we're converting it to the same time in UTC here to make the jar reproducible regardless of the
// build's time zone.
private val CONSTANT_TIME_FOR_ZIP_ENTRIES = LocalDateTime.ofInstant(Instant.ofEpochMilli(ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES), ZoneId.systemDefault())
.toInstant(ZoneOffset.UTC)
.toString()
}

abstract val javaLauncher: Property<JavaLauncher>

abstract val args: ListProperty<String>

init {
args.convention(listOf(
"--update",
"--date=${Instant.ofEpochMilli(ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES)}",
// Use a constant time to make the JAR reproducible.
"--date=$CONSTANT_TIME_FOR_ZIP_ENTRIES",
))
}

Expand Down

0 comments on commit f21a9c7

Please sign in to comment.