source: build.gradle @ 7c71ff1

Last change on this file since 7c71ff1 was d13bf0b, checked in by str4d <str4d@…>, 19 months ago

Gradle: Use tested version of Mockito

The Ant JUnit tests have been tested previously with 2.5.0 as working.
2.11.0 is causing issues that are manifesting as Gradle-specific test
failures. We can upgrade this explicitly when we also upgrade the
dependency in the Ant-based CI system.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1plugins {
2    id 'idea'
3}
4
5String getReleaseVersion() {
6    def releaseVersion
7    file("core/java/src/net/i2p/CoreVersion.java").readLines().findAll({ line ->
8        line.contains("public final static String VERSION")
9    }).first().eachMatch('.*"([^"]+)";', {
10        releaseVersion = it[1]
11    })
12    releaseVersion
13}
14
15String getBuildVersion() {
16    def buildVersion
17    file("router/java/src/net/i2p/router/RouterVersion.java").readLines().findAll({ line ->
18        line.contains("public final static long BUILD")
19    }).first().eachMatch('.*=\\s+([0-9]+);', {
20        buildVersion = it[1]
21    })
22    buildVersion
23}
24
25String getBuildExtra() {
26    def buildExtra
27    file("router/java/src/net/i2p/router/RouterVersion.java").readLines().findAll({ line ->
28        line.contains("public final static String EXTRA")
29    }).first().eachMatch('.*"(.*)";', {
30        buildExtra = it[1]
31    })
32    buildExtra
33}
34
35String getBuiltBy() {
36    def builtBy
37    file("override.properties").readLines().findAll({ line ->
38        line.contains("build.built-by")
39    }).first().eachMatch('.*=(.*)', {
40        builtBy = it[1]
41    })
42    builtBy
43}
44
45boolean haveMonotone() {
46    file("_MTN").exists()
47}
48
49String getWorkspaceVersion() {
50    if (haveMonotone()) {
51        def stdout = new ByteArrayOutputStream()
52        exec {
53            executable 'mtn'
54            args 'automate', 'get_base_revision_id'
55            standardOutput = stdout
56        }
57        stdout.toString().trim()
58    } else {
59        'unknown'
60    }
61}
62
63String compat(String src) {
64    if (src.contains('.')) {
65        src.substring(src.lastIndexOf('.') + 1)
66    } else {
67        src
68    }
69}
70
71String javaExecutable(String targetJavaHome, String execName) {
72    def javaExecutablesPath = new File(targetJavaHome, "bin")
73    def executable = new File(javaExecutablesPath, execName)
74    if (!executable.exists()) {
75        throw new IllegalArgumentException("There is no ${execName} executable in ${javaExecutablesPath}")
76    }
77    executable.toString()
78}
79
80def releaseVersion = getReleaseVersion()
81def buildVersion = getBuildVersion()
82def buildExtra = getBuildExtra()
83def fullVersion = "$releaseVersion-$buildVersion$buildExtra"
84
85def builtBy = getBuiltBy()
86def workspaceVersion = getWorkspaceVersion()
87
88// Exclude apps/ dir itself, but include its subdirs
89def javaProjects = subprojects - project(':apps')
90
91configure(javaProjects) {
92    apply plugin: 'java'
93    apply plugin: 'jacoco'
94    apply plugin: 'eclipse'
95    apply plugin: 'idea'
96
97    repositories {
98        jcenter()
99    }
100
101    dependencies {
102        testCompile 'junit:junit:4.+'
103        testCompile 'org.hamcrest:hamcrest-library:1.3'
104        testCompile 'org.mockito:mockito-core:2.5.0'
105    }
106
107    sourceCompatibility = 1.7
108    targetCompatibility = 1.7
109
110    jar {
111        // Empty attributes are set by each project. They are initialized
112        // here in order to create a defined ordering of the attributes.
113        manifest {
114            attributes 'Specification-Title': ''
115            attributes 'Specification-Version': "$releaseVersion"
116            attributes 'Specification-Vendor': 'The I2P Project https://geti2p.net/'
117            attributes 'Implementation-Title': ''
118            attributes 'Implementation-Version': "$fullVersion"
119            attributes 'Implementation-Vendor': 'The I2P Project https://geti2p.net/'
120            attributes 'Built-By': "$builtBy"
121            attributes 'Build-Date': 'reproducible'
122            attributes 'Base-Revision': "$workspaceVersion"
123            attributes 'Workspace-Changes': ''
124            attributes 'X-Compile-Source-JDK': "$sourceCompatibility"
125            attributes 'X-Compile-Target-JDK': "$targetCompatibility"
126        }
127    }
128
129    tasks.withType(AbstractArchiveTask) {
130        preserveFileTimestamps = false
131        reproducibleFileOrder = true
132    }
133
134    def i2pBootClasspath
135    // Set java7BootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
136    if (java7BootClasspath) {
137        i2pBootClasspath = java7BootClasspath
138    } else {
139        def java7Home = System.getenv("JAVA7_HOME")
140        if (java7Home) {
141            i2pBootClasspath = "${java7Home}/jre/lib/jce.jar:${java7Home}/jre/lib/rt.jar"
142        }
143    }
144
145    if (i2pBootClasspath) {
146        tasks.withType(AbstractCompile, { AbstractCompile ac ->
147            ac.options.bootstrapClasspath = files(i2pBootClasspath)
148        })
149    } else {
150        if (JavaVersion.current().java8Compatible && !JavaVersion.current().java9Compatible) {
151            throw new GradleException("Set java7BootClasspath property or JAVA7_HOME environment variable to enable cross-compilation, or run Gradle with JDK 9+")
152        }
153        project.afterEvaluate {
154            tasks.withType(JavaCompile) {
155                def version = compat(sourceCompatibility)
156                logger.info("Configuring $name to use --release $version")
157                options.compilerArgs.addAll(['--release', version])
158            }
159        }
160    }
161
162    // Set up Java override if configured (used to test with Java 7).
163    def targetJavaHome = System.getenv("TARGET_JAVA_HOME")
164    if (targetJavaHome) {
165        if (JavaVersion.current().java9Compatible) {
166            throw new GradleException("Only set TARGET_JAVA_HOME with JDK 8")
167        }
168
169        project.afterEvaluate {
170            logger.info("Target Java home set to ${targetJavaHome}")
171            logger.info("Configuring Gradle to use forked compilation and testing")
172
173            tasks.withType(JavaCompile) {
174                options.fork = true
175                options.forkOptions.javaHome = file(targetJavaHome)
176            }
177
178            tasks.withType(Javadoc) {
179                executable = javaExecutable(targetJavaHome, "javadoc")
180            }
181
182            tasks.withType(Test) {
183                executable = javaExecutable(targetJavaHome, "java")
184            }
185
186            tasks.withType(JavaExec) {
187                executable = javaExecutable(targetJavaHome, "java")
188            }
189        }
190    }
191}
192
193task codeCoverageReport(type: JacocoReport) {
194    dependsOn(javaProjects.test)
195
196    jacocoClasspath = project(':core').configurations.jacocoAnt
197    additionalSourceDirs.from(files(javaProjects.sourceSets.main.allSource.srcDirs))
198    sourceDirectories.from(files(javaProjects.sourceSets.main.allSource.srcDirs))
199    classDirectories.from(files(javaProjects.sourceSets.main.output))
200    executionData.from(files(javaProjects.jacocoTestReport.executionData))
201
202    doFirst {
203        executionData = files(executionData.findAll { it.exists() })
204    }
205
206    reports {
207        xml.enabled true
208        xml.destination file("${buildDir}/reports/jacoco/report.xml")
209        html.enabled true
210        html.destination file("${buildDir}/reports/jacoco/html")
211    }
212}
213
214//apply from: file('gradle/update.gradle')
Note: See TracBrowser for help on using the repository browser.