maxkomarychev / react-native-ultimate-config

Config that works
MIT License
262 stars 31 forks source link

Update build.gradle to support Gradle 7+ #79

Closed samermurad closed 2 years ago

samermurad commented 2 years ago

Except the installArchives task, which I really don't know how to handle, these values work; the plugin part is a pretty simple change. I don't know how to fix the publication part though, I could try to fix it if you give me a general direction on where to look..

tehong commented 2 years ago

@maxkomarychev Is it possible for you to take a look at this PR and the question posted? It seems that this repo needs this fix for the Gradle 7+.

ThomasGoatITMedia commented 2 years ago

Any idea when this will be merged in/released? I've tested this update and all seems to work fine.

AndrewShapovalov commented 2 years ago

@maxkomarychev could you review and merge it please?

tr3v3r commented 2 years ago

@maxkomarychev same here! Could please review and merge?)

ThomasGoatITMedia commented 2 years ago

I've improved on this PR in a patch with patch-package, this fixes the issue with publication to maven

// android/build.gradle

// based on:
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
//   original location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
//
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
//   original location:
//   - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle

def DEFAULT_COMPILE_SDK_VERSION = 30
def DEFAULT_BUILD_TOOLS_VERSION = '30.0.2'
def DEFAULT_MIN_SDK_VERSION = 21
def DEFAULT_TARGET_SDK_VERSION = 30

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

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

buildscript {
    // The Android Gradle plugin is only required when opening the android folder stand-alone.
    // This avoids unnecessary downloads and potential conflicts when the library is included as a
    // module dependency in an application project.
    // ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
    if (project == rootProject) {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.2.2'
        }
    }
}

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

android {
    compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
    buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
        targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    // ref: https://www.baeldung.com/maven-local-repository
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        // Android JSC is installed from npm
        url "$rootDir/../node_modules/jsc-android/dist"
    }
    google()
    jcenter()
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
}

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)
        project.getConfigurations().implementation.setCanBeResolved(true)
        classpath += files(project.getConfigurations().getByName('implementation').asList())
        include '**/*.java'
    }

    task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
        classifier = 'javadoc'
        from androidJavadoc.destinationDir
    }

    task androidSourcesJar(type: Jar) {
        classifier = 'sources'
        from android.sourceSets.main.java.srcDirs
        include '**/*.java'
    }

    android.libraryVariants.all { variant ->
        def name = variant.name.capitalize()
        def javaCompileTask = variant.javaCompileProvider.get()

        task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
            from javaCompileTask.destinationDir
        }
    }

    artifacts {
        archives androidSourcesJar
        archives androidJavadocJar
    }

    task installArchives(type: Upload) {
        configuration = configurations.archives
        def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)

        publishing {
            publications {
                mavenJava(MavenPublication) {
                    artifactId = packageJson.name
                    groupId = "com.reactnativeultimateconfig"
                    version = packageJson.version

                    pom {
                        name = packageJson.title
                        description = packageJson.description
                        url = packageJson.repository.baseUrl

                        licenses {
                            license {
                                name = packageJson.license
                                url = packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
                                distribution = 'repo'
                            }
                        }

                        developers {
                            developer {
                                id = packageJson.author.username
                                name = packageJson.author.name
                            }
                        }
                    }

                }
            }
            repositories {
                maven {
                    url = "file://${projectDir}/../android/maven"
                }
            }
        }
    }
}
tr3v3r commented 2 years ago

@ThomasGoatITMedia could you please send the normal file you've updated without DIFF markers?

ThomasGoatITMedia commented 2 years ago

@tr3v3r I've updated my comment

maxkomarychev commented 2 years ago

folks I still have no capacity to test or work on this. I am assuming this has been tested by a community. I will issue version 4 shortly. thank you for contribution!