diff --git a/.changeset/bgp-exclude-dependencies.md b/.changeset/bgp-exclude-dependencies.md
new file mode 100644
index 000000000..11cf94a83
--- /dev/null
+++ b/.changeset/bgp-exclude-dependencies.md
@@ -0,0 +1,6 @@
+---
+'@callstack/react-native-brownfield': minor
+'@callstack/brownfield-cli': minor
+---
+
+feat: the published POM and `module.json` now follow the brownfield module's Gradle exclude rules (`configurations.all { exclude(...) }`). Before, the plugin re-added an excluded dependency when it injected the embedded libraries' dependencies, so the host app still resolved it. The excludes are also written onto every dependency the plugin injects, so the excluded library can't arrive through one of them. On Expo, list them in `android.excludeDependencies` (as `group:module` or `group`), which the config plugin writes into the generated module.
diff --git a/apps/RNApp/android/build.gradle b/apps/RNApp/android/build.gradle
index f255767fd..9c14e8ede 100644
--- a/apps/RNApp/android/build.gradle
+++ b/apps/RNApp/android/build.gradle
@@ -16,7 +16,7 @@ buildscript {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
- classpath("com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha13-SNAPSHOT")
+ classpath("com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha14-SNAPSHOT")
}
}
diff --git a/apps/scripts/prepare-android-build-gradle-for-ci.ts b/apps/scripts/prepare-android-build-gradle-for-ci.ts
index 09e84d35e..eb41590d2 100644
--- a/apps/scripts/prepare-android-build-gradle-for-ci.ts
+++ b/apps/scripts/prepare-android-build-gradle-for-ci.ts
@@ -9,7 +9,7 @@ if (!projectDirName) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
-const SNAPSHOT_VERSION = '2.0.0-alpha13-SNAPSHOT';
+const SNAPSHOT_VERSION = '2.0.0-alpha14-SNAPSHOT';
// Accepts a repo-relative app dir (e.g. "ExpoApp58") or an absolute path (e.g.
// the scaffold-smoke app created outside the repo).
const projectDir = path.isAbsolute(projectDirName)
diff --git a/docs/docs/docs/api-reference/configuration.mdx b/docs/docs/docs/api-reference/configuration.mdx
index daa8b40d8..ed8806334 100644
--- a/docs/docs/docs/api-reference/configuration.mdx
+++ b/docs/docs/docs/api-reference/configuration.mdx
@@ -195,6 +195,7 @@ All file-based platform options mirror CLI flags, but they use camelCase propert
| `android.expo.minifyEnabled` | `boolean` | Controls `minifyEnabled` for the generated Android library build. Disabled by default. |
| `android.expo.extraProguardRules` | `string[]`| Additional Proguard rules appended to the generated `proguard-rules.pro`. |
| `android.expo.useLocalMaven` | `boolean` | Load the Brownfield Gradle plugin published to local maven instead of using from remote. Disabled by default. |
+| `android.expo.excludeDependencies` | `string[]` | Dependencies to keep out of the published AAR's POM and `module.json`, as `group:module` or `group` for a whole group. Written into the generated module as Gradle `exclude` rules. |
Example:
diff --git a/gradle-plugins/react/README.md b/gradle-plugins/react/README.md
index 13d58e90f..2da4eb218 100644
--- a/gradle-plugins/react/README.md
+++ b/gradle-plugins/react/README.md
@@ -177,6 +177,27 @@ dependencies {
}
```
+
+
+The published POM and `module.json` follow the brownfield module's Gradle exclude rules. Put the exclude in the brownfield module's `build.gradle.kts`, for example when two libraries ship the same classes under different artifacts:
+
+```kts
+configurations.all {
+ exclude(group = "com.caverock", module = "androidsvg")
+}
+```
+
+The excluded dependency is left out of the published files, and is written as an exclusion on every published dependency, so the host app doesn't get it through one of them either. Use this instead of a custom task that edits the published files: the plugin rewrites them after Gradle generates them, so an earlier edit would be lost.
+
+Only `exclude` rules on the `implementation`, `api`, `runtimeOnly` and `embed` configurations count. These are not read:
+
+- excludes in `:app`: they describe the standalone React Native app, which may leave out things the host app needs
+- excludes on a variant's configuration (`debugRuntimeClasspath`): every variant publishes the same list
+- excludes on a single dependency (`implementation("x") { exclude(...) }`): they only apply under that dependency
+- `resolutionStrategy` substitutions and capability rules
+
+On Expo, prebuild regenerates the brownfield module, so list the dependencies in `brownfield.config.json` under `android.expo.excludeDependencies` (or under `android.excludeDependencies` in the plugin's options in `app.json`), as `group:module` or `group`. Prebuild writes them into the module as the `configurations.all` block above.
+
diff --git a/gradle-plugins/react/brownfield/gradle.properties b/gradle-plugins/react/brownfield/gradle.properties
index 659d435e2..9135c30c4 100644
--- a/gradle-plugins/react/brownfield/gradle.properties
+++ b/gradle-plugins/react/brownfield/gradle.properties
@@ -1,6 +1,6 @@
PROJECT_ID=com.callstack.react.brownfield
ARTIFACT_ID=brownfield-gradle-plugin
-VERSION=2.0.0-alpha13
+VERSION=2.0.0-alpha14
GROUP=com.callstack.react
IMPLEMENTATION_CLASS=com.callstack.react.brownfield.plugin.RNBrownfieldPlugin
diff --git a/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt b/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt
index 6e955f0a1..8246475ee 100644
--- a/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt
+++ b/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/plugin/RNBrownfieldPlugin.kt
@@ -19,11 +19,13 @@ import com.callstack.react.brownfield.processors.VariantTaskProvider
import com.callstack.react.brownfield.shared.BaseProject
import com.callstack.react.brownfield.shared.Constants
import com.callstack.react.brownfield.shared.Constants.PROJECT_ID
+import com.callstack.react.brownfield.shared.GradleExclude
import com.callstack.react.brownfield.shared.Logging
import com.callstack.react.brownfield.shared.PublishingMetadataInjector
import com.callstack.react.brownfield.shared.UnresolvedArtifactInfo
import com.callstack.react.brownfield.shared.VersionMediatingDependencySet
import com.callstack.react.brownfield.shared.dropHardExcludedDependencies
+import com.callstack.react.brownfield.shared.gradleExcludes
import com.callstack.react.brownfield.utils.AndroidArchiveLibrary
import com.callstack.react.brownfield.utils.DirectoryManager
import com.callstack.react.brownfield.utils.Extension
@@ -33,6 +35,24 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.ProjectConfigurationException
+/**
+ * Coordinates that must never be published: embedded in the AAR (not resolvable from Maven), or
+ * excluded by the brownfield module's own Gradle rules.
+ */
+internal fun hardExcludePredicate(
+ project: Project,
+ expoPublishingHelper: ExpoPublishingHelper?,
+ artifacts: List,
+ expoProjects: List,
+ excludes: List,
+): (String, String) -> Boolean =
+ { groupId, artifactId ->
+ (expoPublishingHelper?.shouldExcludeDependency(groupId, artifactId) ?: (groupId == project.rootProject.name)) ||
+ artifacts.any { it.moduleGroup == groupId && it.moduleName == artifactId } ||
+ expoProjects.any { it.publication?.groupId == groupId && it.publication?.artifactId == artifactId } ||
+ excludes.any { it.matches(groupId, artifactId) }
+ }
+
class RNBrownfieldPlugin : Plugin {
private lateinit var extension: Extension
private lateinit var project: Project
@@ -140,11 +160,8 @@ class RNBrownfieldPlugin : Plugin {
// Coordinates that must never be published: they're embedded in the AAR, not
// resolvable from Maven. Distinct from "superseded" coordinates, which ARE re-injected
// (replacing a stale entry) and so must not be dropped here.
- val hardExcludePredicate: (String, String) -> Boolean = { groupId, artifactId ->
- (expoPublishingHelper?.shouldExcludeDependency(groupId, artifactId) ?: (groupId == project.rootProject.name)) ||
- artifacts.any { it.moduleGroup == groupId && it.moduleName == artifactId } ||
- expoProjects.any { it.publication?.groupId == groupId && it.publication?.artifactId == artifactId }
- }
+ val excludes = gradleExcludes(project)
+ val hardExcludePredicate = hardExcludePredicate(project, expoPublishingHelper, artifacts, expoProjects, excludes)
dropHardExcludedDependencies(transitiveDeps, hardExcludePredicate)
Logging.log(
@@ -155,7 +172,7 @@ class RNBrownfieldPlugin : Plugin {
hardExcludePredicate(groupId, artifactId) || rncSupersededCoordinates.contains(groupId to artifactId)
}
- injector.configure(transitiveDeps, removalPredicate)
+ injector.configure(transitiveDeps, removalPredicate, excludes)
Logging.log("PublishingMetadataInjector ran: injected merged transitive dependencies into POM and Gradle Module Metadata")
// Informational only — throwing would recreate the upgrade break that the namespaced
diff --git a/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/GradleExclude.kt b/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/GradleExclude.kt
new file mode 100644
index 000000000..8551b04b5
--- /dev/null
+++ b/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/GradleExclude.kt
@@ -0,0 +1,31 @@
+package com.callstack.react.brownfield.shared
+
+import org.gradle.api.Project
+
+/**
+ * The variant-independent configurations that feed what the host app gets. A variant's own
+ * (`debugRuntimeClasspath`) would leak into every variant, since the published list is shared, and a
+ * tool's (lint, detekt) may exclude things the app still needs.
+ */
+private val PUBLISHED_CONFIG_NAMES = TRANSITIVE_DEPENDENCY_CONFIG_NAMES + "embed"
+
+/**
+ * The configuration-level excludes that keep a dependency out of the brownfield module's build.
+ * The plugin reads what embedded libraries declare, not what Gradle resolves, so without these an
+ * excluded dependency would still be published and the host app would resolve it. `:app`'s rules
+ * are not read: they describe the standalone RN app, which may drop things the host needs.
+ */
+internal fun gradleExcludes(project: Project): List =
+ project.configurations
+ .filter { it.name in PUBLISHED_CONFIG_NAMES }
+ .flatMap { it.excludeRules }
+ .map { GradleExclude(it.group, it.module) }
+ .distinct()
+
+/** One exclude rule. Gradle types both parts as non-null, but a rule without one leaves it null. */
+internal data class GradleExclude(val group: String?, val module: String?) {
+ fun matches(
+ groupId: String,
+ artifactId: String,
+ ) = (group == null || group == groupId) && (module == null || module == artifactId)
+}
diff --git a/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjector.kt b/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjector.kt
index 41dd7556a..4328b6f7d 100644
--- a/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjector.kt
+++ b/gradle-plugins/react/brownfield/src/main/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjector.kt
@@ -19,6 +19,7 @@ import org.gradle.api.publish.tasks.GenerateModuleMetadata
internal fun mutatePomDependenciesNode(
dependenciesNode: Node,
dependencies: VersionMediatingDependencySet,
+ excludes: List = emptyList(),
shouldExclude: (groupId: String, artifactId: String) -> Boolean,
) {
dependenciesNode.children()
@@ -49,6 +50,21 @@ internal fun mutatePomDependenciesNode(
childTags.forEach { (tagName, tagValue) ->
newDepNode.appendNode(tagName, tagValue)
}
+ appendExclusions(newDepNode, excludes)
+ }
+ }
+}
+
+private fun appendExclusions(
+ dependencyNode: Node,
+ excludes: List,
+) {
+ if (excludes.isEmpty()) return
+ val exclusionsNode = dependencyNode.appendNode("exclusions")
+ excludes.forEach { exclude ->
+ exclusionsNode.appendNode("exclusion").apply {
+ appendNode("groupId", exclude.group ?: "*")
+ appendNode("artifactId", exclude.module ?: "*")
}
}
}
@@ -69,6 +85,7 @@ internal fun resolveOrCreateDependenciesNode(root: Node): Node =
internal fun mutateModuleJsonVariants(
json: Map<*, *>,
dependencies: VersionMediatingDependencySet,
+ excludes: List = emptyList(),
shouldExclude: (groupId: String, artifactId: String) -> Boolean,
) {
@Suppress("UNCHECKED_CAST")
@@ -98,6 +115,9 @@ internal fun mutateModuleJsonVariants(
dependencyToAdd.version?.let { version ->
put("version", mapOf("requires" to version))
}
+ if (excludes.isNotEmpty()) {
+ put("excludes", excludes.map { mapOf("group" to (it.group ?: "*"), "module" to (it.module ?: "*")) })
+ }
},
)
}
@@ -116,6 +136,7 @@ internal fun mutateModuleJsonVariants(
class PublishingMetadataInjector(private val project: Project) {
private var dependencies = VersionMediatingDependencySet()
private var shouldExclude: (groupId: String, artifactId: String) -> Boolean = { _, _ -> false }
+ private var excludes: List = emptyList()
private var enabled = false
init {
@@ -124,12 +145,16 @@ class PublishingMetadataInjector(private val project: Project) {
}
/** Supplies the dependencies to inject and enables injection on the hooks registered in [init]. */
- fun configure(
+ internal fun configure(
dependencies: VersionMediatingDependencySet,
shouldExclude: (groupId: String, artifactId: String) -> Boolean,
+ excludes: List,
) {
this.dependencies = dependencies
this.shouldExclude = shouldExclude
+ // Gradle writes the module's excludes onto the dependencies it declares; these are injected
+ // later, so they need them too, or an excluded library could still arrive through one.
+ this.excludes = excludes
this.enabled = true
}
@@ -148,7 +173,7 @@ class PublishingMetadataInjector(private val project: Project) {
if (!moduleFile.exists()) return@forEach
val json = moduleFile.inputStream().use { JsonSlurper().parse(it) as Map<*, *> }
- mutateModuleJsonVariants(json, dependencies, shouldExclude)
+ mutateModuleJsonVariants(json, dependencies, excludes, shouldExclude)
moduleFile.writer().use {
it.write(JsonOutput.prettyPrint(JsonOutput.toJson(json)))
}
@@ -172,7 +197,7 @@ class PublishingMetadataInjector(private val project: Project) {
val root = it.asNode()
val dependenciesNode = resolveOrCreateDependenciesNode(root)
- mutatePomDependenciesNode(dependenciesNode, dependencies, shouldExclude)
+ mutatePomDependenciesNode(dependenciesNode, dependencies, excludes, shouldExclude)
}
}
}
diff --git a/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/plugin/HardExcludePredicateTest.kt b/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/plugin/HardExcludePredicateTest.kt
new file mode 100644
index 000000000..24b5bc2eb
--- /dev/null
+++ b/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/plugin/HardExcludePredicateTest.kt
@@ -0,0 +1,28 @@
+package com.callstack.react.brownfield.plugin
+
+import com.callstack.react.brownfield.shared.gradleExcludes
+import org.gradle.testfixtures.ProjectBuilder
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
+import java.io.File
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+class HardExcludePredicateTest {
+ @TempDir
+ lateinit var tempDir: File
+
+ @Test
+ fun `never publishes what the brownfield module excludes, or its own subprojects`() {
+ val root = ProjectBuilder.builder().withName("MyApp").withProjectDir(tempDir).build()
+ val lib = ProjectBuilder.builder().withName("brownfieldlib").withParent(root).build()
+ lib.configurations.create("implementation")
+ lib.configurations.all { it.exclude(mapOf("group" to "com.caverock", "module" to "androidsvg")) }
+
+ val excluded = hardExcludePredicate(lib, null, emptyList(), emptyList(), gradleExcludes(lib))
+
+ assertTrue(excluded("com.caverock", "androidsvg"))
+ assertTrue(excluded("MyApp", "react-native-screens"))
+ assertFalse(excluded("androidx.core", "core-ktx"))
+ }
+}
diff --git a/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/GradleExcludesTest.kt b/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/GradleExcludesTest.kt
new file mode 100644
index 000000000..4235da132
--- /dev/null
+++ b/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/GradleExcludesTest.kt
@@ -0,0 +1,81 @@
+package com.callstack.react.brownfield.shared
+
+import org.gradle.api.Project
+import org.gradle.testfixtures.ProjectBuilder
+import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.io.TempDir
+import java.io.File
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+class GradleExcludesTest {
+ @TempDir
+ lateinit var tempDir: File
+
+ private fun project(
+ name: String,
+ vararg configNames: String,
+ ): Project =
+ ProjectBuilder.builder().withName(name).withProjectDir(File(tempDir, name)).build().also { project ->
+ configNames.forEach { project.configurations.create(it) }
+ }
+
+ private fun Project.excludeEverywhere(
+ group: String,
+ module: String? = null,
+ ) = configurations.all { config ->
+ config.exclude(listOfNotNull("group" to group, module?.let { "module" to it }).toMap())
+ }
+
+ private fun excluded(
+ project: Project,
+ groupId: String,
+ artifactId: String,
+ ) = gradleExcludes(project).any { it.matches(groupId, artifactId) }
+
+ @Test
+ fun `honors an exclude declared on every configuration`() {
+ val lib = project("lib", "implementation", "releaseRuntimeClasspath")
+ lib.excludeEverywhere("com.caverock", "androidsvg")
+
+ assertTrue(excluded(lib, "com.caverock", "androidsvg"))
+ assertFalse(excluded(lib, "com.caverock", "androidsvg-aar"))
+ }
+
+ @Test
+ fun `a group-only exclude matches every module of the group`() {
+ val lib = project("lib", "api")
+ lib.excludeEverywhere("com.caverock")
+
+ assertTrue(excluded(lib, "com.caverock", "androidsvg-aar"))
+ }
+
+ @Test
+ fun `ignores a variant-specific exclude`() {
+ val lib = project("lib", "implementation", "debugRuntimeClasspath")
+ lib.configurations.getByName("debugRuntimeClasspath").exclude(mapOf("group" to "com.caverock"))
+
+ assertFalse(excluded(lib, "com.caverock", "androidsvg"))
+ }
+
+ @Test
+ fun `honors an exclude on a single runtime configuration`() {
+ val lib = project("lib", "embed")
+ lib.configurations.getByName("embed").exclude(mapOf("group" to "com.caverock", "module" to "androidsvg"))
+
+ assertTrue(excluded(lib, "com.caverock", "androidsvg"))
+ }
+
+ @Test
+ fun `ignores configurations that do not feed the runtime`() {
+ val lib = project("lib", "implementation", "detekt")
+ lib.configurations.getByName("detekt").exclude(mapOf("group" to "org.jetbrains.kotlin"))
+
+ assertFalse(excluded(lib, "org.jetbrains.kotlin", "kotlin-stdlib"))
+ }
+
+ @Test
+ fun `matches nothing without excludes`() {
+ assertFalse(excluded(project("lib", "implementation"), "com.caverock", "androidsvg"))
+ }
+}
diff --git a/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjectorTest.kt b/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjectorTest.kt
index a31db038a..cc5b7d230 100644
--- a/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjectorTest.kt
+++ b/gradle-plugins/react/brownfield/src/test/kotlin/com/callstack/react/brownfield/shared/PublishingMetadataInjectorTest.kt
@@ -163,6 +163,36 @@ class MutatePomDependenciesNodeTest {
assertEquals(listOf("1.7.1"), versionsFor(dependenciesNode, "androidx.appcompat", "appcompat"))
}
+
+ @Test
+ fun `writes the brownfield module's excludes onto every injected dependency`() {
+ val dependenciesNode = dependenciesNodeFrom("")
+ val toInject = VersionMediatingDependencySet()
+ toInject.add(DependencyInfo("com.foo", "charts", "1.0", "compile", false))
+ val excludes = listOf(GradleExclude("com.caverock", "androidsvg"), GradleExclude("com.legacy", null))
+
+ mutatePomDependenciesNode(dependenciesNode, toInject, excludes) { _, _ -> false }
+
+ val dependency = dependenciesNode.children().filterIsInstance().single()
+ val exclusions =
+ ((dependency["exclusions"] as NodeList).single() as groovy.util.Node).children().filterIsInstance()
+ assertEquals(
+ listOf("com.caverock" to "androidsvg", "com.legacy" to "*"),
+ exclusions.map { (it["groupId"] as NodeList).text() to (it["artifactId"] as NodeList).text() },
+ )
+ }
+
+ @Test
+ fun `writes no exclusions element without excludes`() {
+ val dependenciesNode = dependenciesNodeFrom("")
+ val toInject = VersionMediatingDependencySet()
+ toInject.add(DependencyInfo("com.foo", "charts", "1.0", "compile", false))
+
+ mutatePomDependenciesNode(dependenciesNode, toInject) { _, _ -> false }
+
+ val dependency = dependenciesNode.children().filterIsInstance().single()
+ assertTrue((dependency["exclusions"] as NodeList).isEmpty())
+ }
}
class MutateModuleJsonVariantsTest {
@@ -219,4 +249,30 @@ class MutateModuleJsonVariantsTest {
val version = (deps.first()["version"] as? Map)?.get("requires")
assertEquals("1.7.1", version)
}
+
+ @Test
+ fun `writes the brownfield module's excludes onto every injected dependency`() {
+ val json = jsonWithVariant(mutableListOf())
+ val toInject = VersionMediatingDependencySet()
+ toInject.add(DependencyInfo("com.foo", "charts", "1.0", "compile", false))
+ val excludes = listOf(GradleExclude("com.caverock", "androidsvg"), GradleExclude("com.legacy", null))
+
+ mutateModuleJsonVariants(json, toInject, excludes) { _, _ -> false }
+
+ assertEquals(
+ listOf(mapOf("group" to "com.caverock", "module" to "androidsvg"), mapOf("group" to "com.legacy", "module" to "*")),
+ dependenciesOf(json).single()["excludes"],
+ )
+ }
+
+ @Test
+ fun `writes no excludes field without excludes`() {
+ val json = jsonWithVariant(mutableListOf())
+ val toInject = VersionMediatingDependencySet()
+ toInject.add(DependencyInfo("com.foo", "charts", "1.0", "compile", false))
+
+ mutateModuleJsonVariants(json, toInject) { _, _ -> false }
+
+ assertNull(dependenciesOf(json).single()["excludes"])
+ }
}
diff --git a/packages/cli/schema.json b/packages/cli/schema.json
index a25fb5ec9..d732ac690 100644
--- a/packages/cli/schema.json
+++ b/packages/cli/schema.json
@@ -57,6 +57,13 @@
"description": "Compile SDK version for the Android library. Defaults to 37 on Expo SDK 58 and later, otherwise 35.",
"type": "number"
},
+ "excludeDependencies": {
+ "description": "Dependencies to keep out of the published AAR's POM and module.json, as \"group:module\" or \"group\" for a whole group. Written as Gradle excludes into the generated module, e.g. \"com.caverock:androidsvg\".",
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
"extraProguardRules": {
"description": "Extra Proguard rules appended to the default rules.",
"items": {
diff --git a/packages/cli/src/__tests__/expoPluginConfig.test.ts b/packages/cli/src/__tests__/expoPluginConfig.test.ts
index 7ff792845..5ac058d64 100644
--- a/packages/cli/src/__tests__/expoPluginConfig.test.ts
+++ b/packages/cli/src/__tests__/expoPluginConfig.test.ts
@@ -209,6 +209,7 @@ describe('resolveBrownfieldPluginConfig', () => {
extraProguardRules: [],
useLocalMaven: false,
missingDimensionStrategies: [],
+ excludeDependencies: [],
},
});
});
@@ -511,4 +512,21 @@ describe('resolveBrownfieldPluginConfig', () => {
'alpha',
]);
});
+
+ it('maps android.excludeDependencies from app.json plugin props', () => {
+ const resolved = resolveBrownfieldPluginConfig(
+ {
+ android: {
+ moduleName: 'mylib',
+ excludeDependencies: ['com.caverock:androidsvg'],
+ },
+ },
+ null,
+ baseExpoConfig
+ );
+
+ expect(resolved.android?.excludeDependencies).toEqual([
+ 'com.caverock:androidsvg',
+ ]);
+ });
});
diff --git a/packages/cli/src/expoPluginConfig.ts b/packages/cli/src/expoPluginConfig.ts
index be954833f..2d3bcb33f 100644
--- a/packages/cli/src/expoPluginConfig.ts
+++ b/packages/cli/src/expoPluginConfig.ts
@@ -28,6 +28,7 @@ export type BrownfieldPluginProps = {
extraProguardRules?: string[];
useLocalMaven?: boolean;
missingDimensionStrategies?: string[];
+ excludeDependencies?: string[];
};
};
@@ -45,6 +46,7 @@ export type ResolvedBrownfieldPluginAndroidConfig = {
extraProguardRules: string[];
useLocalMaven: boolean;
missingDimensionStrategies: string[];
+ excludeDependencies: string[];
};
export type ResolvedBrownfieldPluginIosConfig = {
@@ -214,6 +216,8 @@ export function resolveBrownfieldPluginConfig(
useLocalMaven: effectiveProps.android?.useLocalMaven ?? false,
missingDimensionStrategies:
effectiveProps.android?.missingDimensionStrategies ?? [],
+ excludeDependencies:
+ effectiveProps.android?.excludeDependencies ?? [],
...(effectiveProps.android?.targetSdkVersion != null
? { targetSdkVersion: effectiveProps.android.targetSdkVersion }
: {}),
diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts
index b11c5607b..7dcd1f756 100644
--- a/packages/cli/src/types.ts
+++ b/packages/cli/src/types.ts
@@ -113,10 +113,17 @@ export type BrownfieldExpoAndroidConfig = {
*/
useLocalMaven?: boolean;
- /**
+ /**
* Missing dimension strategies as dimension + flavor(s), e.g. "type, alpha".
*/
missingDimensionStrategies?: string[];
+
+ /**
+ * Dependencies to keep out of the published AAR's POM and module.json, as
+ * "group:module" or "group" for a whole group. Written as Gradle excludes
+ * into the generated module, e.g. "com.caverock:androidsvg".
+ */
+ excludeDependencies?: string[];
};
/**
diff --git a/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/gradleHelpers.test.ts b/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/gradleHelpers.test.ts
index 6f116765b..546434f23 100644
--- a/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/gradleHelpers.test.ts
+++ b/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/gradleHelpers.test.ts
@@ -16,7 +16,7 @@ describe('gradleHelpers', () => {
}`;
expect(modifyRootBuildGradle(contents)).toContain(
- 'classpath("com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha13")'
+ 'classpath("com.callstack.react:brownfield-gradle-plugin:2.0.0-alpha14")'
);
});
diff --git a/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/withAndroidModuleFiles.test.ts b/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/withAndroidModuleFiles.test.ts
index 28e1123e0..3bcb89b99 100644
--- a/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/withAndroidModuleFiles.test.ts
+++ b/packages/react-native-brownfield/src/expo-config-plugin/android/__tests__/withAndroidModuleFiles.test.ts
@@ -395,6 +395,80 @@ describe('createAndroidModule', () => {
expect(buildGradle).toContain('missingDimensionStrategy("type", "alpha")');
});
+ it('omits the configurations block when no dependencies are excluded', () => {
+ const androidDir = createAndroidDir();
+
+ createAndroidModule({
+ androidDir,
+ config: createConfig(),
+ rnVersion: '0.85.3',
+ });
+
+ expect(readLibraryBuildGradle(androidDir)).not.toContain(
+ 'configurations.all'
+ );
+ });
+
+ it('renders excludeDependencies as Gradle excludes in the generated build.gradle', () => {
+ const androidDir = createAndroidDir();
+
+ createAndroidModule({
+ androidDir,
+ config: createConfig({
+ android: {
+ excludeDependencies: [
+ 'com.caverock:androidsvg',
+ 'com.example.legacy',
+ ],
+ },
+ }),
+ rnVersion: '0.85.3',
+ });
+
+ expect(readLibraryBuildGradle(androidDir)).toContain(
+ [
+ 'configurations.all {',
+ ' exclude(group = "com.caverock", module = "androidsvg")',
+ ' exclude(group = "com.example.legacy")',
+ '}',
+ ].join('\n')
+ );
+ });
+
+ it('rejects an excludeDependencies value that is not a list', () => {
+ const androidDir = createAndroidDir();
+
+ expect(() =>
+ createAndroidModule({
+ androidDir,
+ config: createConfig({
+ android: {
+ excludeDependencies:
+ 'com.caverock:androidsvg' as unknown as string[],
+ },
+ }),
+ rnVersion: '0.85.3',
+ })
+ ).toThrow('android.excludeDependencies must be a list');
+ });
+
+ it.each([
+ 'com.caverock:androidsvg:1.4',
+ ':androidsvg',
+ 'com.caverock:',
+ 'com.caverock:"androidsvg"',
+ ])('rejects the excludeDependencies entry %s', (entry) => {
+ const androidDir = createAndroidDir();
+
+ expect(() =>
+ createAndroidModule({
+ androidDir,
+ config: createConfig({ android: { excludeDependencies: [entry] } }),
+ rnVersion: '0.85.3',
+ })
+ ).toThrow(entry);
+ });
+
it('uses api dependencies and the installed React Native Hermes artifact for newer Expo projects', () => {
const androidDir = createAndroidDir();
const projectRoot = path.dirname(androidDir);
@@ -478,6 +552,7 @@ HERMES_V1_VERSION_NAME=250829098.0.10
useLocalGradlePlugin: false,
useLocalMaven: false,
missingDimensionStrategies: [],
+ excludeDependencies: [],
...(overrides.android ?? {}),
},
};
diff --git a/packages/react-native-brownfield/src/expo-config-plugin/android/utils/constants.ts b/packages/react-native-brownfield/src/expo-config-plugin/android/utils/constants.ts
index 59cf7e2b9..6dfe0d987 100644
--- a/packages/react-native-brownfield/src/expo-config-plugin/android/utils/constants.ts
+++ b/packages/react-native-brownfield/src/expo-config-plugin/android/utils/constants.ts
@@ -1,2 +1,2 @@
-export const BROWNFIELD_PLUGIN_VERSION = '2.0.0-alpha13';
+export const BROWNFIELD_PLUGIN_VERSION = '2.0.0-alpha14';
export const brownfieldGradlePluginDependency = `classpath("com.callstack.react:brownfield-gradle-plugin:${BROWNFIELD_PLUGIN_VERSION}")`;
diff --git a/packages/react-native-brownfield/src/expo-config-plugin/android/withAndroidModuleFiles.ts b/packages/react-native-brownfield/src/expo-config-plugin/android/withAndroidModuleFiles.ts
index 02fbc2689..eeffbe96b 100644
--- a/packages/react-native-brownfield/src/expo-config-plugin/android/withAndroidModuleFiles.ts
+++ b/packages/react-native-brownfield/src/expo-config-plugin/android/withAndroidModuleFiles.ts
@@ -40,6 +40,43 @@ function renderMissingDimensionStrategyBlock(
return ` missingDimensionStrategy(${args})`;
}
+const COORDINATE_PART = /^[A-Za-z0-9._-]+$/;
+
+/**
+ * Renders `excludeDependencies` as a `configurations.all` block. The Brownfield Gradle plugin
+ * leaves anything excluded this way out of the published POM and module.json. Entries become
+ * Kotlin string literals, so anything but a plain coordinate is rejected.
+ */
+function renderExcludeDependenciesBlock(excludeDependencies: string[]): string {
+ // It comes from user JSON, so the type isn't guaranteed.
+ if (!Array.isArray(excludeDependencies)) {
+ throw new Error(
+ 'android.excludeDependencies must be a list of "group:module" or "group" strings.'
+ );
+ }
+ if (excludeDependencies.length === 0) {
+ return '';
+ }
+
+ const lines = excludeDependencies.map((entry) => {
+ const parts = entry.split(':');
+ if (
+ parts.length > 2 ||
+ !parts.every((part) => COORDINATE_PART.test(part))
+ ) {
+ throw new Error(
+ `android.excludeDependencies: '${entry}' is not in the form "group:module" or "group".`
+ );
+ }
+ const [group, module] = parts;
+ return module
+ ? ` exclude(group = "${group}", module = "${module}")`
+ : ` exclude(group = "${group}")`;
+ });
+
+ return `configurations.all {\n${lines.join('\n')}\n}\n\n`;
+}
+
export function resolveCompileSdkVersionExpression(
config: ResolvedBrownfieldPluginConfigWithAndroid
): string {
@@ -154,6 +191,10 @@ export function createAndroidModule({
android.missingDimensionStrategies
);
+ const excludeDependenciesBlock = renderExcludeDependenciesBlock(
+ android.excludeDependencies
+ );
+
// generate module files
const files: RenderedTemplateFile[] = [
{
@@ -171,6 +212,7 @@ export function createAndroidModule({
'{{IS_MINIFY_ENABLED}}': minifyEnabled.toString(),
'{{MISSING_DIMENSION_STRATEGIES}}': missingDimensionStrategiesList,
'{{MISSING_DIMENSION_STRATEGY_BLOCK}}': missingDimensionStrategyBlock,
+ '{{EXCLUDE_DEPENDENCIES_BLOCK}}': excludeDependenciesBlock,
}),
},
{
diff --git a/packages/react-native-brownfield/src/expo-config-plugin/template/android/build.gradle.kts b/packages/react-native-brownfield/src/expo-config-plugin/template/android/build.gradle.kts
index 9053326c1..e404e938c 100644
--- a/packages/react-native-brownfield/src/expo-config-plugin/template/android/build.gradle.kts
+++ b/packages/react-native-brownfield/src/expo-config-plugin/template/android/build.gradle.kts
@@ -47,7 +47,7 @@ reactBrownfield {
missingDimensionStrategies = listOf({{MISSING_DIMENSION_STRATEGIES}})
}
-react {
+{{EXCLUDE_DEPENDENCIES_BLOCK}}react {
autolinkLibrariesWithApp()
}
diff --git a/packages/react-native-brownfield/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.ts b/packages/react-native-brownfield/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.ts
index af44da7f3..1e69b5c66 100644
--- a/packages/react-native-brownfield/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.ts
+++ b/packages/react-native-brownfield/src/expo-config-plugin/types/android/BrownfieldPluginAndroidConfig.ts
@@ -69,6 +69,13 @@ export interface BrownfieldPluginAndroidConfig {
* @default []
*/
missingDimensionStrategies?: string[];
+
+ /**
+ * Dependencies to keep out of the published AAR's POM and module.json, as
+ * "group:module" or "group" for a whole group, e.g. "com.caverock:androidsvg".
+ * @default []
+ */
+ excludeDependencies?: string[];
}
/**
diff --git a/packages/react-native-brownfield/src/scaffold/index.ts b/packages/react-native-brownfield/src/scaffold/index.ts
index 6a55b66f7..f55cd7906 100644
--- a/packages/react-native-brownfield/src/scaffold/index.ts
+++ b/packages/react-native-brownfield/src/scaffold/index.ts
@@ -301,6 +301,7 @@ export async function scaffoldBrownfieldInRncCliProject(
useLocalGradlePlugin: false,
useLocalMaven: false,
missingDimensionStrategies: [],
+ excludeDependencies: [],
},
ios: null,
debug: options.debug ?? false,