From f335afc8876c642d9c15d0ddfb8fecf02c771f02 Mon Sep 17 00:00:00 2001 From: Eli Hart Date: Tue, 4 Apr 2023 09:23:23 -0700 Subject: [PATCH] Update kotlin and ksp (#357) * Bump kotlin and ksp to 1.7.20 * clean up publishing configuration and docs * update to kotlin 1.8.10 * Prepare for release 6.2.1 * remove MaxPermSize * Prepare next development version. * Fix wording --- RELEASING.md | 39 ++++++++++++++----- build.gradle | 1 + deeplinkdispatch-base/build.gradle | 2 +- deeplinkdispatch-processor/build.gradle | 2 +- .../airbnb/deeplinkdispatch/BaseProcessor.kt | 4 +- .../deeplinkdispatch/DeepLinkProcessor.kt | 22 ++++++++--- ...ProcessorDeepLinkHandlerIncrementalTest.kt | 2 +- deeplinkdispatch/build.gradle | 2 +- dependencies.gradle | 17 ++++---- gradle.properties | 11 ++++-- gradle/wrapper/gradle-wrapper.properties | 2 +- publishing.gradle | 29 ++++++++++++++ 12 files changed, 97 insertions(+), 36 deletions(-) create mode 100644 publishing.gradle diff --git a/RELEASING.md b/RELEASING.md index 51f72724..cdda4528 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,12 +1,31 @@ -Releasing +Publishing a new Main release to Maven ======== - 1. Change the version in `gradle.properties` to a non-SNAPSHOT version. - 4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) - 5. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version) - 6. `./gradlew clean assemble sourcesJar androidSourcesJar javadocsJar androidJavadocsJar uploadArchives --no-daemon --no-parallel` - 7. Update the `gradle.properties` to the next SNAPSHOT version. - 8. `git commit -am "Prepare next development version."` - 9. `git push && git push --tags` - 10. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. - 11. Go to https://github.com/airbnb/DeepLinkDispatch/releases and create the release (via pushed tag) \ No newline at end of file +1. Change the version in `gradle.properties` to a non-SNAPSHOT version based on Major.Minor.Patch naming scheme +2. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) +3. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version) +4. Add your sonatype login information under gradle properties mavenCentralUsername and mavenCentralPassword in your local user gradle.properties file +5. Make sure you have a gpg signing key configured (https://vanniktech.github.io/gradle-maven-publish-plugin/central/#secrets) +6. Run `./gradlew publishAllPublicationsToMavenCentral` to build the artifacts and publish them to maven +7. Update the `gradle.properties` to the next SNAPSHOT version. +8. `git commit -am "Prepare next development version."` +9. `git push && git push --tags` +10. Merge to master and create a new release through the Github web UI with release notes + +Publishing a release to an internal repository +======== + +To publish an internal release to an Artifactory repository: + +1. Set credential values for ARTIFACTORY_USERNAME and ARTIFACTORY_PASSWORD in your local gradle.properties +2. Set values for ARTIFACTORY_RELEASE_URL (and optionally ARTIFACTORY_SNAPSHOT_URL if you are publishing a snapshot) +3. /gradlew publishAllPublicationsToAirbnbArtifactoryRepository -PdoNotSignRelease=true +4. "-PdoNotSignRelease=true" is optional, but we don't need to sign artifactory releases and this allows everyone to publish without setting up a gpg key + +If you need to publish to a different repository, look at the configuration in 'publishing.gradle' +to see how to configure additional repositories. + +Maven Local Installation +======================= + +If testing changes locally, you can install to mavenLocal via `./gradlew publishToMavenLocal` diff --git a/build.gradle b/build.gradle index 1862c8ec..c010cd80 100644 --- a/build.gradle +++ b/build.gradle @@ -46,3 +46,4 @@ def getSnapshotRepositoryUrl() { return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : "https://oss.sonatype.org/content/repositories/snapshots/" } + diff --git a/deeplinkdispatch-base/build.gradle b/deeplinkdispatch-base/build.gradle index e594bd6c..f77d9780 100644 --- a/deeplinkdispatch-base/build.gradle +++ b/deeplinkdispatch-base/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'org.jmailen.kotlinter' sourceCompatibility = 11 apply plugin: 'checkstyle' -apply plugin: 'com.vanniktech.maven.publish' +apply from: '../publishing.gradle' dependencies { implementation deps.okio diff --git a/deeplinkdispatch-processor/build.gradle b/deeplinkdispatch-processor/build.gradle index 39405729..28afc25e 100644 --- a/deeplinkdispatch-processor/build.gradle +++ b/deeplinkdispatch-processor/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'org.jmailen.kotlinter' sourceCompatibility = 11 apply plugin: 'checkstyle' -apply plugin: 'com.vanniktech.maven.publish' +apply from: '../publishing.gradle' dependencies { implementation project(':deeplinkdispatch-base') diff --git a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/BaseProcessor.kt b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/BaseProcessor.kt index 5891b85c..6c8c7214 100644 --- a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/BaseProcessor.kt +++ b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/BaseProcessor.kt @@ -48,10 +48,8 @@ abstract class BaseProcessor(val symbolProcessorEnvironment: SymbolProcessorEnvi final override fun process(resolver: Resolver): List { val symbolProcessorEnvironment = requireNotNull(symbolProcessorEnvironment) environment = XProcessingEnv.create( - symbolProcessorEnvironment.options, + symbolProcessorEnvironment, resolver, - symbolProcessorEnvironment.codeGenerator, - symbolProcessorEnvironment.logger ) process(null, environment, XRoundEnv.create(environment)) return emptyList() diff --git a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.kt b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.kt index 3cc086df..c29bd5c2 100644 --- a/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.kt +++ b/deeplinkdispatch-processor/src/main/java/com/airbnb/deeplinkdispatch/DeepLinkProcessor.kt @@ -299,25 +299,35 @@ class DeepLinkProcessor(symbolProcessorEnvironment: SymbolProcessorEnvironment? private fun verifyHandlerMatchArgs(element: XTypeElement, uriTemplate: String) { // Find a method on our element that override the DeepLinkHandler interface method - val argsType = element.getAllMethods().singleOrNull { + val handlerMethod = element.getAllMethods().singleOrNull { it.overrides( other = handleDeepLinkInterfaceMethod, owner = element ) - }?.parameters?.last()?.type + } + // The interface method might be on a superclass, in which case its arguments might be generic. + // We want to make sure we're getting the concrete types of the final element. + ?.asMemberOf(element.type) ?: error("Is not overriding method from interface. This is impossible.") + val argsType = handlerMethod.parameterTypes.last() + val argsTypeElement = argsType.typeElement - if (argsTypeElement?.isPublic() == false) { + ?: throw DeepLinkProcessorException( + element = element, + errorMessage = "Could not extract type element from handler interface type. Found type ${argsType.typeName}" + ) + + if (!argsTypeElement.isPublic()) { throw DeepLinkProcessorException( element = argsTypeElement, errorMessage = "Argument class must be public." ) } - val argsConstructor = argsTypeElement?.getConstructors()?.singleOrNull() ?: run { + val argsConstructor = argsTypeElement.getConstructors().singleOrNull() ?: run { throw DeepLinkProcessorException( - element = argsTypeElement ?: element, - errorMessage = "Argument class can only have one constructor" + element = argsTypeElement, + errorMessage = "Argument class for deeplink handler can only have a single constructor" ) } val allArgParameters = argsConstructor.parameters diff --git a/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorDeepLinkHandlerIncrementalTest.kt b/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorDeepLinkHandlerIncrementalTest.kt index fbccae3e..ca42d439 100644 --- a/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorDeepLinkHandlerIncrementalTest.kt +++ b/deeplinkdispatch-processor/src/test/java/com/airbnb/deeplinkdispatch/DeepLinkProcessorDeepLinkHandlerIncrementalTest.kt @@ -926,7 +926,7 @@ class DeepLinkProcessorDeepLinkHandlerIncrementalTest : BaseDeepLinkProcessorTes ) assertCompileError( results, - "Argument class can only have one constructor" + "Argument class for deeplink handler can only have a single constructor" ) } diff --git a/deeplinkdispatch/build.gradle b/deeplinkdispatch/build.gradle index 813797bb..9009fdc5 100644 --- a/deeplinkdispatch/build.gradle +++ b/deeplinkdispatch/build.gradle @@ -5,7 +5,7 @@ sourceCompatibility = 11 apply plugin: 'checkstyle' apply plugin: 'kotlin-android' -apply plugin: 'com.vanniktech.maven.publish' +apply from: '../publishing.gradle' apply plugin: 'org.jmailen.kotlinter' dependencies { diff --git a/dependencies.gradle b/dependencies.gradle index 7b91bac6..b3bd029e 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,12 +1,12 @@ def versions = [ - kotlinVersion : '1.7.10', + kotlinVersion : '1.8.10', appCompatVersion : '1.4.1', localBroadcastManagerVersion : '1.1.0', - roboelectricVersion : '4.5.1', + roboelectricVersion : '4.9', benchmarkVersion : '1.0.0', - compileTestingVersion : '1.4.9', - kspVersion : '1.7.10-1.0.6', - xProcessorVersion : '2.5.0-alpha02', + compileTestingVersion : '1.5.0', + kspVersion : '1.8.10-1.0.9', + xProcessorVersion : '2.6.0-alpha01', mockkVersion : '1.12.3', ktlintGradlePluginVersion : '3.8.0', androidXTestingVersion : '1.4.0' @@ -14,7 +14,7 @@ def versions = [ ext.versions = versions ext.androidConfig = [ - agpVersion : '7.2.1', + agpVersion : '7.4.0', compileSdkVersion : 32, minSdkVersion : 16, targetSdkVersion : 30 @@ -30,9 +30,8 @@ ext.deps = [ jsr305 : 'com.google.code.findbugs:jsr305:3.0.2', okio : 'com.squareup.okio:okio:3.0.0', androidXAnnotations : 'androidx.annotation:annotation:1.3.0', - // Build and upload with: - // ./gradlew clean assemble sourcesJar androidSourcesJar javadocsJar androidJavadocsJar uploadArchives --no-daemon --no-parallel - gradleMavenPublishPlugin : 'com.vanniktech:gradle-maven-publish-plugin:0.14.2', + // https://vanniktech.github.io/gradle-maven-publish-plugin/ + gradleMavenPublishPlugin : 'com.vanniktech:gradle-maven-publish-plugin:0.22.0', dokkaPlugin : 'org.jetbrains.dokka:dokka-gradle-plugin:1.6.10', ksp : "com.google.devtools.ksp:symbol-processing-api:$versions.kspVersion", kspGradlePlugin : "com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:$versions.kspVersion", diff --git a/gradle.properties b/gradle.properties index ca46f962..e2e41091 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=6.2.0-SNAPSHOT +VERSION_NAME=6.3.0-SNAPSHOT GROUP=com.airbnb POM_URL=https://github.com/airbnb/deeplinkdispatch POM_SCM_URL=https://github.com/airbnb/deeplinkdispatch @@ -13,7 +13,12 @@ POM_DEVELOPER_NAME=Airbnb POM_DEVELOPER_EMAIL=android@airbnb.com org.gradle.daemon=false android.useAndroidX=true -android.enableJetifier=true -org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=1g +# With the default memory size Gradle gets out of memory issues when building, so we have to increase it +# Dokka fails without a larger metaspace https://github.com/Kotlin/dokka/issues/1405 +org.gradle.jvmargs=-Xms128m -Xmx3g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=1g # See https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md android.enableR8.fullMode=true + +# Publishing configuration for vanniktech/gradle-maven-publish-plugin +SONATYPE_HOST=DEFAULT +SONATYPE_AUTOMATIC_RELEASE=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15b1606a..3cc65417 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/publishing.gradle b/publishing.gradle new file mode 100644 index 00000000..325bd99a --- /dev/null +++ b/publishing.gradle @@ -0,0 +1,29 @@ +// Sets up publishing of release artifacts. +// Note: Keep this script in sync across all airbnb open source projects. +apply plugin: 'com.vanniktech.maven.publish' + + +// https://vanniktech.github.io/gradle-maven-publish-plugin/other/ +publishing { + repositories { + maven { + // The "name" value creates a task like `publishAllPublicationsTo[Name]Repository + // In this case, publishAllPublicationsToAirbnbArtifactoryRepository + name = 'airbnbArtifactory' + url = version.toString().endsWith("SNAPSHOT") ? findProperty("ARTIFACTORY_SNAPSHOT_URL") : findProperty("ARTIFACTORY_RELEASE_URL") + credentials { + username = getProperty("ARTIFACTORY_USERNAME") + password = getProperty("ARTIFACTORY_PASSWORD") + } + } + } +} + +mavenPublishing { + if (findProperty("doNotSignRelease").toString().toBoolean()) { + println("Skipping release signing") + } else { + println("Signing release with gpg") + signAllPublications() + } +} \ No newline at end of file