Skip to content

Commit

Permalink
Upgrade Java build to target JDK 17 (#2010)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepone authored Apr 3, 2024
1 parent 8f6f3e2 commit 1aac6ec
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 240 deletions.
9 changes: 8 additions & 1 deletion .github/actions/setup-dependencies/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,21 @@ runs:
run: |
sudo apt-get update && sudo apt-get install -y \
python3 python3-pip nodejs libbz2-dev libssl-dev libffi-dev \
libmcpp-dev libedit-dev liblmdb-dev libexpat1-dev libsystemd-dev openjdk-17-jdk \
libmcpp-dev libedit-dev liblmdb-dev libexpat1-dev libsystemd-dev \
ruby ruby-dev php-cli php-dev \
libbluetooth-dev libdbus-1-dev \
libsystemd-dev
shell: bash
if: runner.os == 'Linux'

- name: Setup Oracle Java 17
uses: actions/setup-java@v4
with:
distribution: "oracle"
java-version: "17"
if: runner.os == 'Linux'

- name: Install testing dependencies from pip
run: python3 -m pip install passlib cryptography numpy
shell: bash
Expand Down
36 changes: 8 additions & 28 deletions java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Copyright (c) ZeroC, Inc. All rights reserved.
//

import org.gradle.util.GradleVersion

subprojects {
project.ext.topSrcDir = "$rootProject.projectDir/.."

Expand All @@ -20,21 +18,15 @@ subprojects {
url this.devRepo
}
}

if(new File("/usr/share/maven-repo").exists()) {
maven {
url "/usr/share/maven-repo"
}
}

mavenCentral()
}

// Only enable infer module path with Java 9 and up
if(GradleVersion.current() >= GradleVersion.version('6.4')) {
java {
modularity.inferModulePath = targetJavaRelease.toInteger() > 8
}
java {
modularity.inferModulePath = true
// The corresponding -source and -target javac options are suppressed by gradle when
// --release is set through options.compileArgs (see above).
sourceCompatibility = "1.${targetJavaRelease}"
targetCompatibility = "1.${targetJavaRelease}"
}

jar {
Expand Down Expand Up @@ -66,23 +58,11 @@ if(!System.env.ICE_BIN_DIST?.split(" ").find{ it == 'all' || it.contains('java')
]

task alljavadoc(type: Javadoc) {

// We rely on Java9+ javadoc features
enabled = JavaVersion.current() > JavaVersion.VERSION_1_8
exclude "**/module-info.java"
enabled = true
source exportedProjects.collect { project(it).javadoc.source }
classpath = files(exportedProjects.collect { project(it).javadoc.classpath })
exclude "**/module-info.java"
destinationDir = file("${buildDir}/docs/javadoc")

if(GradleVersion.current() >= GradleVersion.version('4.7') &&
JavaVersion.current() > JavaVersion.VERSION_1_10 && JavaVersion.current() <= JavaVersion.VERSION_11) {
// --no-module-directories is an undocumented option required for the generated search to work properly.
// Without this option, search returns ../undefined/... URLs.
//
// This option was removed on JDK 13 https://bugs.openjdk.java.net/browse/JDK-8215582
//
options.addBooleanOption('-no-module-directories', true)
}
options.addBooleanOption('html5', true)
options.header = 'Ice for Java'
options.docTitle = "Ice ${iceVersion} API Reference"
Expand Down
2 changes: 1 addition & 1 deletion java/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prefix =
// Used to set --release (with javac >=9) or -source/-target with older javac
// versions.
//
targetJavaRelease = 8
targetJavaRelease = 17

//
// Define debug as true if you want to build with debug information,
Expand Down
35 changes: 2 additions & 33 deletions java/gradle/ice.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,43 +66,12 @@ spotless {
// Android does not have a compileJava task
if(!(project.hasProperty('android') && project.android.sourceSets)) {
compileJava {
exclude 'module-info.java'
// target Java 8 using the --release option introduced in Java 9
if(JavaVersion.current() > JavaVersion.VERSION_1_8) {
options.compilerArgs.addAll(['--release', "${targetJavaRelease}"])
}
// Set the target release using the --release option
options.compilerArgs.addAll(['--release', "${targetJavaRelease}"])
options.debug = debug
}

if(JavaVersion.current() > JavaVersion.VERSION_1_8) {
task compileModuleInfoJava(type: JavaCompile) {
classpath = files() // empty
source = 'src/main/java/module-info.java'
// same dir to see classes compiled by compileJava
if (GradleVersion.current() >= GradleVersion.version('8.0')) {
destinationDirectory = compileJava.destinationDirectory
} else {
destinationDir = compileJava.destinationDir
}
doFirst {
options.compilerArgs = [
'--release', '9',
'--module-path', compileJava.classpath.asPath,
'-Xlint:-module',
]
}
}

compileModuleInfoJava.dependsOn compileJava
classes.dependsOn compileModuleInfoJava
}
}

// The corresponding -source and -target javac options are suppressed by gradle when
// --release is set through options.compileArgs (see above).
sourceCompatibility = "1.${targetJavaRelease}"
targetCompatibility = "1.${targetJavaRelease}"

// Determine the name of the Slice-to-Java translator
def isWindows = System.properties['os.name'].toLowerCase().contains('windows')

Expand Down
46 changes: 8 additions & 38 deletions java/gradle/library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@
//

jar {
if (GradleVersion.current() >= GradleVersion.version('8.0')) {
destinationDirectory = new File("${libDir}")
} else {
destinationDir = new File("${libDir}")
}
destinationDirectory = new File("${libDir}")
}

task jarSources(type:Jar, dependsOn: jar){
from sourceSets.main.allSource
if (GradleVersion.current() >= GradleVersion.version('8.0')) {
archiveClassifier = 'sources'
destinationDirectory = new File("${libDir}")
} else {
classifier = 'sources'
destinationDir = new File("${libDir}")
}
archiveClassifier = 'sources'
destinationDirectory = new File("${libDir}")
}

javadoc.dependsOn(compileSlice)

javadoc {
// We rely on Java9+ javadoc features
enabled = JavaVersion.current() > JavaVersion.VERSION_1_8
source = sourceSets.main.allJava
enabled = true
doFirst {
exclude "**/module-info.java"
options.addBooleanOption('html5', true)
options.addStringOption('Xdoclint:none', '-quiet')
}
failOnError = true
Expand All @@ -37,24 +27,12 @@ javadoc {

task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc
if (GradleVersion.current() >= GradleVersion.version('8.0')) {
archiveClassifier = 'javadoc'
destinationDirectory = new File("${libDir}")
} else {
classifier = 'javadoc'
destinationDir = new File("${libDir}")
}
archiveClassifier = 'javadoc'
destinationDirectory = new File("${libDir}")
}

// The maven plugin change in Gradle 7.3, for compatibility with older gradle versions
// we split maven related tasks to separate files that use the corresponding builtin gradle
// plug-ins
project.ext.pomName = "${libDir}/${project.name}-${project.version}.pom"
if(GradleVersion.current() >= GradleVersion.version('7.3')) {
apply from: "$project.ext.topSrcDir/java/gradle/maven-publish.publishing.gradle"
} else {
apply from: "$project.ext.topSrcDir/java/gradle/maven.publishing.gradle"
}
apply from: "$project.ext.topSrcDir/java/gradle/maven-publish.publishing.gradle"

assemble.dependsOn(jarSources, javadocJar)

Expand All @@ -76,14 +54,6 @@ if(project.name == "icebox") {
}
}

if(project.name == "icebox-compat") {
jar {
manifest {
attributes("Main-Class": "IceBox.Server")
}
}
}

clean {
delete("${libDir}/${project.name}-${project.version}.jar")
delete("${libDir}/${project.name}-${project.version}-sources.jar")
Expand Down
74 changes: 0 additions & 74 deletions java/gradle/maven.publishing.gradle

This file was deleted.

Binary file modified java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
14 changes: 9 additions & 5 deletions java/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -132,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down Expand Up @@ -196,6 +197,9 @@ if "$cygwin" || "$msys" ; then
done
fi

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
3 changes: 2 additions & 1 deletion java/src/Ice/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ javadoc.dependsOn(compileJava)

javadoc {
classpath = project.sourceSets.main.output
excludes = ["**/IceInternal/*.java", "**/IceUtilInternal/*.java", "**/Ice/*I.java"]
// TODO: excluding this files results in errors when building the docs.
// excludes = ["**/IceInternal/*.java", "**/IceUtilInternal/*.java", "**/Ice/*I.java"]
}
Loading

0 comments on commit 1aac6ec

Please sign in to comment.