|
| 1 | +--- |
| 2 | +name: create-extension-module |
| 3 | +description: Scaffold a new extension module under extensions/ for the InstantSearch Android project. Use when the user wants to create an extension, add a new plugin integration, add a new Android library extension, or add third-party library support. |
| 4 | +--- |
| 5 | + |
| 6 | +# Create Extension Module |
| 7 | + |
| 8 | +Extensions live under `extensions/` and integrate InstantSearch with third-party Android libraries (Paging3, SwipeRefreshLayout, etc.) or provide additional utilities. |
| 9 | + |
| 10 | +## Existing extensions for reference |
| 11 | + |
| 12 | +| Module | Type | Depends on | Integrates with | |
| 13 | +|--------|------|------------|-----------------| |
| 14 | +| `android-paging3` | Android-only | `:instantsearch` | AndroidX Paging 3 | |
| 15 | +| `android-loading` | Android-only | `:instantsearch` | SwipeRefreshLayout | |
| 16 | +| `coroutines-extensions` | KMP JVM-only | `:instantsearch-core` | Kotlin Coroutines/Flow | |
| 17 | + |
| 18 | +## Step-by-step |
| 19 | + |
| 20 | +### 1. Create the module directory |
| 21 | + |
| 22 | +``` |
| 23 | +extensions/<extension-name>/ |
| 24 | +├── build.gradle.kts |
| 25 | +├── gradle.properties |
| 26 | +└── src/ |
| 27 | +``` |
| 28 | + |
| 29 | +### 2. Create `build.gradle.kts` |
| 30 | + |
| 31 | +#### Android extension (most common) |
| 32 | + |
| 33 | +```kotlin |
| 34 | +plugins { |
| 35 | + id("com.android.library") |
| 36 | + id("kotlin-android") |
| 37 | + id("com.vanniktech.maven.publish") |
| 38 | +} |
| 39 | + |
| 40 | +android { |
| 41 | + namespace = "com.algolia.instantsearch.android.<extension_suffix>" |
| 42 | + compileSdk = 35 |
| 43 | + |
| 44 | + defaultConfig { |
| 45 | + minSdk = 23 |
| 46 | + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" |
| 47 | + } |
| 48 | + |
| 49 | + compileOptions { |
| 50 | + sourceCompatibility = JavaVersion.VERSION_1_8 |
| 51 | + targetCompatibility = JavaVersion.VERSION_1_8 |
| 52 | + } |
| 53 | + |
| 54 | + testOptions.unitTests.apply { |
| 55 | + isIncludeAndroidResources = true |
| 56 | + isReturnDefaultValues = true |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach { |
| 61 | + compilerOptions { |
| 62 | + jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8) |
| 63 | + freeCompilerArgs.addAll(listOf( |
| 64 | + "-Xopt-in=com.algolia.instantsearch.ExperimentalInstantSearch", |
| 65 | + "-Xopt-in=com.algolia.instantsearch.InternalInstantSearch", |
| 66 | + "-Xexplicit-api=strict" |
| 67 | + )) |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +dependencies { |
| 72 | + api(project(":instantsearch")) |
| 73 | + // api(libs.androidx.<library>) // the third-party library |
| 74 | + testImplementation(kotlin("test-junit")) |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +#### KMP extension (pure Kotlin, no Android) |
| 79 | + |
| 80 | +```kotlin |
| 81 | +plugins { |
| 82 | + kotlin("multiplatform") |
| 83 | + id("com.vanniktech.maven.publish") |
| 84 | +} |
| 85 | + |
| 86 | +kotlin { |
| 87 | + explicitApi() |
| 88 | + jvm() |
| 89 | + sourceSets { |
| 90 | + all { |
| 91 | + languageSettings { |
| 92 | + optIn("kotlin.RequiresOptIn") |
| 93 | + } |
| 94 | + } |
| 95 | + val commonMain by getting { |
| 96 | + dependencies { |
| 97 | + api(project(":instantsearch-core")) |
| 98 | + implementation(libs.kotlinx.coroutines.core) |
| 99 | + } |
| 100 | + } |
| 101 | + val commonTest by getting { |
| 102 | + dependencies { |
| 103 | + implementation(libs.test.kotlin.common) |
| 104 | + implementation(libs.test.kotlin.annotations) |
| 105 | + implementation(libs.test.coroutines) |
| 106 | + } |
| 107 | + } |
| 108 | + val jvmTest by getting { |
| 109 | + dependencies { |
| 110 | + implementation(libs.test.kotlin.junit) |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### 3. Create `gradle.properties` |
| 118 | + |
| 119 | +```properties |
| 120 | +POM_NAME=InstantSearch Android <Extension Name> Extension |
| 121 | +POM_ARTIFACT_ID=instantsearch-android-<extension-name> |
| 122 | +``` |
| 123 | + |
| 124 | +For KMP extensions without Android: |
| 125 | + |
| 126 | +```properties |
| 127 | +POM_NAME=InstantSearch <Extension Name> Extensions |
| 128 | +POM_ARTIFACT_ID=instantsearch-<extension-name> |
| 129 | +``` |
| 130 | + |
| 131 | +### 4. Register in `settings.gradle.kts` |
| 132 | + |
| 133 | +Add under the Extensions section: |
| 134 | + |
| 135 | +```kotlin |
| 136 | +// Extensions |
| 137 | +include(":extensions:android-paging3") |
| 138 | +include(":extensions:android-loading") |
| 139 | +include(":extensions:coroutines-extensions") |
| 140 | +include(":extensions:<new-extension-name>") // <-- add here |
| 141 | +``` |
| 142 | + |
| 143 | +### 5. Register in root test task |
| 144 | + |
| 145 | +In root `build.gradle.kts`, add to `runDebugUnitTest`: |
| 146 | + |
| 147 | +```kotlin |
| 148 | +dependsOn(":extensions:<name>:testDebugUnitTest") // Android |
| 149 | +dependsOn(":extensions:<name>:jvmTest") // KMP JVM-only |
| 150 | +``` |
| 151 | + |
| 152 | +### 6. Create source directories |
| 153 | + |
| 154 | +Android extension: |
| 155 | + |
| 156 | +``` |
| 157 | +extensions/<name>/src/ |
| 158 | +├── main/kotlin/com/algolia/instantsearch/android/<package>/ |
| 159 | +└── test/kotlin/com/algolia/instantsearch/android/<package>/ |
| 160 | +``` |
| 161 | + |
| 162 | +KMP extension: |
| 163 | + |
| 164 | +``` |
| 165 | +extensions/<name>/src/ |
| 166 | +├── commonMain/kotlin/com/algolia/instantsearch/<package>/ |
| 167 | +├── commonTest/kotlin/com/algolia/instantsearch/<package>/ |
| 168 | +└── jvmTest/kotlin/com/algolia/instantsearch/<package>/ |
| 169 | +``` |
| 170 | + |
| 171 | +### 7. Add new version catalog entries (if needed) |
| 172 | + |
| 173 | +If the extension integrates a new third-party library, add it to `gradle/libs.versions.toml`: |
| 174 | + |
| 175 | +```toml |
| 176 | +[libraries] |
| 177 | +androidx-<lib> = { group = "...", name = "...", version = "..." } |
| 178 | +``` |
| 179 | + |
| 180 | +### 8. Verify |
| 181 | + |
| 182 | +```bash |
| 183 | +./gradlew :extensions:<name>:assemble |
| 184 | +./gradlew spotlessCheck |
| 185 | +``` |
| 186 | + |
| 187 | +## Checklist |
| 188 | + |
| 189 | +- [ ] Module lives under `extensions/<name>/` |
| 190 | +- [ ] `build.gradle.kts` follows project conventions |
| 191 | +- [ ] `gradle.properties` has correct `POM_NAME` and `POM_ARTIFACT_ID` |
| 192 | +- [ ] Registered in `settings.gradle.kts` under Extensions section |
| 193 | +- [ ] Added to `runDebugUnitTest` in root `build.gradle.kts` |
| 194 | +- [ ] Third-party library exposed via `api()` (not `implementation()`) |
| 195 | +- [ ] `explicitApi()` or `-Xexplicit-api=strict` enabled |
| 196 | +- [ ] New dependencies added to version catalog if needed |
| 197 | +- [ ] Module compiles successfully |
0 commit comments