From b8bd6bfbc4e67694202eb5ecd4184fb6fcdc36c6 Mon Sep 17 00:00:00 2001 From: Muhammad Rifqi Fatchurrahman Date: Mon, 1 Jan 2024 16:36:54 +0700 Subject: [PATCH] Update Project to use Gradle 8.4, AGP 8.2.0, Fix Detekt Foundings, and uses version catalog (#14) * Update Project to use Gradle 8.4, AGP 8.2.0, and uses version catalog * set jvmtoolchain to 11 * Revert "set jvmtoolchain to 11" This reverts commit 35747cbe48de7710fdb3614de4b9fce499602795. * change the build pipeline to use java 17 * fix codesmell and update some rules on detekt --- .github/workflows/verification.yml | 2 +- build.gradle | 17 +++---- detekt.yml | 4 ++ fuel/build.gradle | 30 ++++++------ fuel/src/main/AndroidManifest.xml | 2 - fuel/src/main/res/values/strings.xml | 3 -- gradle.properties | 31 ++----------- gradle/libs.versions.toml | 46 +++++++++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- parserss/build.gradle | 32 +++++++------ parserss/src/main/AndroidManifest.xml | 2 - .../muhrifqii/parserss/ParserExecutor.kt | 9 ++-- .../github/muhrifqii/parserss/ParsingMode.kt | 8 ++-- retrofit/build.gradle | 31 +++++++------ retrofit/src/main/AndroidManifest.xml | 2 - .../parserss/retrofit/ParseRSSConverter.kt | 1 - root-reportings.gradle | 8 ++-- sample/build.gradle | 38 +++++++++------ .../sample/ExampleInstrumentedTest.kt | 2 +- sample/src/main/AndroidManifest.xml | 2 +- .../parserss/sample/ExampleUnitTest.kt | 3 +- 21 files changed, 154 insertions(+), 121 deletions(-) delete mode 100644 fuel/src/main/AndroidManifest.xml delete mode 100644 fuel/src/main/res/values/strings.xml create mode 100644 gradle/libs.versions.toml delete mode 100644 parserss/src/main/AndroidManifest.xml delete mode 100644 retrofit/src/main/AndroidManifest.xml diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 3565ece..277314f 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 with: - java-version: 11 + java-version: 17 distribution: 'temurin' - uses: gradle/gradle-build-action@v2 with: diff --git a/build.gradle b/build.gradle index 0ca0af3..993e559 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,13 @@ plugins { - id 'com.android.application' version "${agp_version}" apply false - id 'com.android.library' version "${agp_version}" apply false - id 'org.jetbrains.kotlin.android' version "${kotlin_version}" apply false - id "io.gitlab.arturbosch.detekt" version "1.20.0-RC2" - id "com.diffplug.spotless" version "6.4.1" apply false + alias libs.plugins.android.library apply false + alias libs.plugins.android.application apply false + alias libs.plugins.kotlin.android apply false + alias libs.plugins.detekt + alias libs.plugins.spotless apply false } apply from: 'root-reportings.gradle' -task clean(type: Delete) { - delete rootProject.buildDir -} - detekt { - toolVersion = "1.19.0" buildUponDefaultConfig = true config = files("$projectDir/detekt.yml") parallel = true @@ -26,5 +21,5 @@ detekt { } dependencies { - detektPlugins('io.gitlab.arturbosch.detekt:detekt-formatting:1.20.0-RC2') + detektPlugins(libs.detekt.formatting) } diff --git a/detekt.yml b/detekt.yml index 11c8390..43da4a5 100644 --- a/detekt.yml +++ b/detekt.yml @@ -91,5 +91,9 @@ style: max: 3 PreferToOverPairSyntax: active: true + UnnecessaryAbstractClass: + active: true + excludes: *excludedDirs + formatting: excludes: *excludedDirs diff --git a/fuel/build.gradle b/fuel/build.gradle index da98dc8..41ab841 100644 --- a/fuel/build.gradle +++ b/fuel/build.gradle @@ -1,19 +1,23 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +plugins { + alias libs.plugins.android.library + alias libs.plugins.kotlin.android +} apply from: '../reportings.gradle' group 'com.github.muhrifqii.ParseRSS' +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} android { - compileSdkVersion compilesdk_version as int + namespace 'com.github.muhrifqii.ParseRSS' + compileSdk compilesdk_version as int //noinspection GradleDependency - buildToolsVersion buildtools_version defaultConfig { minSdkVersion minsdk_version - targetSdkVersion targetsdk_version - versionCode project_version_code as int - versionName project_version } buildTypes { release { @@ -24,14 +28,12 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':parserss') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.github.kittinunf.fuel:fuel:2.3.1' + implementation libs.fuel - testImplementation 'junit:junit:4.13.2' - testImplementation 'org.robolectric:robolectric:4.7.3' - testImplementation 'org.mockito:mockito-core:4.4.0' - testImplementation 'com.google.truth:truth:1.1.3' + testImplementation libs.junit + testImplementation libs.robolectric + testImplementation libs.mockito.core + testImplementation libs.truth } diff --git a/fuel/src/main/AndroidManifest.xml b/fuel/src/main/AndroidManifest.xml deleted file mode 100644 index a063a50..0000000 --- a/fuel/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - diff --git a/fuel/src/main/res/values/strings.xml b/fuel/src/main/res/values/strings.xml deleted file mode 100644 index 6e0cf4c..0000000 --- a/fuel/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Fuel - diff --git a/gradle.properties b/gradle.properties index 4347da0..8d5d1f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,30 +1,9 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx1536m -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app's APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn +org.gradle.jvmargs=-Xmx5g -Dfile.encoding=UTF-8 android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX android.enableJetifier=false -# Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official # Declare versions -agp_version=7.0.2 -kotlin_version=1.6.10 -compilesdk_version=31 -buildtools_version=30.0.2 -minsdk_version=14 -targetsdk_version=31 -project_version=0.6.0 -project_version_code=600 +compilesdk_version=34 +minsdk_version=16 +project_version=0.7.0 +project_version_code=700 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..9cae1e7 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,46 @@ +[versions] +agp = "8.2.0" +appcompat = "1.6.1" +constraintlayout = "2.1.4" +core-ktx = "1.12.0" +detekt = "1.23.4" +espresso-core = "3.5.1" +fuel = "2.3.1" +junit = "4.13.2" +kotlin = "1.9.21" +kotlinx-coroutines-core = "1.7.3" +material = "1.11.0" +mockito-core = "5.3.1" +ktlint = "1.0.1" +ktor = "2.3.7" +retrofit = "2.9.0" +robolectric = "4.7.3" +runner = "1.5.2" +spotless = "6.23.3" +truth = "1.1.3" + +[libraries] +appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } +constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" } +core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" } +detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } +espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso-core" } +fuel = { module = "com.github.kittinunf.fuel:fuel", version.ref = "fuel" } +junit = { module = "junit:junit", version.ref = "junit" } +kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" } +material = { module = "com.google.android.material:material", version.ref = "material" } +mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito-core" } +retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } +robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" } +runner = { module = "androidx.test:runner", version.ref = "runner" } +truth = { module = "com.google.truth:truth", version.ref = "truth" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +android-library = { id = "com.android.library", version.ref = "agp" } +android-lint = { id = "com.android.lint", version.ref = "agp" } +android-test = { id = "com.android.test", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fbce071..e411586 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-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/parserss/build.gradle b/parserss/build.gradle index c93485e..13bac5b 100644 --- a/parserss/build.gradle +++ b/parserss/build.gradle @@ -1,28 +1,30 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +plugins { + alias libs.plugins.android.library + alias libs.plugins.kotlin.android +} apply from: '../reportings.gradle' group 'com.github.muhrifqii.ParseRSS' +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + android { - compileSdkVersion compilesdk_version as int + compileSdk compilesdk_version as int + namespace 'com.github.muhrifqii.ParseRSS' //noinspection GradleDependency - buildToolsVersion buildtools_version defaultConfig { minSdkVersion minsdk_version - targetSdkVersion targetsdk_version - versionCode project_version_code as int - versionName project_version } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - - testImplementation 'junit:junit:4.13.2' - testImplementation 'org.robolectric:robolectric:4.7.3' - testImplementation 'org.mockito:mockito-core:4.4.0' - testImplementation 'com.google.truth:truth:1.1.3' - testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1" + testImplementation libs.junit + testImplementation libs.robolectric + testImplementation libs.mockito.core + testImplementation libs.truth + testImplementation libs.kotlinx.coroutines.core } diff --git a/parserss/src/main/AndroidManifest.xml b/parserss/src/main/AndroidManifest.xml deleted file mode 100644 index f6b9fd0..0000000 --- a/parserss/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - diff --git a/parserss/src/main/java/com/github/muhrifqii/parserss/ParserExecutor.kt b/parserss/src/main/java/com/github/muhrifqii/parserss/ParserExecutor.kt index c9d32e5..ca19b87 100644 --- a/parserss/src/main/java/com/github/muhrifqii/parserss/ParserExecutor.kt +++ b/parserss/src/main/java/com/github/muhrifqii/parserss/ParserExecutor.kt @@ -52,7 +52,9 @@ class ParserExecutor( if (element.name != RSSVersion.RSS_V1.elementName && element.name != RSSVersion.RSS_V2.elementName && element.name != RSSVersion.RSS_ATOM.elementName - ) return element + ) { + return element + } val attrCount = parser.attributeCount for (i in 0 until attrCount) { val attribute = parser.getRSSAttributeElement(i, pullParserNSAware) @@ -186,10 +188,11 @@ class ParserExecutor( ParseRSSKeyword.LINK -> mode[LinkEnabledObject::class.java] = { val rel = parser.getAttributeValue(XmlPullParser.NO_NAMESPACE, ParseRSSKeyword.ATTR_REL) ?: "" val href = parser.getAttributeValue(XmlPullParser.NO_NAMESPACE, ParseRSSKeyword.ATTR_HREF) - if (rel == "self" && it is RSSFeed) + if (rel == "self" && it is RSSFeed) { it.link = href - else if (rel == "alternate" && it is RSSItem) + } else if (rel == "alternate" && it is RSSItem) { it.link = href + } } ParseRSSKeyword.RIGHTS -> mode[CopyrightsEnabledObject::class.java] = { it?.copyright = parser.nextTextTrimmed() diff --git a/parserss/src/main/java/com/github/muhrifqii/parserss/ParsingMode.kt b/parserss/src/main/java/com/github/muhrifqii/parserss/ParsingMode.kt index 1f6bca2..b1086da 100644 --- a/parserss/src/main/java/com/github/muhrifqii/parserss/ParsingMode.kt +++ b/parserss/src/main/java/com/github/muhrifqii/parserss/ParsingMode.kt @@ -113,9 +113,11 @@ sealed class ParsingMode(val nameToken: String) : ParsingModeOperation { is Read -> return is MediaNS.Group -> { val item = modes.lastValue() - if (item !is Item) throw ParseRSSException( - "Error ${other.nameToken} should be under the item element", - ) + if (item !is Item) { + throw ParseRSSException( + "Error ${other.nameToken} should be under the item element", + ) + } other.rssObject = item.rssObject } is Author -> { diff --git a/retrofit/build.gradle b/retrofit/build.gradle index 5b1b411..c6c28f8 100644 --- a/retrofit/build.gradle +++ b/retrofit/build.gradle @@ -1,18 +1,23 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +plugins { + alias libs.plugins.android.library + alias libs.plugins.kotlin.android +} apply from: '../reportings.gradle' group 'com.github.muhrifqii.ParseRSS' +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + android { - compileSdkVersion compilesdk_version as int + namespace 'com.github.muhrifqii.ParseRSS' + compileSdk compilesdk_version as int //noinspection GradleDependency - buildToolsVersion buildtools_version defaultConfig { minSdkVersion minsdk_version - targetSdkVersion targetsdk_version - versionCode project_version_code as int - versionName project_version } buildTypes { release { @@ -23,14 +28,12 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':parserss') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.squareup.retrofit2:retrofit:2.9.0' + implementation libs.retrofit - testImplementation 'junit:junit:4.13.2' - testImplementation 'org.robolectric:robolectric:4.7.3' - testImplementation 'org.mockito:mockito-core:4.4.0' - testImplementation 'com.google.truth:truth:1.1.3' + testImplementation libs.junit + testImplementation libs.robolectric + testImplementation libs.mockito.core + testImplementation libs.truth } diff --git a/retrofit/src/main/AndroidManifest.xml b/retrofit/src/main/AndroidManifest.xml deleted file mode 100644 index 4359ce4..0000000 --- a/retrofit/src/main/AndroidManifest.xml +++ /dev/null @@ -1,2 +0,0 @@ - diff --git a/retrofit/src/main/java/com/github/muhrifqii/parserss/retrofit/ParseRSSConverter.kt b/retrofit/src/main/java/com/github/muhrifqii/parserss/retrofit/ParseRSSConverter.kt index e713b37..1c019d4 100644 --- a/retrofit/src/main/java/com/github/muhrifqii/parserss/retrofit/ParseRSSConverter.kt +++ b/retrofit/src/main/java/com/github/muhrifqii/parserss/retrofit/ParseRSSConverter.kt @@ -21,7 +21,6 @@ class ParseRSSConverterFactory private constructor() : Converter.Fa annotations: Array, retrofit: Retrofit ): Converter { - return ParseRSSConverter() } diff --git a/root-reportings.gradle b/root-reportings.gradle index da7c8c6..0c6184c 100644 --- a/root-reportings.gradle +++ b/root-reportings.gradle @@ -1,10 +1,10 @@ apply plugin: 'jacoco' -jacoco { - toolVersion '0.8.7' -} +//jacoco { +// toolVersion '0.8.7' +//} -tasks.withType(Test) { +tasks.withType(Test).configureEach { jacoco.includeNoLocationClasses = true } diff --git a/sample/build.gradle b/sample/build.gradle index 3d4ed76..18e45c9 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,16 +1,24 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' +plugins { + alias libs.plugins.android.application + alias libs.plugins.kotlin.android +} + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} android { - compileSdkVersion compilesdk_version as int + compileSdk compilesdk_version as int + namespace 'com.github.muhrifqii.parserss.sample' //noinspection GradleDependency - buildToolsVersion buildtools_version defaultConfig { applicationId "com.github.muhrifqii.parserss.sample" minSdkVersion minsdk_version - targetSdkVersion targetsdk_version versionCode project_version_code as int versionName project_version + multiDexEnabled true } buildTypes { release { @@ -21,20 +29,20 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'androidx.core:core-ktx:1.7.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.3' - implementation 'com.google.android.material:material:1.5.0' + implementation libs.appcompat + implementation libs.core.ktx + implementation libs.constraintlayout + implementation libs.material + + implementation libs.fuel - implementation 'com.github.kittinunf.fuel:fuel:2.3.1' + implementation "androidx.multidex:multidex:2.0.1" implementation project(':parserss') implementation project(':fuel') implementation project(':retrofit') - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test:runner:1.4.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + testImplementation libs.junit + androidTestImplementation libs.runner + androidTestImplementation libs.espresso.core } diff --git a/sample/src/androidTest/java/com/github/muhrifqii/parserss/sample/ExampleInstrumentedTest.kt b/sample/src/androidTest/java/com/github/muhrifqii/parserss/sample/ExampleInstrumentedTest.kt index 6712224..ce71df1 100644 --- a/sample/src/androidTest/java/com/github/muhrifqii/parserss/sample/ExampleInstrumentedTest.kt +++ b/sample/src/androidTest/java/com/github/muhrifqii/parserss/sample/ExampleInstrumentedTest.kt @@ -2,11 +2,11 @@ package com.github.muhrifqii.parserss.sample import androidx.test.InstrumentationRegistry import androidx.test.runner.AndroidJUnit4 +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* /** * Instrumented test, which will execute on an Android device. diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index 59d595b..5eb7e52 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools">