Skip to content

Commit f21a9c7

Browse files
committed
Make updated JARs reproducible across time zones
Issue: #3690
1 parent 5870c3b commit f21a9c7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

gradle/plugins/common/src/main/kotlin/junitbuild/java/UpdateJarAction.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,31 @@ import org.gradle.api.provider.Property
88
import org.gradle.jvm.toolchain.JavaLauncher
99
import org.gradle.process.ExecOperations
1010
import java.time.Instant
11+
import java.time.LocalDateTime
12+
import java.time.ZoneId
13+
import java.time.ZoneOffset
1114
import javax.inject.Inject
1215

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

18+
companion object {
19+
// Since ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES is in the default time zone (see its Javadoc),
20+
// we're converting it to the same time in UTC here to make the jar reproducible regardless of the
21+
// build's time zone.
22+
private val CONSTANT_TIME_FOR_ZIP_ENTRIES = LocalDateTime.ofInstant(Instant.ofEpochMilli(ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES), ZoneId.systemDefault())
23+
.toInstant(ZoneOffset.UTC)
24+
.toString()
25+
}
26+
1527
abstract val javaLauncher: Property<JavaLauncher>
1628

1729
abstract val args: ListProperty<String>
1830

1931
init {
2032
args.convention(listOf(
2133
"--update",
22-
"--date=${Instant.ofEpochMilli(ZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES)}",
34+
// Use a constant time to make the JAR reproducible.
35+
"--date=$CONSTANT_TIME_FOR_ZIP_ENTRIES",
2336
))
2437
}
2538

0 commit comments

Comments
 (0)