Допиливание системы зависимостей

This commit is contained in:
2023-04-08 22:26:14 +03:00
parent fe2acddc44
commit dbc528b45d
5 changed files with 108 additions and 71 deletions
+1
View File
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
+15 -2
View File
@@ -56,16 +56,29 @@ android {
} }
tasks.register("connectToWSA"){
}
dependencies { dependencies {
//std lib //std lib
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
//app libs /* //app libs
implementation(AppDependencies.appLibraries) implementation(AppDependencies.appLibraries)
//test libs //test libs
testImplementation(AppDependencies.testLibraries) testImplementation(AppDependencies.testLibraries)
androidTestImplementation(AppDependencies.androidTestLibraries) androidTestImplementation(AppDependencies.androidTestLibraries)
coreLibraryDesugaring(AppDependencies.desugaringLibraries) coreLibraryDesugaring(AppDependencies.desugaringLibraries)
debugImplementation(AppDependencies.debugLibraries) debugImplementation(AppDependencies.debugLibraries)*/
//app libs
implementation(AppLibraries)
//test libs
testImplementation(TestLibraries)
androidTestImplementation(AndroidTestLibraries)
coreLibraryDesugaring(DesugaringLibraries)
debugImplementation(DebugLibraries)
} }
@@ -1,8 +1,6 @@
package ru.megboyzz.dnevnik package ru.megboyzz.dnevnik
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.window.SplashScreen
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
@@ -12,7 +10,6 @@ import ru.megboyzz.dnevnik.navigation.AppNavHost
import ru.megboyzz.dnevnik.ui.theme.* import ru.megboyzz.dnevnik.ui.theme.*
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
+76 -64
View File
@@ -1,88 +1,74 @@
import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.artifacts.dsl.DependencyHandler
//TODO - придумать обработчик зависмостей основанный на рефлексии //TODO - придумать обработчик зависмостей основанный на рефлексии
object AppDependencies {
object AppLibraries: DependencyList() {
//std lib //std lib
val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}" val kotlinStdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}"
//android ui //android ui
private val appcompat = "androidx.appcompat:appcompat:${Versions.appcompat}" val appcompat = "androidx.appcompat:appcompat:${Versions.appcompat}"
private val coreKtx = "androidx.core:core-ktx:${Versions.coreKtx}" val coreKtx = "androidx.core:core-ktx:${Versions.coreKtx}"
private val lifecycleRuntimeKtx = "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" val lifecycleRuntimeKtx = "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"
//compose //compose
private val composeConstraintLayout = val composeConstraintLayout =
"androidx.constraintlayout:constraintlayout-compose:1.0.1" "androidx.constraintlayout:constraintlayout-compose:1.0.1"
private val composeUi = "androidx.compose.ui:ui:${Versions.compose}" val composeUi = "androidx.compose.ui:ui:${Versions.compose}"
private val composeMaterial = "androidx.compose.material:material:${Versions.compose}" val composeMaterial = "androidx.compose.material:material:${Versions.compose}"
private val composePreview = "androidx.compose.ui:ui-tooling-preview:${Versions.compose}" val composePreview = "androidx.compose.ui:ui-tooling-preview:${Versions.compose}"
private val composeActivity = "androidx.activity:activity-compose:1.7.0" val composeActivity = "androidx.activity:activity-compose:1.7.0"
private val composeIcons = "androidx.compose.material:material-icons-extended:${Versions.compose}" val composeIcons = "androidx.compose.material:material-icons-extended:${Versions.compose}"
private val composeGraphics = "androidx.compose.ui:ui-graphics:${Versions.compose}" val composeGraphics = "androidx.compose.ui:ui-graphics:${Versions.compose}"
//navigation
val composeNavigation = "androidx.navigation:navigation-compose:2.5.3"
//other
val pieChartLib = "com.github.PhilJay:MPAndroidChart:v3.1.0"
val retrofit = "com.squareup.retrofit2:retrofit:2.6.4"
val retrofitConverterGson = "com.squareup.retrofit2:converter-gson:2.3.0"
val accompanist = "com.google.accompanist:accompanist-swiperefresh:0.23.0"
val lazyHorizontalGrid = "androidx.compose.foundation:foundation:1.3.1"
val calendar = "com.kizitonwose.calendar:compose:2.1.1"
val asyncImage = "io.coil-kt:coil-compose:2.2.0"
}
object DebugLibraries: DependencyList() {
//compose-debug //compose-debug
private val composeUiTooling = "androidx.compose.ui:ui-tooling:${Versions.compose}" private val composeUiTooling = "androidx.compose.ui:ui-tooling:${Versions.compose}"
private val composeTestManifest = "androidx.compose.ui:ui-test-manifest:${Versions.compose}" private val composeTestManifest = "androidx.compose.ui:ui-test-manifest:${Versions.compose}"
//navigation }
private val composeNavigation = "androidx.navigation:navigation-compose:2.5.3"
//other object DesugaringLibraries: DependencyList() {
private val pieChartLib = "com.github.PhilJay:MPAndroidChart:v3.1.0"
private val retrofit = "com.squareup.retrofit2:retrofit:2.6.4" val desugarJdk = "com.android.tools:desugar_jdk_libs:${Versions.desugarJdkVersion}"
private val retrofitConverterGson = "com.squareup.retrofit2:converter-gson:2.3.0"
private val accompanist = "com.google.accompanist:accompanist-swiperefresh:0.23.0" }
private val lazyHorizontalGrid = "androidx.compose.foundation:foundation:1.3.1"
private val calendar = "com.kizitonwose.calendar:compose:2.1.1" object AndroidTestLibraries: DependencyList() {
private val asyncImage = "io.coil-kt:coil-compose:2.2.0"
//test libs //test libs
private val junit = "junit:junit:${Versions.junit}" val extJUnit = "androidx.test.ext:junit:${Versions.extJunit}"
private val extJUnit = "androidx.test.ext:junit:${Versions.extJunit}" val espressoCore = "androidx.test.espresso:espresso-core:${Versions.espresso}"
private val espressoCore = "androidx.test.espresso:espresso-core:${Versions.espresso}"
//desugaring
private val desugarJdk = "com.android.tools:desugar_jdk_libs:${Versions.desugarJdkVersion}"
val appLibraries = arrayListOf<String>().apply {
add(kotlinStdLib)
add(coreKtx)
add(appcompat)
add(composeConstraintLayout)
add(composeUi)
add(composeMaterial)
add(composePreview)
add(composeActivity)
add(composeIcons)
add(pieChartLib)
add(composeNavigation)
add(retrofit)
add(retrofitConverterGson)
add(accompanist)
add(lazyHorizontalGrid)
add(asyncImage)
add(calendar)
}
val desugaringLibraries = arrayListOf<String>().apply {
add(desugarJdk)
}
val debugLibraries = arrayListOf<String>().apply {
add(composeUiTooling)
add(composeTestManifest)
}
val androidTestLibraries = arrayListOf<String>().apply {
add(extJUnit)
add(espressoCore)
}
val testLibraries = arrayListOf<String>().apply {
add(junit)
}
} }
object TestLibraries: DependencyList() {
//test libs
private val junit = "junit:junit:${Versions.junit}"
}
/**
* Старый подход
* создать переменную список зависимостей
* раньше это был целый класс, котором объявлялись переменные
*/
//util functions for adding the different type dependencies from build.gradle file //util functions for adding the different type dependencies from build.gradle file
@@ -92,32 +78,58 @@ fun DependencyHandler.kapt(list: List<String>) {
} }
} }
fun DependencyHandler.kapt(list: DependencyList){
this.kapt(list.list())
}
fun DependencyHandler.implementation(list: List<String>) { fun DependencyHandler.implementation(list: List<String>) {
list.forEach { dependency -> list.forEach { dependency ->
add("implementation", dependency) add("implementation", dependency)
} }
} }
fun DependencyHandler.implementation(list: DependencyList){
this.implementation(list.list())
}
fun DependencyHandler.testImplementation(list: List<String>){ fun DependencyHandler.testImplementation(list: List<String>){
list.forEach { dependency -> list.forEach { dependency ->
add("testImplementation", dependency) add("testImplementation", dependency)
} }
} }
fun DependencyHandler.testImplementation(list: DependencyList){
this.testImplementation(list.list())
}
fun DependencyHandler.androidTestImplementation(list: List<String>){ fun DependencyHandler.androidTestImplementation(list: List<String>){
list.forEach { dependency -> list.forEach { dependency ->
add("androidTestImplementation", dependency) add("androidTestImplementation", dependency)
} }
} }
fun DependencyHandler.androidTestImplementation(list: DependencyList){
this.androidTestImplementation(list.list())
}
fun DependencyHandler.coreLibraryDesugaring(list: List<String>){ fun DependencyHandler.coreLibraryDesugaring(list: List<String>){
list.forEach { dependency -> list.forEach { dependency ->
add("coreLibraryDesugaring", dependency) add("coreLibraryDesugaring", dependency)
} }
} }
fun DependencyHandler.coreLibraryDesugaring(list: DependencyList){
this.coreLibraryDesugaring(list.list())
}
fun DependencyHandler.debugImplementation(list: List<String>){ fun DependencyHandler.debugImplementation(list: List<String>){
list.forEach { dependency -> list.forEach { dependency ->
add("debugImplementation", dependency) add("debugImplementation", dependency)
} }
} }
fun DependencyHandler.debugImplementation(list: DependencyList){
this.debugImplementation(list.list())
}
+14
View File
@@ -0,0 +1,14 @@
open class DependencyList {
fun list(): List<String>{
val list = mutableListOf<String>()
this::class.java.methods.filter {
it.name.startsWith("get")
}.forEach {
if(it.returnType.name == "java.lang.String")
list.add(it.invoke(this).toString())
}
return list
}
}