Skip to content

Commit 29b8f0c

Browse files
README: update Gradle setup to drop ID mapping, add repos in Settings
Declaring dependency repositories in the Settings file is now Gradle best practice: https://docs.gradle.org/current/userguide/best_practices_dependencies.html#set_up_repositories_in_settings
1 parent 30a0098 commit 29b8f0c

1 file changed

Lines changed: 31 additions & 48 deletions

File tree

README.md

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,15 @@ When using a [TOML version catalog](https://docs.gradle.org/current/userguide/ve
145145
# gradle/libs.versions.toml
146146

147147
[versions]
148-
# Define a variable for the version of the plugin
149-
objectbox = "5.2.0"
150-
151148
# For an Android project
152-
agp = "<AGP_VERSION>"
153-
149+
agp = "AGP_VERSION"
154150
# If using Kotlin
155-
kotlin = "<KOTLIN_VERSION>"
151+
kotlin = "KOTLIN_VERSION"
156152

157-
[plugins]
158-
# Add an alias for the plugin
159-
objectbox = { id = "io.objectbox", version.ref = "objectbox" }
153+
# Define a variable for the version of the ObjectBox plugin
154+
objectbox = "5.2.0"
160155

156+
[plugins]
161157
# For an Android project, using Android Gradle Plugin 9.0 or newer
162158
android-application = { id = "com.android.application", version.ref = "agp" }
163159
kotlin-kapt = { id = "com.android.legacy-kapt", version.ref = "agp" }
@@ -170,15 +166,15 @@ kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
170166
# For a JVM project, if using Kotlin
171167
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
172168
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
169+
170+
# Add an alias for the ObjectBox plugin
171+
objectbox = { id = "io.objectbox", version.ref = "objectbox" }
173172
```
174173

175174
```kotlin
176175
// build.gradle.kts
177176

178177
plugins {
179-
// Add the plugin
180-
alias(libs.plugins.objectbox) apply false
181-
182178
// For an Android project, using Android Gradle Plugin 9.0 or newer
183179
alias(libs.plugins.android.application) apply false
184180
alias(libs.plugins.kotlin.kapt) apply false
@@ -191,13 +187,9 @@ plugins {
191187
// For a JVM project, if using Kotlin
192188
alias(libs.plugins.kotlin.jvm) apply false
193189
alias(libs.plugins.kotlin.kapt) apply false
194-
}
195-
196-
allprojects {
197-
repositories {
198-
// Add Maven Central to the dependency repositories
199-
mavenCentral()
200-
}
190+
191+
// Add the ObjectBox plugin
192+
alias(libs.plugins.objectbox) apply false
201193
}
202194
```
203195

@@ -209,14 +201,13 @@ pluginManagement {
209201
// Add Maven Central to the plugin repositories
210202
mavenCentral()
211203
}
212-
213-
resolutionStrategy {
214-
eachPlugin {
215-
// Map the plugin ID to the Maven artifact
216-
if (requested.id.id == "io.objectbox") {
217-
useModule("io.objectbox:objectbox-gradle-plugin:${requested.version}")
218-
}
219-
}
204+
}
205+
206+
dependencyResolutionManagement {
207+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
208+
repositories {
209+
// Add Maven Central to the dependency repositories
210+
mavenCentral()
220211
}
221212
}
222213
```
@@ -242,7 +233,7 @@ plugins {
242233
alias(libs.plugins.kotlin.jvm)
243234
alias(libs.plugins.kotlin.kapt)
244235

245-
// Finally, apply the plugin
236+
// Finally, apply the ObjectBox plugin
246237
alias(libs.plugins.objectbox)
247238
}
248239
```
@@ -259,16 +250,9 @@ Your project can now use ObjectBox, continue by [defining entity classes](https:
259250
// build.gradle.kts
260251

261252
plugins {
262-
// Add the plugin
253+
// Add the ObjectBox plugin
263254
id("io.objectbox") version "5.2.0" apply false
264255
}
265-
266-
allprojects {
267-
repositories {
268-
// Add Maven Central to the dependency repositories
269-
mavenCentral()
270-
}
271-
}
272256
```
273257

274258
```kotlin
@@ -279,14 +263,13 @@ pluginManagement {
279263
// Add Maven Central to the plugin repositories
280264
mavenCentral()
281265
}
266+
}
282267

283-
resolutionStrategy {
284-
eachPlugin {
285-
// Map the plugin ID to the Maven artifact
286-
if (requested.id.id == "io.objectbox") {
287-
useModule("io.objectbox:objectbox-gradle-plugin:${requested.version}")
288-
}
289-
}
268+
dependencyResolutionManagement {
269+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
270+
repositories {
271+
// Add Maven Central to the dependency repositories
272+
mavenCentral()
290273
}
291274
}
292275
```
@@ -299,7 +282,7 @@ pluginManagement {
299282
// build.gradle.kts
300283

301284
buildscript {
302-
// Define a variable for the plugin version
285+
// Define a variable for the ObjectBox plugin version
303286
val objectboxVersion by extra("5.2.0")
304287

305288
repositories {
@@ -308,7 +291,7 @@ buildscript {
308291
}
309292

310293
dependencies {
311-
// Add the plugin
294+
// Add the ObjectBox plugin
312295
classpath("io.objectbox:objectbox-gradle-plugin:$objectboxVersion")
313296
}
314297
}
@@ -329,7 +312,7 @@ allprojects {
329312
// build.gradle
330313
331314
buildscript {
332-
// Define a variable for the plugin version
315+
// Define a variable for the ObjectBox plugin version
333316
ext.objectboxVersion = "5.2.0"
334317
335318
repositories {
@@ -338,7 +321,7 @@ buildscript {
338321
}
339322
340323
dependencies {
341-
// Add the plugin
324+
// Add the ObjectBox plugin
342325
classpath("io.objectbox:objectbox-gradle-plugin:$objectboxVersion")
343326
}
344327
}
@@ -374,7 +357,7 @@ plugins {
374357
id("org.jetbrains.kotlin.jvm") // or kotlin("jvm")
375358
id("org.jetbrains.kotlin.kapt") // or kotlin("kapt")
376359

377-
// Finally, apply the plugin
360+
// Finally, apply the ObjectBox plugin
378361
id("io.objectbox")
379362
}
380363
```

0 commit comments

Comments
 (0)