THRIFT-5581: use gradle 7 for java/kotlin (#2601)
* upgrade gradle version to 7.4
* migrate from `maven` plugin to `maven-publish` plugin as required for Gradle 7
* add guard to ktfmt, since it can't run with JDK 8
Co-authored-by: Christopher Tubbs <ctubbsii@apache.org>
diff --git a/lib/java/gradle/publishing.gradle b/lib/java/gradle/publishing.gradle
index 7be7de4..91f456a 100644
--- a/lib/java/gradle/publishing.gradle
+++ b/lib/java/gradle/publishing.gradle
@@ -27,7 +27,7 @@
destinationDir = file(installPath)
from jar
- from configurations.compile
+ from configurations.implementation
}
task installJavadoc(type: Copy, group: 'Install', dependsOn: javadoc) {
@@ -38,84 +38,66 @@
from javadoc.destinationDir
}
-// This is not needed by Gradle builds but the remaining Ant builds seem to
-// need access to the generated test classes for Thrift unit tests so we
-// assist them to use it this way.
-task copyDependencies(type: Copy, group: 'Build') {
- description = 'Copy runtime dependencies in a common location for other Ant based projects'
- project.assemble.dependsOn it
-
- destinationDir = file("$buildDir/deps")
- from configurations.testRuntime
- // exclude some very specific unit test dependencies
- exclude '**/junit*.jar', '**/mockito*.jar', '**/hamcrest*.jar'
+java {
+ withJavadocJar()
+ withSourcesJar()
}
-// ----------------------------------------------------------------------------
-// Allow this configuration to be shared between install and uploadArchives tasks
-def configurePom(pom) {
- pom.project {
- name 'Apache Thrift'
- description 'Thrift is a software framework for scalable cross-language services development.'
- packaging 'jar'
- url 'http://thrift.apache.org'
-
- scm {
- url 'https://github.com/apache/thrift'
- connection 'scm:git:https://github.com/apache/thrift.git'
- developerConnection 'scm:git:git@github.com:apache/thrift.git'
- }
-
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url "${project.license}"
- distribution 'repo'
- }
- }
-
- developers {
- developer {
- id 'dev'
- name 'Apache Thrift Developers'
- email 'dev@thrift.apache.org'
+publishing {
+ publications {
+ mavenJava(MavenPublication) {
+ artifactId = "libthrift"
+ // explicitly set 3 jars because calling "from components.java" will include shadow jar which isn't what we want
+ artifact jar
+ artifact sourcesJar
+ artifact javadocJar
+ pom {
+ name = 'Apache Thrift'
+ description = 'Thrift is a software framework for scalable cross-language services development.'
+ url = 'http://thrift.apache.org'
+ licenses {
+ license {
+ name = 'The Apache Software License, Version 2.0'
+ url = "${project.license}"
+ distribution = 'repo'
+ }
+ }
+ developers {
+ developer {
+ id = 'dev'
+ name = 'Apache Thrift Developers'
+ email = 'dev@thrift.apache.org'
+ }
+ }
+ scm {
+ url = 'https://github.com/apache/thrift'
+ connection = 'scm:git:https://github.com/apache/thrift.git'
+ developerConnection = 'scm:git:git@github.com:apache/thrift.git'
+ }
}
}
}
-
- pom.whenConfigured {
- // Fixup the scope for servlet-api to be 'provided' instead of 'compile'
- dependencies.find { dep -> dep.groupId == 'javax.servlet' && dep.artifactId == 'javax.servlet-api' }.with {
- if(it != null) {
- // it.optional = true
- it.scope = 'provided'
+ repositories {
+ maven {
+ url = mavenRepositoryUrl
+ if (project.hasProperty("mavenUser") && project.hasProperty("mavenPassword")) {
+ credentials {
+ username = mavenUser
+ password = mavenPassword
+ }
}
}
}
}
-install {
- repositories.mavenInstaller {
- configurePom(pom)
- }
-}
-
-uploadArchives {
- dependsOn test // make sure we run unit tests when publishing
- repositories.mavenDeployer {
- // signPom will silently do nothing when no signing information is provided
- beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
- repository(url: project.mavenRepositoryUrl) {
- if (project.hasProperty('mavenUser') && project.hasProperty('mavenPassword')) {
- authentication(userName: mavenUser, password: mavenPassword)
- }
- }
- configurePom(pom)
- }
-}
-
-// Signing configuration, optional, only when release and uploadArchives is activated
+// Signing configuration, optional, only when release and publish is activated
signing {
- required { !version.endsWith("SNAPSHOT") && gradle.taskGraph.hasTask("uploadArchives") }
- sign configurations.archives
+ required { !version.endsWith("SNAPSHOT") && gradle.taskGraph.hasTask("publish") }
+ sign publishing.publications.mavenJava
+}
+
+javadoc {
+ if(JavaVersion.current().isJava9Compatible()) {
+ options.addBooleanOption('html5', true)
+ }
}