{"id":21096907,"url":"https://github.com/klarna/gradle-react-native","last_synced_at":"2025-05-05T17:07:16.007Z","repository":{"id":38942418,"uuid":"209487998","full_name":"klarna/gradle-react-native","owner":"klarna","description":"Gradle Plugin for Building React Native projects","archived":false,"fork":false,"pushed_at":"2023-02-28T01:50:45.000Z","size":1396,"stargazers_count":3,"open_issues_count":19,"forks_count":2,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-30T22:32:22.056Z","etag":null,"topics":["android","gradle","gradle-android-plugin","gradle-plugin","kotlin","kotlin-dsl","react-native"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/klarna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-19T07:18:29.000Z","updated_at":"2024-12-29T18:45:14.000Z","dependencies_parsed_at":"2024-11-19T22:54:47.132Z","dependency_job_id":null,"html_url":"https://github.com/klarna/gradle-react-native","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna%2Fgradle-react-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna%2Fgradle-react-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna%2Fgradle-react-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klarna%2Fgradle-react-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klarna","download_url":"https://codeload.github.com/klarna/gradle-react-native/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252542065,"owners_count":21764907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","gradle","gradle-android-plugin","gradle-plugin","kotlin","kotlin-dsl","react-native"],"created_at":"2024-11-19T22:44:37.908Z","updated_at":"2025-05-05T17:07:15.952Z","avatar_url":"https://github.com/klarna.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradle React Native Plugin\n\n[![CircleCI](https://circleci.com/gh/klarna/gradle-react-native.svg?style=svg)](https://circleci.com/gh/klarna/gradle-react-native)\n[![codecov](https://codecov.io/gh/klarna/gradle-react-native/branch/master/graph/badge.svg)](https://codecov.io/gh/klarna/gradle-react-native)\n[![gradlePluginPortal](https://img.shields.io/maven-metadata/v?label=plugin\u0026metadataUrl=https%3A%2F%2Fplugins.gradle.org%2Fm2%2Fcom%2Fklarna%2Fgradle%2Freactnative%2Fcom.klarna.gradle.reactnative.gradle.plugin%2Fmaven-metadata.xml)](https://plugins.gradle.org/plugin/com.klarna.gradle.reactnative) ![GitHub](https://img.shields.io/github/license/klarna/gradle-react-native)\n\n- [Gradle React Native Plugin](#gradle-react-native-plugin)\n  - [Setup](#setup)\n  - [Usage](#usage)\n    - [Minimalistic](#minimalistic)\n    - [Extended](#extended)\n    - [Compatibility](#compatibility)\n  - [Contribute](#contribute)\n    - [Enable Git Hooks](#enable-git-hooks)\n    - [Publishing](#publishing)\n      - [Why Not A Standard Approach](#why-not-a-standard-approach)\n    - [Run CircleCI locally](#run-circleci-locally)\n    - [Snapshots development](#snapshots-development)\n  - [References](#references)\n  - [Legal](#legal)\n\n## Setup\n\nGradle's [kotlin-dsl][kotlin_dsl]:\n\n```groovy\n// build.gradle.kts\nplugins {\n    id \"com.klarna.gradle.reactnative\" version \"$version\" apply false\n}\n```\n\n```groovy\n// project build.gradle.kts\nplugins {\n    id(\"com.android.application\")\n    id(\"com.klarna.gradle.reactnative\")\n}\n```\n\nOr via the `buildscript` block:\n\n```groovy\n// rootProject build.gradle\nbuildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath \"com.klarna.gradle.reactnative:plugin:$version\"\n    }\n}\n```\n\n```groovy\n// project build.gradle\napply plugin: \"com.android.application\"\napply plugin: \"com.klarna.gradle.reactnative\"\n```\n\n## Usage\n\n### Minimalistic\n\n```groovy\n// project build.gradle\napply plugin: \"com.android.application\"\napply plugin: \"com.klarna.gradle.reactnative\"\n```\n\nAfter applying plugin all tasks will be created automatically and attached to the build graph.\n\n### Extended\n\n```groovy\n// project build.gradle\napply plugin: \"com.android.application\"\napply plugin: \"com.klarna.gradle.reactnative\"\n\n/* https://developer.android.com/studio/build/index.html */\nandroid {\n    /* ... Configuration of the Android app ... */\n}\n\nreact {\n    /* declare custom configuration options for each build type */\n    buildTypes {\n        debug {\n            /* ... */\n        }\n        release {\n            /* ... */\n        }\n        /* ... more build types ... */\n    }\n    \n    /* declare custom configuration options for each flavor */\n    productFlavors {\n        local {\n            /* ... */\n        }\n        /* ... more flavors ... */\n    }\n    \n    /* Reconfigure `android.packagingOptions{...}` for supporting well JSC integration. */\n    applyJscPackagingOptions()\n}\n```\n\nBuild types and Flavors are corresponding the Android Build Plugin - [android_build_variants]\n\n### Compatibility\n\nOur plugin is designed for replacing the old React Native `react.gradle` code by properly maintained and heavily tested code. Just for that purpose everything in plugin configuration is backward compatible with old approaches.\n\nWe are targeting to replace RN 0.61 [build scripts](https://github.com/facebook/react-native/blob/0.61-stable/react.gradle).\n\nThose lines of code below are equal:\n\n```groovy\nproject.ext.react = [\n    entryFile   : \"index.js\",\n    enableHermes: false,  // clean and rebuild if changing\n]\n\n// replaced by\n\nreact {\n    entryFile = \"index.js\"\n    enableHermes = false\n}\n``` \n\nWhen you use the plugin DSL for configuration, plugin will take care for reflecting \nany defined configuration in `project.ext.react` array/collection. In other words you \ncan combine old and approach and current plugin in one project at the same time.\n\nThe biggest advantage of the plugin that all the variables definitions are type \nsafe and validated in the moment of gradle script running/editing (depends on IDE you use).  \n\n\n## Contribute\n\n### Enable Git Hooks\n\nIn the root folder of the project you can find folder `.githooks` inside it you can find pre-configured hooks.\nTo enable them just copy all files from `.githooks` to `.git/hooks`.\n\nOR which is a bette approach create a symbolic links to hooks:\n\n```bash\ncd .git/hooks\n# drop all old hooks\nrm *\n# create all symbolic links\nfind ../../.githooks -type f -exec basename {} \\; | xargs -I {} ln -s ../../.githooks/{} {}\n```\n\n### Publishing\n\nDo login:\n\n```bash\n./gradlew login\n```\n\nOutput:\n\n```text\n# Task ':login' is not up-to-date because:\n#  Task has not declared any outputs despite executing actions.\n#\n# To add your publishing API keys to /usr/local/opt/gradle/gradle.properties, open the following URL in your browser:\n#\n#   https://plugins.gradle.org/api/v1/login/auth/{token}\n#\n# Your publishing API keys have been written to: $GRADLE_USER_HOME/gradle.properties\n```\n\nCopy `gradle.publish.key` and `gradle.publish.secret` keys:\n\n```bash\ncat $GRADLE_HOME/gradle.properties\n```\n\n```text\n#Updated secret and key with server message: Using key 'C02WW29ZHTDD' for OlKu\n#Thu, 26 Sep 2019 09:41:39 +0200\ngradle.publish.key={secret}\ngradle.publish.secret={secret2}\n```\n\nCreate file in root of the project `credentials.properties` and place those keys into it.\n\n```bash\n# increase version MINOR part, switch to RELEASE from any (alpha, beta, rc) and force tag apply\ngradle/version-up.sh --minor --release --apply\n\n# take version from properties file\nexport VER=$(cat version.properties | grep snapshot.version | cut -d'=' -f2)\n\n# switch to release TAG as a branch\ngit checkout -b $VER $VER\n\n# force full rebuild\n./gradlew clean build assembleRelease -Pversion=$VER\n\n# now we can publish the version\n./gradlew publishPlugins -Pversion=$VER\n```\n\n#### Why Not A Standard Approach\n\nas a developer I work with multiple projects, companies, repositories.\nMain rule for me is to keep projects as much as possible isolated from local environment of the laptop.\nThat is why `credentials.properties` approach used - isolate project from global system settings.\n\nReferences:\n\n- [publishing overview](https://docs.gradle.org/current/userguide/publishing_overview.html)\n- [gradle plugin portal](https://guides.gradle.org/publishing-plugins-to-gradle-plugin-portal/)\n\n### Run CircleCI locally\n\nbased on: \u003chttps://circleci.com/docs/2.0/local-cli/\u003e\n\n```bash\nbrew install circleci\n\n# validate config\ncircleci config validate\n\n# run specific job\ncircleci local execute --job [dependencies|debug|release|test|lint|deploy] -e VAR1=FOO\n\n## run tests 1/4 - specifically second slice: 2\ncircleci local execute --job test -e TEST_START=2 -e TEST_TOTAL=4\n\n# cleanup\nbrew uninstall circleci\n```\n\n### Snapshots development\n\nIf you want to use the latest development SNAPSHOT version on a regular basis, you will need to also need to add the following to the `buildscript` block to ensure Gradle checks more frequently for updates:\n\n```groovy\nbuildscript {\n  // ...\n  /* Since the files in the repository change with each build, we need to recheck for changes */\n  configurations.all {\n    resolutionStrategy {\n      cacheChangingModulesFor 0, 'seconds'\n      cacheDynamicVersionsFor 0, 'seconds'\n    }\n  }\n}\n\n// `-SNAPSHOT` suffix automatically recognized as `changing` dependency\ndependencies {\n    compile group: \"groupId\", name: \"artifactId\", version: \"1+\", changing: true\n    compile group: \"groupId\", name: \"artifactId\", version: \"1.0-SNAPSHOT\"\n}\n```\n\nReferences:\n\n- [Resolution Strategy](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html)\n- [Snapshots configuration](https://stackoverflow.com/questions/42058626/how-to-get-newest-snapshot-of-a-dependency-without-changing-version-in-gradle?rq=1)\n- [other plugin](https://github.com/bndtools/bnd/blob/master/biz.aQute.bnd.gradle/README.md#using-the-latest-development-snapshot-build-of-the-bnd-gradle-plugins)\n\n## References\n\n- \u003chttps://www.klg71.de/post/kotlin_gradle_plugin/\u003e\n- \u003chttps://github.com/FRI-DAY/elasticmq-gradle-plugin\u003e\n\n## Legal\n\nThis project is available under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0.html).\n\nCopyright 2013-2019 Klarna AB.\n\n[kotlin_dsl]: https://github.com/gradle/kotlin-dsl\n[android_build_variants]: https://developer.android.com/studio/build/build-variants\n[plugin]: https://plugins.gradle.org/plugin/com.klarna.gradle.reactnative\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklarna%2Fgradle-react-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklarna%2Fgradle-react-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklarna%2Fgradle-react-native/lists"}