source: build.gradle @ 9731c20

Last change on this file since 9731c20 was 9731c20, checked in by str4d <str4d@…>, 22 months ago

Gradle: Improve cross-compilation support

JDK 9+ have a —release flag that correctly configures the bootClasspath.
For JDK 8 we now enforce manual configuration.

  • Property mode set to 100644
File size: 3.6 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 compat(String src) {
36    if (src.contains('.')) {
37        src.substring(src.lastIndexOf('.') + 1)
38    } else {
39        src
40    }
41}
42
43def releaseVersion = getReleaseVersion()
44def buildVersion = getBuildVersion()
45def buildExtra = getBuildExtra()
46def fullVersion = "$releaseVersion-$buildVersion$buildExtra"
47
48// Exclude apps/ dir itself, but include its subdirs
49def javaProjects = subprojects - project(':apps')
50
51configure(javaProjects) {
52    apply plugin: 'java'
53    apply plugin: 'jacoco'
54    apply plugin: 'eclipse'
55    apply plugin: 'idea'
56
57    repositories {
58        jcenter()
59    }
60
61    dependencies {
62        testCompile 'junit:junit:4.+'
63        testCompile 'org.hamcrest:hamcrest-library:1.3'
64        testCompile 'org.mockito:mockito-core:2.11.0'
65    }
66
67    jar {
68        manifest {
69            attributes 'Implementation-Version': "$fullVersion"
70        }
71    }
72
73    sourceCompatibility = 1.7
74    targetCompatibility = 1.7
75
76    def i2pBootClasspath
77    // Set java7BootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
78    if (java7BootClasspath) {
79        i2pBootClasspath = java7BootClasspath
80    } else {
81        def java7Home = System.getenv("JAVA7_HOME")
82        if (java7Home) {
83            i2pBootClasspath = "${java7Home}/jre/lib/jce.jar:${java7Home}/jre/lib/rt.jar"
84        }
85    }
86
87    if (i2pBootClasspath) {
88        tasks.withType(AbstractCompile, { AbstractCompile ac ->
89            ac.options.bootstrapClasspath = files(i2pBootClasspath)
90        })
91    } else {
92        if (JavaVersion.current().java8Compatible && !JavaVersion.current().java9Compatible) {
93            throw new GradleException("Set java7BootClasspath property or JAVA7_HOME environment variable to enable cross-compilation, or run Gradle with JDK 9+")
94        }
95        tasks.withType(JavaCompile) {
96            def version = compat(sourceCompatibility)
97            logger.info("Configuring $name to use --release $version")
98            options.compilerArgs.addAll(['--release', version])
99        }
100    }
101}
102
103task codeCoverageReport(type: JacocoReport) {
104    dependsOn(javaProjects.test)
105
106    jacocoClasspath = project(':core').configurations.jacocoAnt
107    additionalSourceDirs = files(javaProjects.sourceSets.main.allSource.srcDirs)
108    sourceDirectories = files(javaProjects.sourceSets.main.allSource.srcDirs)
109    classDirectories = files(javaProjects.sourceSets.main.output)
110    executionData = files(javaProjects.jacocoTestReport.executionData)
111
112    doFirst {
113        executionData = files(executionData.findAll { it.exists() })
114    }
115
116    reports {
117        xml.enabled true
118        xml.destination file("${buildDir}/reports/jacoco/report.xml")
119        html.enabled true
120        html.destination file("${buildDir}/reports/jacoco/html")
121    }
122}
123
124//apply from: file('gradle/update.gradle')
Note: See TracBrowser for help on using the repository browser.