Skip to content

Commit

Permalink
opt: Config
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiMengjie committed Dec 5, 2021
1 parent 402cc73 commit e40b6d4
Show file tree
Hide file tree
Showing 47 changed files with 968 additions and 959 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

dependencies {
for (def entrySet : ConfigUtils.getApplyPlugins().entrySet()) {
classpath entrySet.value.dep
classpath entrySet.value.path
}
}
}
Expand All @@ -29,7 +29,7 @@ allprojects {

resolutionStrategy.eachDependency {
if (it.requested.group == 'com.android.support' && !it.requested.name.contains(
'multidex')) {
'multidex')) {
it.useVersion Config.supportVersion
}
}
Expand Down
43 changes: 22 additions & 21 deletions buildApp.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
apply plugin: "com.android.application"

apply {
plugin "com.android.application"
from "${rootDir.path}/buildCommon.gradle"
from "${rootDir.path}/config/flavor.gradle"
if (Config.depConfig.plugin_api.isApply) {
plugin Config.depConfig.plugin_api.pluginId
if (Config.plugins.plugin_api.isApply) {
plugin Config.plugins.plugin_api.id
}
if (Config.depConfig.plugin_bus.isApply) {
plugin Config.depConfig.plugin_bus.pluginId
if (Config.plugins.plugin_bus.isApply) {
plugin Config.plugins.plugin_bus.id
}
}

configSigning()
configApkName()

if (Config.depConfig.plugin_bus.isApply) {
bus {
onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
}
}

if (Config.depConfig.plugin_api.isApply) {
api {
onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
}
}
//if (PluginConfig.plugin_bus.isApply) {
// bus {
// onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
// }
//}
//
//if (PluginConfig.plugin_api.isApply) {
// api {
// onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
// }
//}

android {
defaultConfig {
Expand Down Expand Up @@ -67,18 +68,18 @@ android {

dependencies {
// LeakCanary
debugImplementation Config.depConfig.leakcanary.dep
debugImplementation Config.libs.leakcanary.path

debugImplementation Config.depConfig.lib_utildebug.dep
releaseImplementation Config.depConfig.lib_utildebug_no_op.dep
debugImplementation Config.modules.lib_utildebug.dep
releaseImplementation Config.modules.lib_utildebug_no_op.dep

// 根据 Config.pkgConfig 来依赖所有 pkg
for (def entrySet : ConfigUtils.getApplyPkgs().entrySet()) {
api entrySet.value.dep
}

if (Config.depConfig.feature_mock.isApply) {
api Config.depConfig.feature_mock.dep
if (Config.modules.feature_mock.isApply) {
api ModuleConfig.modules.feature_mock.dep
}
}

Expand Down
5 changes: 5 additions & 0 deletions buildCommon.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ android {
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

lintOptions {
abortOnError false
}
Expand Down
2 changes: 1 addition & 1 deletion buildLib.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ dependencies {
api entrySet.value.dep
}
} else if (project.name.endsWith("_export")) {
api Config.depConfig.lib_common.dep
api Config.modules.lib_common.dep
}
}
8 changes: 8 additions & 0 deletions buildSrc/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//dependencyResolutionManagement {
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
// repositories {
// google()
// mavenCentral()
// jcenter() // Warning: this repository is going to shut down soon
// }
//}
114 changes: 58 additions & 56 deletions buildSrc/src/main/groovy/Config.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/**
* <pre>
* author: blankj
* blog : http://blankj.com
* time : 2019/07/13
* desc :
* </pre>
*/
class Config {

static applicationId = 'com.blankj.androidutilcode'
Expand All @@ -14,74 +6,84 @@ class Config {
static compileSdkVersion = 29
static minSdkVersion = 14
static targetSdkVersion = 29
static versionCode = 1_030_006
static versionName = '1.30.7-alpha1'// E.g. 1.9.72 => 1,009,072
static versionCode = 1_030_007
static versionName = '1.31.0'// E.g. 1.9.72 => 1,009,072

// lib version
static gradlePluginVersion = '4.1.0'
static kotlinVersion = '1.3.72'
static androidxVersion = '1.0.0'

static depConfig = [
/*Never delete this line*/
/*Generated by "config.json"*/
plugin_api_gradle_plugin : new DepConfig(true , true , ":plugin:api-gradle-plugin"),
plugin_bus_gradle_plugin : new DepConfig(true , true , ":plugin:bus-gradle-plugin"),
plugin_lib_base_transform : new DepConfig(true , false, ":plugin:lib:base-transform", "com.blankj:base-transform:1.0"),
feature_mock : new DepConfig(false, true , ":feature:mock"),
feature_launcher_app : new DepConfig(true , true , ":feature:launcher:app"),
feature_main_app : new DepConfig(false, true , ":feature:main:app"),
feature_main_pkg : new DepConfig(true , true , ":feature:main:pkg"),
feature_subutil_app : new DepConfig(false, true , ":feature:subutil:app"),
feature_subutil_pkg : new DepConfig(true , true , ":feature:subutil:pkg"),
feature_subutil_export : new DepConfig(true , true , ":feature:subutil:export"),
feature_utilcode_app : new DepConfig(false, true , ":feature:utilcode:app"),
feature_utilcode_pkg : new DepConfig(true , true , ":feature:utilcode:pkg"),
feature_utilcode_export : new DepConfig(true , true , ":feature:utilcode:export", "com.blankj:utilcode-export:1.1"),
lib_base : new DepConfig(true , true , ":lib:base"),
lib_common : new DepConfig(true , true , ":lib:common"),
lib_subutil : new DepConfig(true , true , ":lib:subutil"),
lib_utilcode : new DepConfig(true , true , ":lib:utilcode", "com.blankj:utilcodex:$versionName"),
lib_utildebug : new DepConfig(true , true , ":lib:utildebug"),
lib_utildebug_no_op : new DepConfig(true , true , ":lib:utildebug-no-op"),
/*Never delete this line*/
plugin_gradle : new DepConfig(pluginPath: "com.android.tools.build:gradle:$gradlePluginVersion"),
plugin_kotlin : new DepConfig(pluginPath: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"),
plugin_traute : new DepConfig(pluginPath: "tech.harmonysoft:traute-gradle:1.1.10", pluginId: "tech.harmonysoft.oss.traute"),// 注解转非空判断
static modules = [
/*Don't delete this line*/
/*Generated by "module_config.json"*/
plugin_api_gradle_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/api-gradle-plugin"),
plugin_bus_gradle_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/bus-gradle-plugin"),
plugin_lib_base_transform : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/lib/base-transform", remotePath: "com.blankj:base-transform:1.0"),
plugin_buildSrc_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/buildSrc-plugin"),
feature_mock : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/mock"),
feature_launcher_app : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/launcher/app"),
feature_main_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/main/app"),
feature_main_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/main/pkg"),
feature_subutil_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/subutil/app"),
feature_subutil_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/subutil/pkg"),
feature_subutil_export : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/subutil/export"),
feature_utilcode_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/utilcode/app"),
feature_utilcode_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/utilcode/pkg"),
feature_utilcode_export : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/utilcode/export", remotePath: "com.blankj:utilcode-export:1.1"),
lib_base : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/base"),
lib_common : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/common"),
lib_subutil : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/subutil"),
lib_utilcode : new ModuleConfig(isApply: true , useLocal: false, localPath: "./lib/utilcode", remotePath: "com.blankj:utilcode:$Config.versionName"),
lib_utildebug : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug"),
lib_utildebug_no_op : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug-no-op"),
/*Don't delete this line*/
]

static plugins = [
plugin_gradle : new PluginConfig(path: "com.android.tools.build:gradle:$gradlePluginVersion"),
plugin_kotlin : new PluginConfig(path: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"),
// 上传到 maven
plugin_maven : new PluginConfig(path: "com.github.dcendents:android-maven-gradle-plugin:2.1", id: "com.github.dcendents.android-maven"),

// 上传新版本插件更新 pluginPath 中的版本号,并设置 isApply = false
// 上传新版本插件更新 path 中的版本号,并设置 isApply = false
// 通过 mavenLocal 上传本地版本,设置 isApply = true 即可应用插件来调试,最后通过 bintrayUpload 来发布插件
plugin_api : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:api-gradle-plugin:1.5", pluginId: "com.blankj.api"),
plugin_api : new PluginConfig(isApply: true, useLocal: false, path: "com.blankj:api-gradle-plugin:1.5", id: "com.blankj.api"),
//./gradlew clean :plugin_api-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew clean :plugin_api-gradle-plugin:bintrayUpload // 上传到 jcenter
plugin_bus : new DepConfig(isApply: true, useLocal: false, pluginPath: "com.blankj:bus-gradle-plugin:2.6", pluginId: "com.blankj.bus"),
plugin_bus : new PluginConfig(isApply: true, useLocal: false, path: "com.blankj:bus-gradle-plugin:2.6", id: "com.blankj.bus"),
//./gradlew clean :plugin_bus-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew clean :plugin_bus-gradle-plugin:bintrayUpload // 上传到 jcenter
plugin_buildSrc: new PluginConfig(isApply: true, useLocal: false, path: "com.blankj:buildSrc-plugin:1.0", id: "com.blankj.buildSrc"),
//./gradlew clean :plugin_bus-gradle-plugin:mavenLocal // 上传到本地 mavenLocal
//./gradlew clean :plugin_bus-gradle-plugin:bintrayUpload // 上传到 jcenter
]

androidx_appcompat : new DepConfig("androidx.appcompat:appcompat:$androidxVersion"),
androidx_material : new DepConfig("com.google.android.material:material:$androidxVersion"),
androidx_multidex : new DepConfig("androidx.multidex:multidex:2.0.0"),
androidx_constraint : new DepConfig("androidx.constraintlayout:constraintlayout:1.1.3"),
static libs = [
androidx_appcompat : new LibConfig(path: "androidx.appcompat:appcompat:$androidxVersion"),
androidx_material : new LibConfig(path: "com.google.android.material:material:$androidxVersion"),
androidx_multidex : new LibConfig(path: "androidx.multidex:multidex:2.0.0"),
androidx_constraint: new LibConfig(path: "androidx.constraintlayout:constraintlayout:1.1.3"),

kotlin : new DepConfig("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"),
kotlin : new LibConfig(path: "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"),

leakcanary : new DepConfig("com.squareup.leakcanary:leakcanary-android:2.1"),
leakcanary : new LibConfig(path: "com.squareup.leakcanary:leakcanary-android:2.1"),

free_proguard : new DepConfig("com.blankj:free-proguard:1.0.2"),
swipe_panel : new DepConfig("com.blankj:swipe-panel:1.2"),
free_proguard : new LibConfig(path: "com.blankj:free-proguard:1.0.2"),
swipe_panel : new LibConfig(path: "com.blankj:swipe-panel:1.2"),

gson : new DepConfig("com.google.code.gson:gson:2.8.5"),
glide : new DepConfig("com.github.bumptech.glide:glide:4.7.1"),
retrofit : new DepConfig("com.squareup.retrofit2:retrofit:2.4.0"),
commons_io : new DepConfig("commons-io:commons-io:2.6"),
gson : new LibConfig(path: "com.google.code.gson:gson:2.8.5"),
glide : new LibConfig(path: "com.github.bumptech.glide:glide:4.7.1"),
retrofit : new LibConfig(path: "com.squareup.retrofit2:retrofit:2.4.0"),
commons_io : new LibConfig(path: "commons-io:commons-io:2.6"),

eventbus_lib : new DepConfig("org.greenrobot:eventbus:3.1.1"),
eventbus_processor : new DepConfig("org.greenrobot:eventbus-annotation-processor:3.0.1"),
eventbus_lib : new LibConfig(path: "org.greenrobot:eventbus:3.1.1"),
eventbus_processor : new LibConfig(path: "org.greenrobot:eventbus-annotation-processor:3.0.1"),

photo_view : new DepConfig("com.github.chrisbanes:PhotoView:2.0.0"),
photo_view : new LibConfig(path: "com.github.chrisbanes:PhotoView:2.0.0"),

test_junit : new DepConfig("junit:junit:4.12"),
test_robolectric : new DepConfig("org.robolectric:robolectric:4.3.1"),
test_junit : new LibConfig(path: "junit:junit:4.12"),
test_robolectric : new LibConfig(path: "org.robolectric:robolectric:4.3.1"),
]
}
//./gradlew clean :lib_utilcode:bintrayUpload
45 changes: 19 additions & 26 deletions buildSrc/src/main/groovy/ConfigUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,19 @@ class ConfigUtils {
generateDep(gradle)
addCommonGradle(gradle)
TaskDurationUtils.init(gradle)
GitUtils.init(gradle)
}

/**
* 根据 depConfig 生成 dep
*/
private static void generateDep(Gradle gradle) {
def configs = [:]
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
for (Map.Entry<String, ModuleConfig> entry : Config.modules.entrySet()) {
def (name, config) = [entry.key, entry.value]
if (entry.value.pluginPath) {
config.dep = config.pluginPath
if (config.useLocal) {
config.dep = gradle.rootProject.findProject(name)
} else {
if (config.useLocal) {
config.dep = gradle.rootProject.findProject(config.projectPath)
} else {
config.dep = config.remotePath
}
config.dep = config.remotePath
}
configs.put(name, config)
}
Expand All @@ -46,20 +41,18 @@ class ConfigUtils {
@Override
void beforeEvaluate(Project project) {
// 在 project 的 build.gradle 前 do sth.
if (project.subprojects.isEmpty()) {
if (project.path.startsWith(":plugin")) {
return
if (project.name.contains("plugin")) {
return
}
if (project.name.endsWith("_app")) {
GLog.l(project.toString() + " applies buildApp.gradle")
project.apply {
from "${project.rootDir.path}/buildApp.gradle"
}
if (project.name.endsWith("_app")) {
GLog.l(project.toString() + " applies buildApp.gradle")
project.apply {
from "${project.rootDir.path}/buildApp.gradle"
}
} else {
GLog.l(project.toString() + " applies buildLib.gradle")
project.apply {
from "${project.rootDir.path}/buildLib.gradle"
}
} else {
GLog.l(project.toString() + " applies buildLib.gradle")
project.apply {
from "${project.rootDir.path}/buildLib.gradle"
}
}
}
Expand All @@ -73,8 +66,8 @@ class ConfigUtils {

static getApplyPlugins() {
def plugins = [:]
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
if (entry.value.isApply && entry.value.pluginPath) {
for (Map.Entry<String, PluginConfig> entry : Config.plugins.entrySet()) {
if (entry.value.isApply) {
plugins.put(entry.key, entry.value)
}
}
Expand All @@ -84,7 +77,7 @@ class ConfigUtils {

static getApplyPkgs() {
def pkgs = [:]
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
for (Map.Entry<String, ModuleConfig> entry : Config.modules.entrySet()) {
if (entry.value.isApply && entry.key.endsWith("_pkg")) {
pkgs.put(entry.key, entry.value)
}
Expand All @@ -95,7 +88,7 @@ class ConfigUtils {

static getApplyExports() {
def exports = [:]
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
for (Map.Entry<String, ModuleConfig> entry : Config.modules.entrySet()) {
if (entry.value.isApply && entry.key.endsWith("_export")) {
exports.put(entry.key, entry.value)
}
Expand Down
Loading

0 comments on commit e40b6d4

Please sign in to comment.