Skip to content

Commit e40b6d4

Browse files
committed
opt: Config
1 parent 402cc73 commit e40b6d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+968
-959
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010

1111
dependencies {
1212
for (def entrySet : ConfigUtils.getApplyPlugins().entrySet()) {
13-
classpath entrySet.value.dep
13+
classpath entrySet.value.path
1414
}
1515
}
1616
}
@@ -29,7 +29,7 @@ allprojects {
2929

3030
resolutionStrategy.eachDependency {
3131
if (it.requested.group == 'com.android.support' && !it.requested.name.contains(
32-
'multidex')) {
32+
'multidex')) {
3333
it.useVersion Config.supportVersion
3434
}
3535
}

buildApp.gradle

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1+
apply plugin: "com.android.application"
2+
13
apply {
2-
plugin "com.android.application"
34
from "${rootDir.path}/buildCommon.gradle"
45
from "${rootDir.path}/config/flavor.gradle"
5-
if (Config.depConfig.plugin_api.isApply) {
6-
plugin Config.depConfig.plugin_api.pluginId
6+
if (Config.plugins.plugin_api.isApply) {
7+
plugin Config.plugins.plugin_api.id
78
}
8-
if (Config.depConfig.plugin_bus.isApply) {
9-
plugin Config.depConfig.plugin_bus.pluginId
9+
if (Config.plugins.plugin_bus.isApply) {
10+
plugin Config.plugins.plugin_bus.id
1011
}
1112
}
1213

1314
configSigning()
1415
configApkName()
1516

16-
if (Config.depConfig.plugin_bus.isApply) {
17-
bus {
18-
onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
19-
}
20-
}
21-
22-
if (Config.depConfig.plugin_api.isApply) {
23-
api {
24-
onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
25-
}
26-
}
17+
//if (PluginConfig.plugin_bus.isApply) {
18+
// bus {
19+
// onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
20+
// }
21+
//}
22+
//
23+
//if (PluginConfig.plugin_api.isApply) {
24+
// api {
25+
// onlyScanLibRegex = '^([:]|(com\\.blankj)).+$'
26+
// }
27+
//}
2728

2829
android {
2930
defaultConfig {
@@ -67,18 +68,18 @@ android {
6768

6869
dependencies {
6970
// LeakCanary
70-
debugImplementation Config.depConfig.leakcanary.dep
71+
debugImplementation Config.libs.leakcanary.path
7172

72-
debugImplementation Config.depConfig.lib_utildebug.dep
73-
releaseImplementation Config.depConfig.lib_utildebug_no_op.dep
73+
debugImplementation Config.modules.lib_utildebug.dep
74+
releaseImplementation Config.modules.lib_utildebug_no_op.dep
7475

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

80-
if (Config.depConfig.feature_mock.isApply) {
81-
api Config.depConfig.feature_mock.dep
81+
if (Config.modules.feature_mock.isApply) {
82+
api ModuleConfig.modules.feature_mock.dep
8283
}
8384
}
8485

buildCommon.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ android {
1919
}
2020
}
2121

22+
compileOptions {
23+
sourceCompatibility JavaVersion.VERSION_1_8
24+
targetCompatibility JavaVersion.VERSION_1_8
25+
}
26+
2227
lintOptions {
2328
abortOnError false
2429
}

buildLib.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ dependencies {
88
api entrySet.value.dep
99
}
1010
} else if (project.name.endsWith("_export")) {
11-
api Config.depConfig.lib_common.dep
11+
api Config.modules.lib_common.dep
1212
}
1313
}

buildSrc/settings.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//dependencyResolutionManagement {
2+
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3+
// repositories {
4+
// google()
5+
// mavenCentral()
6+
// jcenter() // Warning: this repository is going to shut down soon
7+
// }
8+
//}
+58-56
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/**
2-
* <pre>
3-
* author: blankj
4-
* blog : http://blankj.com
5-
* time : 2019/07/13
6-
* desc :
7-
* </pre>
8-
*/
91
class Config {
102

113
static applicationId = 'com.blankj.androidutilcode'
@@ -14,74 +6,84 @@ class Config {
146
static compileSdkVersion = 29
157
static minSdkVersion = 14
168
static targetSdkVersion = 29
17-
static versionCode = 1_030_006
18-
static versionName = '1.30.7-alpha1'// E.g. 1.9.72 => 1,009,072
9+
static versionCode = 1_030_007
10+
static versionName = '1.31.0'// E.g. 1.9.72 => 1,009,072
1911

2012
// lib version
2113
static gradlePluginVersion = '4.1.0'
2214
static kotlinVersion = '1.3.72'
2315
static androidxVersion = '1.0.0'
2416

25-
static depConfig = [
26-
/*Never delete this line*/
27-
/*Generated by "config.json"*/
28-
plugin_api_gradle_plugin : new DepConfig(true , true , ":plugin:api-gradle-plugin"),
29-
plugin_bus_gradle_plugin : new DepConfig(true , true , ":plugin:bus-gradle-plugin"),
30-
plugin_lib_base_transform : new DepConfig(true , false, ":plugin:lib:base-transform", "com.blankj:base-transform:1.0"),
31-
feature_mock : new DepConfig(false, true , ":feature:mock"),
32-
feature_launcher_app : new DepConfig(true , true , ":feature:launcher:app"),
33-
feature_main_app : new DepConfig(false, true , ":feature:main:app"),
34-
feature_main_pkg : new DepConfig(true , true , ":feature:main:pkg"),
35-
feature_subutil_app : new DepConfig(false, true , ":feature:subutil:app"),
36-
feature_subutil_pkg : new DepConfig(true , true , ":feature:subutil:pkg"),
37-
feature_subutil_export : new DepConfig(true , true , ":feature:subutil:export"),
38-
feature_utilcode_app : new DepConfig(false, true , ":feature:utilcode:app"),
39-
feature_utilcode_pkg : new DepConfig(true , true , ":feature:utilcode:pkg"),
40-
feature_utilcode_export : new DepConfig(true , true , ":feature:utilcode:export", "com.blankj:utilcode-export:1.1"),
41-
lib_base : new DepConfig(true , true , ":lib:base"),
42-
lib_common : new DepConfig(true , true , ":lib:common"),
43-
lib_subutil : new DepConfig(true , true , ":lib:subutil"),
44-
lib_utilcode : new DepConfig(true , true , ":lib:utilcode", "com.blankj:utilcodex:$versionName"),
45-
lib_utildebug : new DepConfig(true , true , ":lib:utildebug"),
46-
lib_utildebug_no_op : new DepConfig(true , true , ":lib:utildebug-no-op"),
47-
/*Never delete this line*/
48-
plugin_gradle : new DepConfig(pluginPath: "com.android.tools.build:gradle:$gradlePluginVersion"),
49-
plugin_kotlin : new DepConfig(pluginPath: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"),
50-
plugin_traute : new DepConfig(pluginPath: "tech.harmonysoft:traute-gradle:1.1.10", pluginId: "tech.harmonysoft.oss.traute"),// 注解转非空判断
17+
static modules = [
18+
/*Don't delete this line*/
19+
/*Generated by "module_config.json"*/
20+
plugin_api_gradle_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/api-gradle-plugin"),
21+
plugin_bus_gradle_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/bus-gradle-plugin"),
22+
plugin_lib_base_transform : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/lib/base-transform", remotePath: "com.blankj:base-transform:1.0"),
23+
plugin_buildSrc_plugin : new ModuleConfig(isApply: true , useLocal: true , localPath: "./plugin/buildSrc-plugin"),
24+
feature_mock : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/mock"),
25+
feature_launcher_app : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/launcher/app"),
26+
feature_main_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/main/app"),
27+
feature_main_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/main/pkg"),
28+
feature_subutil_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/subutil/app"),
29+
feature_subutil_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/subutil/pkg"),
30+
feature_subutil_export : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/subutil/export"),
31+
feature_utilcode_app : new ModuleConfig(isApply: false, useLocal: true , localPath: "./feature/utilcode/app"),
32+
feature_utilcode_pkg : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/utilcode/pkg"),
33+
feature_utilcode_export : new ModuleConfig(isApply: true , useLocal: true , localPath: "./feature/utilcode/export", remotePath: "com.blankj:utilcode-export:1.1"),
34+
lib_base : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/base"),
35+
lib_common : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/common"),
36+
lib_subutil : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/subutil"),
37+
lib_utilcode : new ModuleConfig(isApply: true , useLocal: false, localPath: "./lib/utilcode", remotePath: "com.blankj:utilcode:$Config.versionName"),
38+
lib_utildebug : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug"),
39+
lib_utildebug_no_op : new ModuleConfig(isApply: true , useLocal: true , localPath: "./lib/utildebug-no-op"),
40+
/*Don't delete this line*/
41+
]
42+
43+
static plugins = [
44+
plugin_gradle : new PluginConfig(path: "com.android.tools.build:gradle:$gradlePluginVersion"),
45+
plugin_kotlin : new PluginConfig(path: "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"),
46+
// 上传到 maven
47+
plugin_maven : new PluginConfig(path: "com.github.dcendents:android-maven-gradle-plugin:2.1", id: "com.github.dcendents.android-maven"),
5148

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

61-
androidx_appcompat : new DepConfig("androidx.appcompat:appcompat:$androidxVersion"),
62-
androidx_material : new DepConfig("com.google.android.material:material:$androidxVersion"),
63-
androidx_multidex : new DepConfig("androidx.multidex:multidex:2.0.0"),
64-
androidx_constraint : new DepConfig("androidx.constraintlayout:constraintlayout:1.1.3"),
62+
static libs = [
63+
androidx_appcompat : new LibConfig(path: "androidx.appcompat:appcompat:$androidxVersion"),
64+
androidx_material : new LibConfig(path: "com.google.android.material:material:$androidxVersion"),
65+
androidx_multidex : new LibConfig(path: "androidx.multidex:multidex:2.0.0"),
66+
androidx_constraint: new LibConfig(path: "androidx.constraintlayout:constraintlayout:1.1.3"),
6567

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

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

70-
free_proguard : new DepConfig("com.blankj:free-proguard:1.0.2"),
71-
swipe_panel : new DepConfig("com.blankj:swipe-panel:1.2"),
72+
free_proguard : new LibConfig(path: "com.blankj:free-proguard:1.0.2"),
73+
swipe_panel : new LibConfig(path: "com.blankj:swipe-panel:1.2"),
7274

73-
gson : new DepConfig("com.google.code.gson:gson:2.8.5"),
74-
glide : new DepConfig("com.github.bumptech.glide:glide:4.7.1"),
75-
retrofit : new DepConfig("com.squareup.retrofit2:retrofit:2.4.0"),
76-
commons_io : new DepConfig("commons-io:commons-io:2.6"),
75+
gson : new LibConfig(path: "com.google.code.gson:gson:2.8.5"),
76+
glide : new LibConfig(path: "com.github.bumptech.glide:glide:4.7.1"),
77+
retrofit : new LibConfig(path: "com.squareup.retrofit2:retrofit:2.4.0"),
78+
commons_io : new LibConfig(path: "commons-io:commons-io:2.6"),
7779

78-
eventbus_lib : new DepConfig("org.greenrobot:eventbus:3.1.1"),
79-
eventbus_processor : new DepConfig("org.greenrobot:eventbus-annotation-processor:3.0.1"),
80+
eventbus_lib : new LibConfig(path: "org.greenrobot:eventbus:3.1.1"),
81+
eventbus_processor : new LibConfig(path: "org.greenrobot:eventbus-annotation-processor:3.0.1"),
8082

81-
photo_view : new DepConfig("com.github.chrisbanes:PhotoView:2.0.0"),
83+
photo_view : new LibConfig(path: "com.github.chrisbanes:PhotoView:2.0.0"),
8284

83-
test_junit : new DepConfig("junit:junit:4.12"),
84-
test_robolectric : new DepConfig("org.robolectric:robolectric:4.3.1"),
85+
test_junit : new LibConfig(path: "junit:junit:4.12"),
86+
test_robolectric : new LibConfig(path: "org.robolectric:robolectric:4.3.1"),
8587
]
8688
}
8789
//./gradlew clean :lib_utilcode:bintrayUpload

buildSrc/src/main/groovy/ConfigUtils.groovy

+19-26
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,19 @@ class ConfigUtils {
1717
generateDep(gradle)
1818
addCommonGradle(gradle)
1919
TaskDurationUtils.init(gradle)
20-
GitUtils.init(gradle)
2120
}
2221

2322
/**
2423
* 根据 depConfig 生成 dep
2524
*/
2625
private static void generateDep(Gradle gradle) {
2726
def configs = [:]
28-
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
27+
for (Map.Entry<String, ModuleConfig> entry : Config.modules.entrySet()) {
2928
def (name, config) = [entry.key, entry.value]
30-
if (entry.value.pluginPath) {
31-
config.dep = config.pluginPath
29+
if (config.useLocal) {
30+
config.dep = gradle.rootProject.findProject(name)
3231
} else {
33-
if (config.useLocal) {
34-
config.dep = gradle.rootProject.findProject(config.projectPath)
35-
} else {
36-
config.dep = config.remotePath
37-
}
32+
config.dep = config.remotePath
3833
}
3934
configs.put(name, config)
4035
}
@@ -46,20 +41,18 @@ class ConfigUtils {
4641
@Override
4742
void beforeEvaluate(Project project) {
4843
// 在 project 的 build.gradle 前 do sth.
49-
if (project.subprojects.isEmpty()) {
50-
if (project.path.startsWith(":plugin")) {
51-
return
44+
if (project.name.contains("plugin")) {
45+
return
46+
}
47+
if (project.name.endsWith("_app")) {
48+
GLog.l(project.toString() + " applies buildApp.gradle")
49+
project.apply {
50+
from "${project.rootDir.path}/buildApp.gradle"
5251
}
53-
if (project.name.endsWith("_app")) {
54-
GLog.l(project.toString() + " applies buildApp.gradle")
55-
project.apply {
56-
from "${project.rootDir.path}/buildApp.gradle"
57-
}
58-
} else {
59-
GLog.l(project.toString() + " applies buildLib.gradle")
60-
project.apply {
61-
from "${project.rootDir.path}/buildLib.gradle"
62-
}
52+
} else {
53+
GLog.l(project.toString() + " applies buildLib.gradle")
54+
project.apply {
55+
from "${project.rootDir.path}/buildLib.gradle"
6356
}
6457
}
6558
}
@@ -73,8 +66,8 @@ class ConfigUtils {
7366

7467
static getApplyPlugins() {
7568
def plugins = [:]
76-
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
77-
if (entry.value.isApply && entry.value.pluginPath) {
69+
for (Map.Entry<String, PluginConfig> entry : Config.plugins.entrySet()) {
70+
if (entry.value.isApply) {
7871
plugins.put(entry.key, entry.value)
7972
}
8073
}
@@ -84,7 +77,7 @@ class ConfigUtils {
8477

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

9689
static getApplyExports() {
9790
def exports = [:]
98-
for (Map.Entry<String, DepConfig> entry : Config.depConfig.entrySet()) {
91+
for (Map.Entry<String, ModuleConfig> entry : Config.modules.entrySet()) {
9992
if (entry.value.isApply && entry.key.endsWith("_export")) {
10093
exports.put(entry.key, entry.value)
10194
}

0 commit comments

Comments
 (0)