forked from rsksmart/gradle-witness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
41 lines (35 loc) · 1.07 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
apply plugin: 'groovy'
dependencies {
compile gradleApi()
compile localGroovy()
}
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
tasks.withType(Jar) {
preserveFileTimestamps = false
reproducibleFileOrder = true
dirMode = 0775
fileMode = 0664
doLast {
stripJar(outputs.files.singleFile)
}
}
def stripJar(File originalFile) {
def constantTimeForZipEntries = new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0).timeInMillis
def reproducibleFile = File.createTempFile("temp", ".tmp")
reproducibleFile.withOutputStream { fout ->
def out = new JarOutputStream(fout)
def jf = new JarFile(originalFile)
jf.entries().unique {it.name}.sort {it.name}.each {
def copy = new JarEntry(it.name)
copy.time = constantTimeForZipEntries
out.putNextEntry(copy)
out << jf.getInputStream(it)
}
out.finish()
}
reproducibleFile.renameTo originalFile
}