Skip to content

Commit

Permalink
Add resources DSL (#523)
Browse files Browse the repository at this point in the history
This streamlines configuration of enabling `androidResources` and
enforces use of a resource prefix to avoid conflicts.

May your avatars never be wrongly sized again.

<!--
  ⬆ Put your description above this! ⬆

  Please be descriptive and detailed.
  
Please read our [Contributing
Guidelines](https://github.com/tinyspeck/slack-gradle-plugin/blob/main/.github/CONTRIBUTING.md)
and [Code of Conduct](https://slackhq.github.io/code-of-conduct).

Don't worry about deleting this, it's not visible in the PR!
-->
  • Loading branch information
ZacSweers authored Aug 10, 2023
1 parent 979f4f2 commit cb63b5b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/dsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ By default, SGP disables androidTests in projects. These can be enabled via the

This is important for opting in tests to [AndroidTest APK Aggregation](/utilities/#androidtest-apk-aggregation).

### Resources

By default, we disable _Android_ resources (different from _Java_ resources) and libraries have to opt-in to using them.

This can be enabled via the `resources()` feature, which will enable the relevant `BuildFeature` in the Android plugin and also takes a required `prefix` parameter that is used as the required `resourcePrefix` for that library's resources to avoid naming conflicts.

## Android Application Features

### Permission AllowList
Expand Down
15 changes: 15 additions & 0 deletions slack-plugin/src/main/kotlin/slack/gradle/SlackExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package slack.gradle

import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.LibraryExtension
import com.squareup.anvil.plugin.AnvilExtension
import dev.zacsweers.moshix.ir.gradle.MoshiPluginExtension
import javax.inject.Inject
Expand Down Expand Up @@ -813,6 +814,20 @@ public abstract class AndroidFeaturesHandler @Inject constructor() {
androidExtension!!.testOptions.unitTests.isIncludeAndroidResources = true
robolectric.setDisallowChanges(true)
}

/**
* **LIBRARIES ONLY**
*
* Enables android resources in this library and enforces use of the given [prefix] for all
* resources.
*/
public fun resources(prefix: String) {
val libraryExtension =
androidExtension as? LibraryExtension
?: error("slack.android.features.resources() is only applicable in libraries!")
libraryExtension.resourcePrefix = prefix
libraryExtension.buildFeatures { androidResources = true }
}
}

@SlackExtensionMarker
Expand Down

0 comments on commit cb63b5b

Please sign in to comment.