From b81814c436aee76ef1f91a8ed25f630d8e089f18 Mon Sep 17 00:00:00 2001 From: "Kenneth J. Shackleton" Date: Sun, 4 Feb 2024 20:05:16 +0000 Subject: [PATCH] Decouple SQLite implementation from main Android artifact, and publish a BOM. Signed-off-by: Kenneth J. Shackleton --- docs/getting_started.md | 8 +++- gradle.properties | 4 +- selekt-android-sqlcipher/build.gradle.kts | 7 +++ .../com/bloomberg/selekt/android/Loader.kt | 4 +- .../com/bloomberg/selekt/android/Loader.kt | 3 +- selekt-android/build.gradle.kts | 10 +---- .../com/bloomberg/selekt/android/SQLite.kt | 2 + selekt-bom/build.gradle.kts | 45 +++++++++++++++++++ settings.gradle.kts | 1 + 9 files changed, 70 insertions(+), 14 deletions(-) rename selekt-android/src/debug/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt => selekt-android-sqlcipher/src/debug/kotlin/com/bloomberg/selekt/android/Loader.kt (89%) rename selekt-android/src/release/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt => selekt-android-sqlcipher/src/release/kotlin/com/bloomberg/selekt/android/Loader.kt (87%) create mode 100644 selekt-bom/build.gradle.kts diff --git a/docs/getting_started.md b/docs/getting_started.md index f66a4bbb37..5d91473aa0 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -9,7 +9,9 @@ } dependencies { - implementation("com.bloomberg:selekt-android:") + implementation(platform("com.bloomberg:selekt-bom:")) + implementation("com.bloomberg:selekt-android") + implementation("com.bloomberg:selekt-android-sqlcipher") } ``` @@ -20,7 +22,9 @@ } dependencies { - implementation 'com.bloomberg:selekt-android:' + implementation platform('com.bloomberg:selekt-bom:')) + implementation 'com.bloomberg:selekt-android' + implementation 'com.bloomberg:selekt-android-sqlcipher' } ``` diff --git a/gradle.properties b/gradle.properties index cbc855296e..85a6ade78b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -selekt.versionName=0.21.0 -selekt.nextVersionName=0.22.0 +selekt.versionName=0.22.0 +selekt.nextVersionName=0.23.0 openssl.version=3.1.2 openssl.sha256=a0ce69b8b97ea6a35b96875235aa453b966ba3cba8af2de23657d8b6767d6539 diff --git a/selekt-android-sqlcipher/build.gradle.kts b/selekt-android-sqlcipher/build.gradle.kts index a383af00bc..1724b72bef 100644 --- a/selekt-android-sqlcipher/build.gradle.kts +++ b/selekt-android-sqlcipher/build.gradle.kts @@ -21,6 +21,7 @@ logger.quiet("SQLCipher version: {}", sqlcipherVersionName) plugins { id("com.android.library") + id("kotlin-android") `maven-publish` signing id("io.gitlab.arturbosch.detekt") @@ -49,6 +50,7 @@ android { } } release { + isMinifyEnabled = false ndk { abiFilters.addAll(allABIs) } @@ -65,6 +67,11 @@ android { } } +dependencies { + implementation(projects.selektJava) + implementation(projects.selektSqlite3Classes) +} + allABIs.forEach { abi -> tasks.matching { it is ExternalNativeBuildJsonTask && it.name.contains(abi) diff --git a/selekt-android/src/debug/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt b/selekt-android-sqlcipher/src/debug/kotlin/com/bloomberg/selekt/android/Loader.kt similarity index 89% rename from selekt-android/src/debug/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt rename to selekt-android-sqlcipher/src/debug/kotlin/com/bloomberg/selekt/android/Loader.kt index 8d29f1829f..0cb9abf243 100644 --- a/selekt-android/src/debug/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt +++ b/selekt-android-sqlcipher/src/debug/kotlin/com/bloomberg/selekt/android/Loader.kt @@ -16,12 +16,14 @@ package com.bloomberg.selekt.android +import com.bloomberg.selekt.ExternalSQLite +import com.bloomberg.selekt.SQLite import com.bloomberg.selekt.commons.loadEmbeddedLibrary import com.bloomberg.selekt.externalSQLiteSingleton private const val CAN_USE_EMBEDDED_PROPERTY_KEY = "com.bloomberg.selekt.lib.can_use_embedded" -internal val sqlite = externalSQLiteSingleton { +fun loadSQLite(): ExternalSQLite = externalSQLiteSingleton { "selekt".let { try { System.loadLibrary(it) diff --git a/selekt-android/src/release/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt b/selekt-android-sqlcipher/src/release/kotlin/com/bloomberg/selekt/android/Loader.kt similarity index 87% rename from selekt-android/src/release/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt rename to selekt-android-sqlcipher/src/release/kotlin/com/bloomberg/selekt/android/Loader.kt index f4f9ba89c3..f7080708e0 100644 --- a/selekt-android/src/release/kotlin/com/bloomberg/selekt/android/ExternalSQLite.kt +++ b/selekt-android-sqlcipher/src/release/kotlin/com/bloomberg/selekt/android/Loader.kt @@ -16,6 +16,7 @@ package com.bloomberg.selekt.android +import com.bloomberg.selekt.ExternalSQLite import com.bloomberg.selekt.externalSQLiteSingleton -internal val sqlite = externalSQLiteSingleton() +fun loadSQLite(): ExternalSQLite = externalSQLiteSingleton() diff --git a/selekt-android/build.gradle.kts b/selekt-android/build.gradle.kts index e60154253a..798cc02da8 100644 --- a/selekt-android/build.gradle.kts +++ b/selekt-android/build.gradle.kts @@ -42,18 +42,11 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildTypes { - debug { - buildConfigField("Boolean", "USE_EMBEDDED_LIBS", "true") - } release { isMinifyEnabled = false - buildConfigField("Boolean", "USE_EMBEDDED_LIBS", "false") buildConfigField("String", "gitCommitSha1", "\"${gitCommit()}\"") } } - arrayOf("debug", "main", "release", "test").forEach { - sourceSets[it].java.srcDir("src/$it/kotlin") - } sourceSets["test"].resources.srcDir(layout.buildDirectory.dir("intermediates/libs")) publishing { singleVariant("release") { @@ -65,8 +58,8 @@ android { dependencies { api(projects.selektApi) + compileOnly(projects.selektAndroidSqlcipher) compileOnly(androidX("room", "runtime", Versions.ANDROIDX_ROOM.version)) - implementation(projects.selektAndroidSqlcipher) implementation(projects.selektJava) implementation(projects.selektSqlite3Classes) kaptTest(androidX("room", "compiler", Versions.ANDROIDX_ROOM.version)) @@ -74,6 +67,7 @@ dependencies { testImplementation(androidX("room", "runtime", Versions.ANDROIDX_ROOM.version)) testImplementation(androidX("room", "ktx", Versions.ANDROIDX_ROOM.version)) testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT5}") + testRuntimeOnly(projects.selektAndroidSqlcipher) testRuntimeOnly("org.robolectric:android-all:${Versions.ROBOLECTRIC_ANDROID_ALL}") } diff --git a/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/SQLite.kt b/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/SQLite.kt index 0e07d848da..f7d6de7519 100644 --- a/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/SQLite.kt +++ b/selekt-android/src/main/kotlin/com/bloomberg/selekt/android/SQLite.kt @@ -52,6 +52,8 @@ import com.bloomberg.selekt.SQL_RANGE import com.bloomberg.selekt.SQL_READONLY import com.bloomberg.selekt.SQL_TOO_BIG +internal val sqlite = loadSQLite() + object Selekt { internal const val TAG = "SLKT" diff --git a/selekt-bom/build.gradle.kts b/selekt-bom/build.gradle.kts new file mode 100644 index 0000000000..7bb305d03c --- /dev/null +++ b/selekt-bom/build.gradle.kts @@ -0,0 +1,45 @@ +/* + * Copyright 2024 Bloomberg Finance L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + `java-platform` + `maven-publish` +} + +dependencies { + constraints { + projects.run { + listOf( + selektAndroid, + selektAndroidLint, + selektAndroidSqlcipher, + selektApi, + selektJava, + selektSqlite3Classes + ) + }.forEach(::api) + } +} + +publishing { + publications.register("main") { + from(components.getByName("javaPlatform")) + pom { + commonInitialisation(project) + description.set("Selekt BOM.") + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index efd9aab967..a4a8677195 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,6 +24,7 @@ include(":selekt-android") include(":selekt-android-lint") include(":selekt-android-sqlcipher") include(":selekt-api") +include(":selekt-bom") include(":selekt-java") include(":selekt-sqlite3") include(":selekt-sqlite3-classes")