Skip to content

Commit

Permalink
Modernize build & update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tfcporciuncula committed Apr 9, 2023
1 parent 0b0d825 commit e34ae6b
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 95 deletions.
20 changes: 20 additions & 0 deletions .detekt/detekt.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
complexity:
TooManyFunctions:
active: false

empty-blocks:
EmptyClassBlock:
active: false # Overlaps with NoEmptyClassBody from ktlint

formatting:
Indentation:
indentSize: 2

naming:
MatchingDeclarationName:
active: false # Overlaps with Filename from ktlint

style:
MaxLineLength:
active: false # Overlaps with MaximumLineLength from ktlint
ModifierOrder:
active: false # Overlaps with ModifierOrdering from ktlint
NewLineAtEndOfFile:
active: false # Overlaps with FinalNewline from ktlint
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ jobs:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}

- name: Ktlint
run: ./gradlew lintKotlin

- name: Detekt
run: ./gradlew detekt
run: ./gradlew detektMain

instrumentation-tests:
name: Instrumentation Tests
Expand All @@ -49,7 +46,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v1
with:
Expand Down
38 changes: 7 additions & 31 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
buildscript {
repositories {
mavenCentral()
google()
maven { url 'https://plugins.gradle.org/m2/' }
}

dependencies {
classpath libs.gradle.agp
classpath libs.gradle.kotlin
classpath libs.gradle.kotlinter
classpath libs.gradle.detekt
classpath libs.gradle.publish
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.detekt) apply false
}

ext.buildConfig = [
'minSdk' : 14,
'compileSdk': 33,
'targetSdk' : 33,
]

subprojects {
repositories {
mavenCentral()
google()
}

apply from: rootProject.file('ktlint.gradle')
apply from: rootProject.file('detekt.gradle')
}

task clean(type: Delete) {
delete rootProject.buildDir
apply from: rootProject.file('gradle/android.gradle')
apply from: rootProject.file('gradle/detekt.gradle')
}
16 changes: 5 additions & 11 deletions flow-preferences-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}

android {
compileSdkVersion buildConfig.compileSdk
namespace 'com.fredporciuncula.flow.preferences.sample'

defaultConfig {
applicationId 'com.fredporciuncula.flow.preferences.sample'
minSdkVersion buildConfig.minSdk
targetSdkVersion buildConfig.targetSdk
versionCode 1
versionName '1.0'

multiDexEnabled true
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}

buildFeatures {
Expand Down
13 changes: 5 additions & 8 deletions flow-preferences-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}

android {
compileSdkVersion buildConfig.compileSdk
namespace 'com.fredporciuncula.flow.preferences.tests'

defaultConfig {
minSdkVersion 26
targetSdkVersion buildConfig.targetSdk

multiDexEnabled true

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
}
Expand Down
14 changes: 6 additions & 8 deletions flow-preferences/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.vanniktech.maven.publish'
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.mavenPublish)
}

android {
compileSdkVersion buildConfig.compileSdk

defaultConfig {
minSdkVersion buildConfig.minSdk
}
namespace 'com.fredporciuncula.flow.preferences'
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion flow-preferences/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class StringPreference(
private val coroutineContext: CoroutineContext
) : BasePreference<String>(key, keyFlow, sharedPreferences, coroutineContext) {

override fun get() = sharedPreferences.getString(key, defaultValue)!!
override fun get() = checkNotNull(sharedPreferences.getString(key, defaultValue))

override fun set(value: String) = sharedPreferences.edit().putString(key, value).apply()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class StringSetOfNullablesPreference(
private val coroutineContext: CoroutineContext
) : BasePreference<Set<String?>>(key, keyFlow, sharedPreferences, coroutineContext) {

override fun get(): Set<String?> = sharedPreferences.getStringSet(key, defaultValue)!!
override fun get(): Set<String?> = checkNotNull(sharedPreferences.getStringSet(key, defaultValue))

override fun set(value: Set<String?>) = sharedPreferences.edit().putStringSet(key, value).apply()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class StringSetPreference(
private val coroutineContext: CoroutineContext
) : BasePreference<Set<String>>(key, keyFlow, sharedPreferences, coroutineContext) {

override fun get(): Set<String> = sharedPreferences.getStringSet(key, defaultValue)!!
override fun get(): Set<String> = checkNotNull(sharedPreferences.getStringSet(key, defaultValue))

override fun set(value: Set<String>) = sharedPreferences.edit().putStringSet(key, value).apply()

Expand Down
21 changes: 21 additions & 0 deletions gradle/android.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
afterEvaluate { project ->
if (project.hasProperty('android')) {
android {
compileSdkVersion 33

defaultConfig {
minSdkVersion 14
targetSdkVersion 33
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
}
}
6 changes: 5 additions & 1 deletion detekt.gradle → gradle/detekt.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: libs.plugins.detekt.get().pluginId

detekt {
buildUponDefaultConfig = true
config = files("$rootProject.rootDir/.detekt/detekt.yml")
}

dependencies {
detektPlugins libs.detekt.ktlint
}
23 changes: 13 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
[versions]
agp = '7.4.1'
agp = '7.4.2'
androidx-appCompat = '1.6.1'
androidx-coreKtx = '1.9.0'
androidx-lifecycle = '2.5.1'
androidx-lifecycle = '2.6.1'
androidx-preference = '1.2.0'
androidx-constraintLayout = '2.1.4'
androidx-test-coreKtx = '1.5.0'
androidx-test-espresso = '3.5.1'
androidx-test-junitKtx = '1.1.5'
coroutines = '1.6.4'
detekt = '1.22.0'
kotlin = '1.8.10'
kotlinter = '3.13.0'
publish = '0.18.0'
kotlin = '1.8.20'
mavenPublish = '0.18.0'
truth = '1.1.3'

[libraries]
Expand All @@ -26,9 +25,13 @@ androidx-test-espresso = { group = 'androidx.test.espresso', name = 'espresso-co
androidx-test-junitKtx = { group = 'androidx.test.ext', name = 'junit-ktx', version.ref = 'androidx-test-junitKtx' }
coroutines-core = { group = 'org.jetbrains.kotlinx', name = 'kotlinx-coroutines-core', version.ref = 'coroutines' }
coroutines-android = { group = 'org.jetbrains.kotlinx', name = 'kotlinx-coroutines-android', version.ref = 'coroutines' }
gradle-agp = { group = 'com.android.tools.build', name = 'gradle', version.ref = 'agp' }
gradle-kotlin = { group = 'org.jetbrains.kotlin', name = 'kotlin-gradle-plugin', version.ref = 'kotlin' }
gradle-kotlinter = { group = 'org.jmailen.gradle', name = 'kotlinter-gradle', version.ref = 'kotlinter' }
gradle-detekt = { group = 'io.gitlab.arturbosch.detekt', name = 'detekt-gradle-plugin', version.ref = 'detekt' }
gradle-publish = { group = 'com.vanniktech', name = 'gradle-maven-publish-plugin', version.ref = 'publish' }
detekt-ktlint = { module = 'io.gitlab.arturbosch.detekt:detekt-formatting', version.ref = 'detekt' }
truth = { group = 'com.google.truth', name = 'truth', version.ref = 'truth' }

[plugins]
android-application = { id = 'com.android.application', version.ref = 'agp' }
android-library = { id = 'com.android.library', version.ref = 'agp' }
detekt = { id = 'io.gitlab.arturbosch.detekt', version.ref = 'detekt' }
kotlin-android = { id = 'org.jetbrains.kotlin.android', version.ref = 'kotlin' }
kotlinter = { id = 'org.jmailen.gradle:kotlinter' }
mavenPublish = { id = 'com.vanniktech.maven.publish', version.ref = 'mavenPublish' }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 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
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
5 changes: 0 additions & 5 deletions ktlint.gradle

This file was deleted.

25 changes: 20 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
include ':flow-preferences'
include ':flow-preferences-tests'
include ':flow-preferences-sample'
pluginManagement {
repositories {
mavenCentral()
google()
gradlePluginPortal()
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
google()
}
}

// https://docs.gradle.org/current/userguide/declaring_dependencies.html#sec:type-safe-project-accessors
enableFeaturePreview('TYPESAFE_PROJECT_ACCESSORS')

rootProject.name = 'flow-preferences-root'

enableFeaturePreview("VERSION_CATALOGS")
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
include ':flow-preferences'
include ':flow-preferences-tests'
include ':flow-preferences-sample'

0 comments on commit e34ae6b

Please sign in to comment.