source: build.gradle @ 2556c77

Last change on this file since 2556c77 was 2556c77, checked in by str4d <str4d@…>, 21 months ago

Travis CI: Update config to handle cross-compilation

  • Property mode set to 100644
File size: 5.0 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
43String javaExecutable(String targetJavaHome, String execName) {
44    def javaExecutablesPath = new File(targetJavaHome, "bin")
45    def executable = new File(javaExecutablesPath, execName)
46    if (!executable.exists()) {
47        throw new IllegalArgumentException("There is no ${execName} executable in ${javaExecutablesPath}")
48    }
49    executable.toString()
50}
51
52def releaseVersion = getReleaseVersion()
53def buildVersion = getBuildVersion()
54def buildExtra = getBuildExtra()
55def fullVersion = "$releaseVersion-$buildVersion$buildExtra"
56
57// Exclude apps/ dir itself, but include its subdirs
58def javaProjects = subprojects - project(':apps')
59
60configure(javaProjects) {
61    apply plugin: 'java'
62    apply plugin: 'jacoco'
63    apply plugin: 'eclipse'
64    apply plugin: 'idea'
65
66    repositories {
67        jcenter()
68    }
69
70    dependencies {
71        testCompile 'junit:junit:4.+'
72        testCompile 'org.hamcrest:hamcrest-library:1.3'
73        testCompile 'org.mockito:mockito-core:2.11.0'
74    }
75
76    jar {
77        manifest {
78            attributes 'Implementation-Version': "$fullVersion"
79        }
80    }
81
82    sourceCompatibility = 1.7
83    targetCompatibility = 1.7
84
85    def i2pBootClasspath
86    // Set java7BootClasspath=/path/to/rt.jar:/path/to/jce.jar in ~/.gradle/gradle.properties if needed
87    if (java7BootClasspath) {
88        i2pBootClasspath = java7BootClasspath
89    } else {
90        def java7Home = System.getenv("JAVA7_HOME")
91        if (java7Home) {
92            i2pBootClasspath = "${java7Home}/jre/lib/jce.jar:${java7Home}/jre/lib/rt.jar"
93        }
94    }
95
96    if (i2pBootClasspath) {
97        tasks.withType(AbstractCompile, { AbstractCompile ac ->
98            ac.options.bootstrapClasspath = files(i2pBootClasspath)
99        })
100    } else {
101        if (JavaVersion.current().java8Compatible && !JavaVersion.current().java9Compatible) {
102            throw new GradleException("Set java7BootClasspath property or JAVA7_HOME environment variable to enable cross-compilation, or run Gradle with JDK 9+")
103        }
104        tasks.withType(JavaCompile) {
105            def version = compat(sourceCompatibility)
106            logger.info("Configuring $name to use --release $version")
107            options.compilerArgs.addAll(['--release', version])
108        }
109    }
110
111    // Set up Java override if configured (used to test with Java 7).
112    def targetJavaHome = System.getenv("TARGET_JAVA_HOME")
113    if (targetJavaHome) {
114        if (JavaVersion.current().java9Compatible) {
115            throw new GradleException("Only set TARGET_JAVA_HOME with JDK 8")
116        }
117
118        project.afterEvaluate {
119            logger.info("Target Java home set to ${targetJavaHome}")
120            logger.info("Configuring Gradle to use forked compilation and testing")
121
122            tasks.withType(JavaCompile) {
123                options.fork = true
124                options.forkOptions.javaHome = file(targetJavaHome)
125            }
126
127            tasks.withType(Javadoc) {
128                executable = javaExecutable(targetJavaHome, "javadoc")
129            }
130
131            tasks.withType(Test) {
132                executable = javaExecutable(targetJavaHome, "java")
133            }
134
135            tasks.withType(JavaExec) {
136                executable = javaExecutable(targetJavaHome, "java")
137            }
138        }
139    }
140}
141
142task codeCoverageReport(type: JacocoReport) {
143    dependsOn(javaProjects.test)
144
145    jacocoClasspath = project(':core').configurations.jacocoAnt
146    additionalSourceDirs = files(javaProjects.sourceSets.main.allSource.srcDirs)
147    sourceDirectories = files(javaProjects.sourceSets.main.allSource.srcDirs)
148    classDirectories = files(javaProjects.sourceSets.main.output)
149    executionData = files(javaProjects.jacocoTestReport.executionData)
150
151    doFirst {
152        executionData = files(executionData.findAll { it.exists() })
153    }
154
155    reports {
156        xml.enabled true
157        xml.destination file("${buildDir}/reports/jacoco/report.xml")
158        html.enabled true
159        html.destination file("${buildDir}/reports/jacoco/html")
160    }
161}
162
163//apply from: file('gradle/update.gradle')
Note: See TracBrowser for help on using the repository browser.