11/* *****************************************************************************
22 * Copyright (c) 2016 TypeFox and others.
3- *
3+ *
44 * This program and the accompanying materials are made available under the
55 * terms of the Eclipse Public License v. 2.0 which is available at
66 * http://www.eclipse.org/legal/epl-2.0,
77 * or the Eclipse Distribution License v. 1.0 which is available at
88 * http://www.eclipse.org/org/documents/edl-v10.php.
9- *
9+ *
1010 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
1111 ******************************************************************************/
1212
13+ final int JAVA_VERSION = (findProperty(' javaVersion' ) ?: 11 ) as Integer
14+
1315java {
14- sourceCompatibility = JavaVersion . VERSION_11
16+ // Keep source level at Java 11
17+ sourceCompatibility = JavaVersion . toVersion(JAVA_VERSION )
18+ // Use a Java 11 toolchain for compilation and task launches
19+ toolchain {
20+ languageVersion = JavaLanguageVersion . of(JAVA_VERSION )
21+ }
1522}
1623
1724tasks. withType(Javadoc ) {
@@ -21,6 +28,15 @@ tasks.withType(Javadoc) {
2128
2229tasks. withType(JavaCompile ) {
2330 options. encoding = ' UTF-8'
31+ // Ensure cross-compilation targets Java 11 APIs
32+ options. release = JAVA_VERSION
33+ }
34+
35+ // Ensure tests run on the Java 11 toolchain (not the Gradle JVM)
36+ tasks. withType(Test ). configureEach {
37+ javaLauncher = javaToolchains. launcherFor {
38+ languageVersion = JavaLanguageVersion . of(JAVA_VERSION )
39+ }
2440}
2541
2642task sourcesJar (type : Jar , dependsOn : classes) {
@@ -37,15 +53,15 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
3753 from javadoc. destinationDir
3854}
3955
40- ext. signMethod = { jarfile ->
56+ ext. signMethod = { jarfile ->
4157 println " Signing $jarfile "
4258 def SIGNING_SERVICE = ' https://cbi.eclipse.org/jarsigner/sign'
4359 def STDOUT_FORMAT = ' %{size_upload} bytes uploaded, %{size_download} bytes downloaded (%{time_total} s)\\ n'
4460
45- ProcessBuilder curl_pb = new ProcessBuilder (" curl" ,
61+ ProcessBuilder curl_pb = new ProcessBuilder (" curl" ,
4662 " --fail" , " --silent" , " --show-error" , " --output" ,
4763 " ${ jarfile} -signed" , " --form" , " file=@${ jarfile} " ,
48- " --write-out" , STDOUT_FORMAT ,
64+ " --write-out" , STDOUT_FORMAT ,
4965 SIGNING_SERVICE );
5066 println String . join(" " , curl_pb. command());
5167 curl_pb. directory(new File (" ${ project.buildDir} " ));
@@ -56,23 +72,23 @@ ext.signMethod = { jarfile ->
5672 println curl_process. text
5773
5874 if (curl_process. exitValue() != 0 ) {
59- throw new GradleException (" Failed to run curl" );
75+ throw new GradleException (" Failed to run curl" );
6076 }
6177
62- ProcessBuilder mv_pb = new ProcessBuilder (" mv" ,
78+ ProcessBuilder mv_pb = new ProcessBuilder (" mv" ,
6379 " ${ jarfile} -signed" , jarfile)
6480 println String . join(" " , mv_pb. command());
6581 mv_pb. directory(new File (" ${ project.buildDir} " ));
6682 Process mv_process = mv_pb. start()
6783 mv_process. waitFor()
6884
6985 if (curl_process. exitValue() != 0 ) {
70- throw new GradleException (" Failed to run mv" );
86+ throw new GradleException (" Failed to run mv" );
7187 }
7288}
7389
7490task signJar (description : ' Sign JARs with Eclipse Signing Service' , group : ' Build' ){
75- doLast {
91+ doLast {
7692 signMethod(" ${ project.buildDir} /libs/${ project.name} -${ project.version} .jar" )
7793 signMethod(" ${ project.buildDir} /libs/${ project.name} -${ project.version} -sources.jar" )
7894 signMethod(" ${ project.buildDir} /libs/${ project.name} -${ project.version} -javadoc.jar" )
0 commit comments