From 883231ec8be26b9b118db5a2df3651cff840d322 Mon Sep 17 00:00:00 2001 From: pradeepbn Date: Fri, 8 Oct 2021 09:58:06 -0700 Subject: [PATCH] Building bookkeeper with gradle on java11 Descriptions of the changes in this PR: ### Motivation This change enable gradle to build on java11 ### Changes - generateJniHeaders for CpuAffinity using native gradle config rather than using javac rather than specifying it via command line in gradle - Update gradle dependencies that helps build java11 - Update checkstyle to use native configurations from gradle Master Issue: #2640 Reviewers: Prashant Kumar , Henry Saputra , Matteo Merli This closes #2817 from pradeepbn/java11 and squashes the following commits: 95c19de0d [pradeepbn] Merge pull request #1 from mauricebarnum/pr-2817-jni 049a510b9 [maurice barnum] use compileJava task to generate jni headers f690e90e4 [Pradeep Nagaraju] Replace javac to use gradle native config 9285c10a0 [Pradeep Nagaraju] Revert the changes to avoid deprecation of finalize() 22c3cfd5a [Pradeep Nagaraju] remove unwanted changes b41605931 [Pradeep Nagaraju] - Building bookkeeper with gradle on java11 - Use gradle native solution for using javac rather than specifying it via command line in gradle --- build.gradle | 1 + .../src/main/resources/bookkeeper/checkstyle.xml | 2 +- circe-checksum/build.gradle | 10 ++-------- circe-checksum/src/main/circe/build.gradle | 4 ++-- cpu-affinity/build.gradle | 16 ++++++---------- cpu-affinity/src/main/affinity/build.gradle | 4 ++-- dependencies.gradle | 2 ++ stream/distributedlog/core/build.gradle | 1 + stream/proto/build.gradle | 1 + stream/server/build.gradle | 1 + stream/tests-common/build.gradle | 1 + 11 files changed, 20 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 6bb45a614e9..6373c77877b 100644 --- a/build.gradle +++ b/build.gradle @@ -73,6 +73,7 @@ allprojects { checkstyle { toolVersion "${checkStyleVersion}" configFile file("$rootDir/buildtools/src/main/resources/bookkeeper/checkstyle.xml") + configDirectory = file("$rootDir/buildtools/src/main/resources/bookkeeper") checkstyleMain { source ='src/main/java' } diff --git a/buildtools/src/main/resources/bookkeeper/checkstyle.xml b/buildtools/src/main/resources/bookkeeper/checkstyle.xml index b79bfdd3f24..fda4fb619d6 100644 --- a/buildtools/src/main/resources/bookkeeper/checkstyle.xml +++ b/buildtools/src/main/resources/bookkeeper/checkstyle.xml @@ -60,7 +60,7 @@ page at http://checkstyle.sourceforge.net/config.html --> - + diff --git a/circe-checksum/build.gradle b/circe-checksum/build.gradle index 17258fee0b2..5e03ec9324e 100644 --- a/circe-checksum/build.gradle +++ b/circe-checksum/build.gradle @@ -28,14 +28,8 @@ dependencies { testImplementation depLibs.mockito } -task generateJniHeaders(type:Exec) { - ext { - javahOutputDir = "$buildDir/javahGenerated" - } - dependsOn classes - def classpath = sourceSets.main.output.classesDirs.join(":") - commandLine("javah", "-d", javahOutputDir, "-classpath", - classpath, "com.scurrilous.circe.crc.Sse42Crc32C") +compileJava { + options.headerOutputDirectory = file("${buildDir}/javahGenerated") } jar { diff --git a/circe-checksum/src/main/circe/build.gradle b/circe-checksum/src/main/circe/build.gradle index 5b49ba82885..0a35c874aab 100644 --- a/circe-checksum/src/main/circe/build.gradle +++ b/circe-checksum/src/main/circe/build.gradle @@ -27,9 +27,9 @@ library { binaries.configureEach { CppBinary binary -> def compileTask = binary.compileTask.get() - compileTask.dependsOn project(':circe-checksum').generateJniHeaders + compileTask.dependsOn project(':circe-checksum').compileJava compileTask.includes.from("${Jvm.current().javaHome}/include", - project(':circe-checksum').generateJniHeaders.javahOutputDir) + project(':circe-checksum').compileJava.options.headerOutputDirectory) def osFamily = binary.targetPlatform.targetMachine.operatingSystemFamily diff --git a/cpu-affinity/build.gradle b/cpu-affinity/build.gradle index 981fd6df381..750f7a2802d 100644 --- a/cpu-affinity/build.gradle +++ b/cpu-affinity/build.gradle @@ -16,29 +16,25 @@ * specific language governing permissions and limitations * under the License. */ + plugins { id 'java' } dependencies { - compileOnly depLibs.lombok compileOnly depLibs.spotbugsAnnotations implementation depLibs.commonsLang3 implementation depLibs.guava implementation depLibs.slf4j testImplementation depLibs.junit - + compileOnly depLibs.lombok annotationProcessor depLibs.lombok + testCompileOnly depLibs.lombok + testAnnotationProcessor depLibs.lombok } -task generateJniHeaders(type:Exec) { - ext { - javahOutputDir = "$buildDir/javahGenerated" - } - dependsOn classes - def classpath = sourceSets.main.output.classesDirs.join(":") - commandLine("javah", "-d", javahOutputDir, "-classpath", - classpath, "org.apache.bookkeeper.common.util.affinity.impl.CpuAffinityJni") +compileJava { + options.headerOutputDirectory = file("${buildDir}/javahGenerated") } jar { diff --git a/cpu-affinity/src/main/affinity/build.gradle b/cpu-affinity/src/main/affinity/build.gradle index 2e444234fad..49868c0c515 100644 --- a/cpu-affinity/src/main/affinity/build.gradle +++ b/cpu-affinity/src/main/affinity/build.gradle @@ -25,9 +25,9 @@ plugins { library { binaries.configureEach { CppBinary binary -> def compileTask = binary.compileTask.get() - compileTask.dependsOn project(':cpu-affinity').generateJniHeaders + compileTask.dependsOn project(':cpu-affinity').compileJava compileTask.includes.from("${Jvm.current().javaHome}/include", - project(':cpu-affinity').generateJniHeaders.javahOutputDir) + project(':cpu-affinity').compileJava.options.headerOutputDirectory) def osFamily = binary.targetPlatform.targetMachine.operatingSystemFamily diff --git a/dependencies.gradle b/dependencies.gradle index 1f34a813a74..aee92d74d72 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -48,6 +48,7 @@ depVersions = [ hdrhistogram: "2.1.4", httpclient: "4.5.13", jackson: "2.11.1", + javaAnnotations:"1.3.2", jcommander: "1.78", jctools: "2.1.2", jetty: "9.4.31.v20200723", @@ -111,6 +112,7 @@ depLibs = [ hamcrest: "org.hamcrest:hamcrest-all:${depVersions.hamcrest}", httpclient: "org.apache.httpcomponents:httpclient:${depVersions.httpclient}", jacksonAnnotations: "com.fasterxml.jackson.core:jackson-annotations:${depVersions.jackson}", + javaAnnotations: "javax.annotation:javax.annotation-api:${depVersions.javaAnnotations}", jacksonCore: "com.fasterxml.jackson.core:jackson-core:${depVersions.jackson}", jacksonDatabind: "com.fasterxml.jackson.core:jackson-databind:${depVersions.jackson}", jcommander: "com.beust:jcommander:${depVersions.jcommander}", diff --git a/stream/distributedlog/core/build.gradle b/stream/distributedlog/core/build.gradle index e4a65eacbef..ca739376dec 100644 --- a/stream/distributedlog/core/build.gradle +++ b/stream/distributedlog/core/build.gradle @@ -49,6 +49,7 @@ dependencies { testImplementation project(path: ':stream:distributedlog:common', configuration: 'testArtifacts') testImplementation depLibs.junit testImplementation depLibs.mockito + implementation depLibs.javaAnnotations annotationProcessor depLibs.lombok testAnnotationProcessor depLibs.lombok diff --git a/stream/proto/build.gradle b/stream/proto/build.gradle index cd90529e2b7..cc27288f437 100644 --- a/stream/proto/build.gradle +++ b/stream/proto/build.gradle @@ -25,6 +25,7 @@ dependencies { implementation depLibs.lombok implementation depLibs.grpc implementation depLibs.commonsLang3 + implementation depLibs.javaAnnotations annotationProcessor depLibs.lombok } diff --git a/stream/server/build.gradle b/stream/server/build.gradle index 08f2403ac4e..7eb3510848e 100644 --- a/stream/server/build.gradle +++ b/stream/server/build.gradle @@ -55,6 +55,7 @@ dependencies { runtimeOnly depLibs.vertxCore runtimeOnly depLibs.vertxWeb testImplementation depLibs.mockito + implementation depLibs.javaAnnotations annotationProcessor depLibs.lombok } diff --git a/stream/tests-common/build.gradle b/stream/tests-common/build.gradle index f3c33c78c56..5259cd6e0e9 100644 --- a/stream/tests-common/build.gradle +++ b/stream/tests-common/build.gradle @@ -26,6 +26,7 @@ dependencies { implementation depLibs.slf4j annotationProcessor depLibs.lombok + implementation depLibs.javaAnnotations } protobuf {