diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 32cecce2..1be4eb75 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Run detekt with ktlint run: ./gradlew detektBundledDebug detektUnbundledDebug @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Run bundled and unbundled unit tests run: ./gradlew test @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Build debug bundled sample app run: ./gradlew :sample:assembleBundledDebug @@ -43,6 +43,6 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Build debug unbundled sample app run: ./gradlew :sample:assembleUnbundledDebug \ No newline at end of file diff --git a/README.md b/README.md index f77d7c8f..b3b248b0 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ There are two different flavors available on `mavenCentral()`: | V3 model is used (faster, more accurate) | currently V1 model will be downloaded ```kotlin // bundled: -implementation("io.github.g00fy2.quickie:quickie-bundled:1.4.0") +implementation("io.github.g00fy2.quickie:quickie-bundled:1.4.1") // unbundled: -implementation("io.github.g00fy2.quickie:quickie-unbundled:1.4.0") +implementation("io.github.g00fy2.quickie:quickie-unbundled:1.4.1") ``` ## Quick Start diff --git a/build.gradle.kts b/build.gradle.kts index 0801d16e..4df32cf0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,23 +3,24 @@ import io.gitlab.arturbosch.detekt.Detekt import io.gitlab.arturbosch.detekt.extensions.DetektExtension import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +@Suppress("DSL_SCOPE_VIOLATION") plugins { - id(Plugins.Android.application) version Versions.androidGradle apply false - kotlin(Plugins.Kotlin.androidGradle) version Versions.kotlin apply false - id(Plugins.Misc.detekt) version Versions.detekt apply false - id(Plugins.Misc.gradleVersions) version Versions.gradleVersions + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.androidGradle) apply false + alias(libs.plugins.misc.detekt) apply false + alias(libs.plugins.misc.gradleVersions) } subprojects { - apply(plugin = Plugins.Misc.detekt) + apply(plugin = rootProject.libs.plugins.misc.detekt.get().pluginId) extensions.configure { - toolVersion = Versions.detekt + toolVersion = rootProject.libs.versions.detekt.get() config = files("$rootDir/detekt.yml") buildUponDefaultConfig = true ignoredBuildTypes = listOf("release") } dependencies { - "detektPlugins"(Plugins.Misc.detektFormatting) + add("detektPlugins", rootProject.libs.misc.detektFormatting) } tasks.withType().configureEach { jvmTarget = "1.8" @@ -36,6 +37,12 @@ subprojects { } afterEvaluate { extensions.configure { + compileSdkVersion(libs.versions.androidconfig.compileSdk.get().toInt()) + buildToolsVersion(libs.versions.androidconfig.buildTools.get()) + defaultConfig { + minSdk = libs.versions.androidconfig.minSdk.get().toInt() + targetSdk = libs.versions.androidconfig.targetSdk.get().toInt() + } compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -46,7 +53,14 @@ subprojects { tasks.dependencyUpdates.configure { gradleReleaseChannel = "current" - rejectVersionIf { Versions.maturityLevel(candidate.version) < Versions.maturityLevel(currentVersion) } + + fun releaseType(version: String): Int { + val qualifiers = listOf("alpha", "beta", "m", "rc") + val index = qualifiers.indexOfFirst { version.matches(".*[.\\-]$it[.\\-\\d]*".toRegex(RegexOption.IGNORE_CASE)) } + return if (index < 0) qualifiers.size else index + } + + rejectVersionIf { releaseType(candidate.version) < releaseType(currentVersion) } } tasks.register("clean") { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 157c5567..00000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,12 +0,0 @@ -plugins { - `kotlin-dsl` -} - -repositories { - mavenCentral() -} - -tasks.withType().configureEach { - sourceCompatibility = "1.8" - targetCompatibility = "1.8" -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt deleted file mode 100644 index 5253cd51..00000000 --- a/buildSrc/src/main/kotlin/Deps.kt +++ /dev/null @@ -1,25 +0,0 @@ -object Deps { - - object AndroidX { - const val appcompat = "androidx.appcompat:appcompat:${Versions.appcompat}" - - const val camera = "androidx.camera:camera-camera2:${Versions.cameraX}" - const val cameraLifecycle = "androidx.camera:camera-lifecycle:${Versions.cameraX}" - const val cameraPreview = "androidx.camera:camera-view:${Versions.cameraView}" - } - - object MLKit { - const val barcodeScanning = "com.google.mlkit:barcode-scanning:${Versions.barcodeScanning}" - const val barcodeScanningGms = - "com.google.android.gms:play-services-mlkit-barcode-scanning:${Versions.barcodeScanningGms}" - } - - object UI { - const val materialDesign = "com.google.android.material:material:${Versions.materialDesign}" - } - - object Test { - const val junitApi = "org.junit.jupiter:junit-jupiter-api:${Versions.junit}" - const val junitEngine = "org.junit.jupiter:junit-jupiter-engine:${Versions.junit}" - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Plugins.kt b/buildSrc/src/main/kotlin/Plugins.kt deleted file mode 100644 index 5f49d62c..00000000 --- a/buildSrc/src/main/kotlin/Plugins.kt +++ /dev/null @@ -1,20 +0,0 @@ -object Plugins { - - object Android { - const val application = "com.android.application" - const val library = "com.android.library" - } - - object Kotlin { - const val androidGradle = "android" - const val android = "kotlin-android" - const val parcelize = "kotlin-parcelize" - const val dokka = "org.jetbrains.dokka" - } - - object Misc { - const val detekt = "io.gitlab.arturbosch.detekt" - const val detektFormatting = "io.gitlab.arturbosch.detekt:detekt-formatting:${Versions.detekt}" - const val gradleVersions = "com.github.ben-manes.versions" - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt deleted file mode 100644 index d4ea424c..00000000 --- a/buildSrc/src/main/kotlin/Versions.kt +++ /dev/null @@ -1,36 +0,0 @@ -object Versions { - - const val quickie = "1.4.0" - - const val androidMinSdk = 21 - const val androidCompileSdk = 31 - const val androidTargetSdk = 31 - const val androidBuildTools = "31.0.0" - - const val androidGradle = "7.0.4" - const val kotlin = "1.6.10" - - const val appcompat = "1.4.1" - - const val cameraX = "1.0.2" - const val cameraView = "1.0.0-alpha32" - - const val barcodeScanning = "17.0.1" - const val barcodeScanningGms = "17.0.0" - - const val materialDesign = "1.5.0" - - const val detekt = "1.19.0" - const val gradleVersions = "0.41.0" - const val dokka = "1.6.10" - - const val junit = "5.8.2" - - fun maturityLevel(version: String): Int { - val levels = listOf("alpha", "beta", "m", "rc") - levels.forEachIndexed { index, s -> - if (version.matches(".*[.\\-]$s[.\\-\\d]*".toRegex(RegexOption.IGNORE_CASE))) return index - } - return levels.size - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..9cec0432 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,54 @@ +[versions] +quickie = "1.4.1" + +androidconfig-minSdk = "21" +androidconfig-compileSdk = "31" +androidconfig-targetSdk = "31" +androidconfig-buildTools = "31.0.0" + +androidGradle = "7.1.2" +kotlin = "1.6.20" + +appcompat = "1.4.1" + +cameraX = "1.0.2" +cameraView = "1.0.0-alpha32" + +barcodeScanning = "17.0.2" +barcodeScanningGms = "18.0.0" + +materialDesign = "1.5.0" + +detekt = "1.19.0" +gradleVersions = "0.42.0" +dokka = "1.6.10" + +junit = "5.8.2" + +[libraries] +androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } +androidx-camera = { module = "androidx.camera:camera-camera2", version.ref = "cameraX" } +androidx-cameraLifecycle = { module = "androidx.camera:camera-lifecycle", version.ref = "cameraX" } +androidx-cameraPreview = { module = "androidx.camera:camera-view", version.ref = "cameraView" } + +mlkit-barcodeScanning = { module = "com.google.mlkit:barcode-scanning", version.ref = "barcodeScanning" } +mlkit-barcodeScanningGms = { module = "com.google.android.gms:play-services-mlkit-barcode-scanning", version.ref = "barcodeScanningGms" } + +google-materialDesign = { module = "com.google.android.material:material", version.ref = "materialDesign" } + +test-junitApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } +test-junitEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" } + +misc-detektFormatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "androidGradle" } +android-library = { id = "com.android.library", version.ref = "androidGradle" } + +kotlin-androidGradle = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-android = { id = "kotlin-android", version.ref = "kotlin" } +kotlin-parcelize = { id = "kotlin-parcelize", version.ref = "kotlin" } +kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } + +misc-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } +misc-gradleVersions = { id = "com.github.ben-manes.versions", version.ref = "gradleVersions" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f..41d9927a 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e5897..aa991fce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew.bat b/gradlew.bat index 107acd32..ac1b06f9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/quickie/build.gradle.kts b/quickie/build.gradle.kts index 208dfd21..6be6a705 100644 --- a/quickie/build.gradle.kts +++ b/quickie/build.gradle.kts @@ -1,15 +1,14 @@ +@Suppress("DSL_SCOPE_VIOLATION") plugins { - id(Plugins.Android.library) - id(Plugins.Kotlin.android) - id(Plugins.Kotlin.parcelize) - id(Plugins.Kotlin.dokka) version Versions.dokka + id(libs.plugins.android.library.get().pluginId) + id(libs.plugins.kotlin.android.get().pluginId) + id(libs.plugins.kotlin.parcelize.get().pluginId) + alias(libs.plugins.kotlin.dokka) `maven-publish` signing } android { - compileSdk = Versions.androidCompileSdk - defaultConfig.minSdk = Versions.androidMinSdk resourcePrefix = "quickie" buildFeatures { viewBinding = true @@ -21,29 +20,31 @@ android { create("unbundled").dimension = "mlkit" } sourceSets { - getByName("main").java.srcDirs("src/main/kotlin") getByName("bundled").java.srcDirs("src/bundled/kotlin") getByName("unbundled").java.srcDirs("src/unbundled/kotlin") - getByName("test").java.srcDirs("src/test/kotlin") + } + publishing { + singleVariant("bundledRelease") + singleVariant("unbundledRelease") } } dependencies { - implementation(Deps.AndroidX.appcompat) + implementation(libs.androidx.appcompat) - implementation(Deps.AndroidX.camera) - implementation(Deps.AndroidX.cameraLifecycle) - implementation(Deps.AndroidX.cameraPreview) + implementation(libs.androidx.camera) + implementation(libs.androidx.cameraLifecycle) + implementation(libs.androidx.cameraPreview) - "bundledImplementation"(Deps.MLKit.barcodeScanning) - "unbundledImplementation"(Deps.MLKit.barcodeScanningGms) + add("bundledImplementation", libs.mlkit.barcodeScanning) + add("unbundledImplementation", libs.mlkit.barcodeScanningGms) - testImplementation(Deps.Test.junitApi) - testRuntimeOnly(Deps.Test.junitEngine) + testImplementation(libs.test.junitApi) + testRuntimeOnly(libs.test.junitEngine) } group = "io.github.g00fy2.quickie" -version = Versions.quickie +version = libs.versions.quickie.get() tasks.register("androidJavadocJar") { archiveClassifier.set("javadoc") diff --git a/quickie/src/test/kotlin/io/github/g00fy2/quickie/BarcodeFormatsTest.kt b/quickie/src/test/kotlin/io/github/g00fy2/quickie/BarcodeFormatsTest.kt index 4f8103bd..15db7eb5 100644 --- a/quickie/src/test/kotlin/io/github/g00fy2/quickie/BarcodeFormatsTest.kt +++ b/quickie/src/test/kotlin/io/github/g00fy2/quickie/BarcodeFormatsTest.kt @@ -13,10 +13,9 @@ internal class BarcodeFormatsTest { .filter { it.type == Int::class.java } .filter { it.name.startsWith("FORMAT_") } .filter { it.name != "FORMAT_UNKNOWN" } - .map { it.name to it.getInt(null) } - .toMap() + .associate { it.name to it.getInt(null) } - val quickieBarcodeFormats: Map = BarcodeFormat.values().map { it.name to it.value }.toMap() + val quickieBarcodeFormats: Map = BarcodeFormat.values().associate { it.name to it.value } assertEquals(mlKitBarcodeFormats, quickieBarcodeFormats) } diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index cf27e4ae..3b4568a1 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -1,15 +1,12 @@ +@Suppress("DSL_SCOPE_VIOLATION") plugins { - id(Plugins.Android.application) - id(Plugins.Kotlin.android) + id(libs.plugins.android.application.get().pluginId) + id(libs.plugins.kotlin.android.get().pluginId) } android { - compileSdk = Versions.androidCompileSdk - buildToolsVersion = Versions.androidBuildTools defaultConfig { applicationId = "io.github.g00fy2.quickiesample" - minSdk = Versions.androidMinSdk - targetSdk = Versions.androidTargetSdk versionCode = 1 versionName = "1.0" } @@ -36,11 +33,10 @@ android { buildFeatures { viewBinding = true } - sourceSets.getByName("main").java.srcDirs("src/main/kotlin") } dependencies { implementation(project(":quickie")) - implementation(Deps.UI.materialDesign) + implementation(libs.google.materialDesign) } \ No newline at end of file diff --git a/sample/src/main/kotlin/io/github/g00fy2/quickiesample/SampleApp.kt b/sample/src/main/kotlin/io/github/g00fy2/quickiesample/SampleApp.kt index c5853c74..de8a6a22 100644 --- a/sample/src/main/kotlin/io/github/g00fy2/quickiesample/SampleApp.kt +++ b/sample/src/main/kotlin/io/github/g00fy2/quickiesample/SampleApp.kt @@ -4,7 +4,6 @@ import android.app.Application import android.os.StrictMode import androidx.viewbinding.BuildConfig -@Suppress("unused") class SampleApp : Application() { override fun onCreate() {