shakebugs / shake-react-native

Bug reporting SDK for React Native apps.
https://shakebugs.com
11 stars 1 forks source link

[BUG] Use maven-publish to support React Native 0.67 > 0.68 #1

Closed Derewith closed 2 years ago

Derewith commented 2 years ago

Description

The maven plugin has been deprecated since gradle 6.0 and was removed in gradle 7.0.

React Native 0.68.0 uses gradle 7.3.3

Upgrade the library to use maven-publish so it works with gradle 7.X and React Native 0.67 / 0.68

Test code and steps to reproduce

Install the library in a project that has "react-native": "0.67.0" or major version

Example Reference

https://github.com/software-mansion/react-native-reanimated/pull/2881/files

Patch-package

I've made a patch that you can use if you need to use the library. ( I know it's not perfect but it works )

diff --git a/node_modules/@shakebugs/react-native-shake/android/build.gradle b/node_modules/@shakebugs/react-native-shake/android/build.gradle
index d3a8ea1..fd3e6af 100644
--- a/node_modules/@shakebugs/react-native-shake/android/build.gradle
+++ b/node_modules/@shakebugs/react-native-shake/android/build.gradle
@@ -22,7 +22,7 @@ def safeExtGet(prop, fallback) {
 }

 apply plugin: 'com.android.library'
-apply plugin: 'maven'
+apply plugin: 'maven-publish'

 buildscript {
     // The Android Gradle plugin is only required when opening the android folder stand-alone.
@@ -45,9 +45,6 @@ rootProject.allprojects {
     }
 }

-apply plugin: 'com.android.library'
-apply plugin: 'maven'
-
 android {
     compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
     buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
@@ -55,7 +52,7 @@ android {
         minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
         targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
         versionCode 1
-        versionName "1.0"
+        versionName '1.0'
     }
     lintOptions {
         abortOnError false
@@ -79,7 +76,7 @@ repositories {
 dependencies {
     //noinspection GradleDynamicVersion
     implementation 'com.facebook.react:react-native:+'  // From node_modules
-    api "com.shakebugs:shake:15.0.+"
+    api 'com.shakebugs:shake:15.0.+'
 }

 def configureReactNativePom(def pom) {
@@ -88,7 +85,7 @@ def configureReactNativePom(def pom) {
         name packageJson.title
         artifactId packageJson.name
         version = packageJson.version
-        group = "com.shakebugs.react"
+        group = 'com.shakebugs.react'
         description packageJson.description
         url packageJson.repository.baseUrl

@@ -112,20 +109,20 @@ def configureReactNativePom(def pom) {
 afterEvaluate { project ->
     // some Gradle build hooks ref:
     // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
-    task androidJavadoc(type: Javadoc) {
-        source = android.sourceSets.main.java.srcDirs
-        classpath += files(android.bootClasspath)
-        classpath += files(project.getConfigurations().getByName('compile').asList())
-        include '**/*.java'
-    }
-
-    task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
-        classifier = 'javadoc'
-        from androidJavadoc.destinationDir
-    }
+    // task androidJavadoc(type: Javadoc) {
+    //     source = android.sourceSets.main.java.srcDirs
+    //     classpath += files(android.bootClasspath)
+    //     classpath += files(project.getConfigurations().getByName('compile').asList())
+    //     include '**/*.java'
+    // }
+
+    // task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
+    //     archiveClassifier = 'javadoc'
+    //     from androidJavadoc.destinationDir
+    // }

     task androidSourcesJar(type: Jar) {
-        classifier = 'sources'
+        archiveClassifier = 'sources'
         from android.sourceSets.main.java.srcDirs
         include '**/*.java'
     }
@@ -141,15 +138,22 @@ afterEvaluate { project ->

     artifacts {
         archives androidSourcesJar
-        archives androidJavadocJar
+    // archives androidJavadocJar
     }

     task installArchives(type: Upload) {
-        configuration = configurations.archives
-        repositories.mavenDeployer {
-            // Deploy to react-native-event-bridge/maven, ready to publish to npm
-            repository url: "file://${projectDir}/../android/maven"
-            configureReactNativePom pom
+        publishing {
+            publications {
+                maven(MavenPublication) {
+                    artifact androidSourcesJar
+                }
+            }
         }
+    // configuration = configurations.archives
+    // repositories.mavenDeployer {
+    //     // Deploy to react-native-event-bridge/maven, ready to publish to npm
+    //     repository url: "file://${projectDir}/../android/maven"
+    //     configureReactNativePom pom
+    // }
     }
 }
mstanic-shake commented 2 years ago

Hi @Derewith , sorry for the late answer. We have released 15.2 version of RN SDK, Gradle 7 should be supported now. If it still doesn't works for you please open a new issue.