Skip to content

Commit c639945

Browse files
committed
build: 添加CommonAarSettingsPlugin
消除大量重复的配置代码。 PR时原本VERSION_NAME是null,添加rlespinasse/[email protected]修复。
1 parent bf33970 commit c639945

File tree

22 files changed

+126
-409
lines changed

22 files changed

+126
-409
lines changed

.github/workflows/pr-check.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
env:
1111
DISABLE_TENCENT_MAVEN_MIRROR: true
1212
steps:
13+
- name: Inject slug/short variables
14+
uses: rlespinasse/[email protected]
1315
- name: checkout
1416
uses: actions/checkout@v2
1517
- uses: actions/setup-java@v2
@@ -26,7 +28,7 @@ jobs:
2628
restore-keys: |
2729
${{ runner.os }}-gradle-
2830
- name: buildSdk
29-
run: ./gradlew wrapper; ./gradlew buildSdk
31+
run: ./gradlew wrapper; ./gradlew buildSdk -S
3032
- name: lintSdk
3133
run: ./gradlew wrapper; ./gradlew lintSdk
3234
- name: build sample/source
@@ -49,6 +51,8 @@ jobs:
4951
env:
5052
DISABLE_TENCENT_MAVEN_MIRROR: true
5153
steps:
54+
- name: Inject slug/short variables
55+
uses: rlespinasse/[email protected]
5256
- name: checkout
5357
uses: actions/checkout@v2
5458
- uses: actions/setup-java@v2
@@ -65,7 +69,7 @@ jobs:
6569
restore-keys: |
6670
${{ runner.os }}-gradle-
6771
- name: buildSdk
68-
run: ./gradlew wrapper; ./gradlew buildSdk
72+
run: ./gradlew wrapper; ./gradlew buildSdk -S
6973
- name: lintSdk
7074
run: ./gradlew wrapper; ./gradlew lintSdk
7175
- name: build sample/source
@@ -77,6 +81,8 @@ jobs:
7781
env:
7882
DISABLE_TENCENT_MAVEN_MIRROR: true
7983
steps:
84+
- name: Inject slug/short variables
85+
uses: rlespinasse/[email protected]
8086
- name: checkout
8187
uses: actions/checkout@v2
8288
- uses: actions/cache@v2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apply plugin: 'java-gradle-plugin'
2+
3+
apply plugin: 'kotlin'
4+
5+
group 'com.tencent.shadow.coding'
6+
7+
gradlePlugin {
8+
plugins {
9+
shadow {
10+
id = "com.tencent.shadow.internal.common-aar-settings"
11+
implementationClass = "com.tencent.shadow.coding.common_aar_settings.CommonAarSettingsPlugin"
12+
}
13+
}
14+
}
15+
16+
dependencies {
17+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
18+
implementation "com.android.tools.build:gradle:$build_gradle_version"
19+
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
20+
testImplementation 'junit:junit:4.12'
21+
testImplementation gradleTestKit()
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.tencent.shadow.coding.common_aar_settings
2+
3+
import com.android.build.gradle.BaseExtension
4+
import org.gradle.api.JavaVersion
5+
import org.gradle.api.Plugin
6+
import org.gradle.api.Project
7+
import org.gradle.api.plugins.ExtensionAware
8+
import org.gradle.api.plugins.ExtraPropertiesExtension
9+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
10+
11+
class CommonAarSettingsPlugin : Plugin<Project> {
12+
13+
override fun apply(project: Project) {
14+
project.pluginManager.apply("com.android.library")
15+
project.pluginManager.apply("com.tencent.shadow.internal.aar-to-jar")
16+
17+
val android = project.extensions.getByName("android") as BaseExtension
18+
19+
configVersions(project, android)
20+
21+
keepOldAGPBehavior(android, project)
22+
23+
addCommonDependencies(project)
24+
}
25+
26+
private fun addCommonDependencies(project: Project) {
27+
project.dependencies.add("implementation", "com.tencent.shadow.coding:lint")
28+
}
29+
30+
private fun keepOldAGPBehavior(
31+
android: BaseExtension,
32+
project: Project
33+
) {
34+
// Starting in version 4.2, AGP will use the Java 8 language level by default.
35+
// To keep the old behavior, specify Java 7 explicitly.
36+
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
37+
android.compileOptions {
38+
it.sourceCompatibility = JavaVersion.VERSION_1_7
39+
it.targetCompatibility = JavaVersion.VERSION_1_7
40+
}
41+
42+
// For Kotlin projects, compile to Java 6 instead of 7
43+
project.afterEvaluate {
44+
val kotlinOptions = (it.extensions.getByName("android") as ExtensionAware).extensions
45+
.findByType(KotlinJvmOptions::class.java)
46+
kotlinOptions?.apply {
47+
jvmTarget = "1.6"
48+
}
49+
}
50+
51+
android.defaultConfig.buildConfigField(
52+
"String",
53+
"VERSION_NAME",
54+
"\"${android.defaultConfig.versionName}\""
55+
)
56+
}
57+
58+
private fun configVersions(
59+
project: Project,
60+
android: BaseExtension
61+
) {
62+
val ext = project.extensions.getByName("ext") as ExtraPropertiesExtension
63+
64+
android.compileSdkVersion(ext["COMPILE_SDK_VERSION"] as Int)
65+
66+
android.defaultConfig {
67+
it.minSdk = ext["MIN_SDK_VERSION"] as Int
68+
it.targetSdk = ext["TARGET_SDK_VERSION"] as Int
69+
it.versionCode = ext["VERSION_CODE"] as Int
70+
it.versionName = ext["VERSION_NAME"] as String
71+
it.testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
72+
}
73+
}
74+
75+
}

projects/sdk/coding/lint/build.gradle

-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ android {
1414
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1515

1616
}
17-
18-
buildTypes {
19-
debug {
20-
minifyEnabled false
21-
}
22-
23-
release {
24-
minifyEnabled false
25-
}
26-
}
2717
}
2818

2919
dependencies {

projects/sdk/coding/settings.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include 'checks', 'lint'
22
include 'code-generator'
3-
include 'aar-to-jar-plugin'
3+
include 'aar-to-jar-plugin'
4+
include 'common-aar-settings'
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
1-
apply plugin: 'com.android.library'
2-
apply plugin: 'com.tencent.shadow.internal.aar-to-jar'
1+
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'
32

43
group 'com.tencent.shadow.core'
54

65
android {
7-
compileSdkVersion project.COMPILE_SDK_VERSION
8-
9-
defaultConfig {
10-
minSdkVersion project.MIN_SDK_VERSION
11-
targetSdkVersion project.TARGET_SDK_VERSION
12-
versionCode project.VERSION_CODE
13-
versionName project.VERSION_NAME
14-
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")
15-
16-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17-
18-
}
19-
206
sourceSets {
217
main.java.srcDirs += project(':generate-delegate-code').buildDir.path + '/generated/DelegateCode/activity_container'
228
}
23-
24-
// Starting in version 4.2, AGP will use the Java 8 language level by default.
25-
// To keep the old behavior, specify Java 7 explicitly.
26-
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
27-
compileOptions {
28-
sourceCompatibility JavaVersion.VERSION_1_7
29-
targetCompatibility JavaVersion.VERSION_1_7
30-
}
31-
}
32-
33-
dependencies{
34-
implementation 'com.tencent.shadow.coding:lint'
359
}
3610

3711
preBuild.dependsOn(project(":generate-delegate-code").getTasksByName("generateDelegateCode", false).first())

projects/sdk/core/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ buildscript {
1717
classpath "com.android.tools.build:gradle:$build_gradle_version"
1818
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1919
classpath 'com.tencent.shadow.coding:aar-to-jar-plugin'
20+
classpath 'com.tencent.shadow.coding:common-aar-settings'
2021
}
2122
}
2223
apply from: '../../../buildScripts/gradle/common.gradle'

projects/sdk/core/common/build.gradle

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
apply plugin: 'com.android.library'
2-
apply plugin: 'com.tencent.shadow.internal.aar-to-jar'
1+
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'
32

43
group 'com.tencent.shadow.core'
5-
6-
android {
7-
compileSdkVersion project.COMPILE_SDK_VERSION
8-
9-
defaultConfig {
10-
minSdkVersion project.MIN_SDK_VERSION
11-
targetSdkVersion project.TARGET_SDK_VERSION
12-
versionCode project.VERSION_CODE
13-
versionName project.VERSION_NAME
14-
15-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16-
17-
}
18-
19-
// Starting in version 4.2, AGP will use the Java 8 language level by default.
20-
// To keep the old behavior, specify Java 7 explicitly.
21-
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
22-
compileOptions {
23-
sourceCompatibility JavaVersion.VERSION_1_7
24-
targetCompatibility JavaVersion.VERSION_1_7
25-
}
26-
}
27-
28-
dependencies{
29-
implementation 'com.tencent.shadow.coding:lint'
30-
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
apply plugin: 'com.android.library'
1+
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'
22

33
group 'com.tencent.shadow.core'
4-
5-
android {
6-
compileSdkVersion project.COMPILE_SDK_VERSION
7-
8-
9-
defaultConfig {
10-
minSdkVersion project.MIN_SDK_VERSION
11-
targetSdkVersion project.TARGET_SDK_VERSION
12-
versionCode project.VERSION_CODE
13-
versionName project.VERSION_NAME
14-
}
15-
buildTypes {
16-
release {
17-
minifyEnabled false
18-
}
19-
}
20-
21-
// Starting in version 4.2, AGP will use the Java 8 language level by default.
22-
// To keep the old behavior, specify Java 7 explicitly.
23-
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
24-
compileOptions {
25-
sourceCompatibility JavaVersion.VERSION_1_7
26-
targetCompatibility JavaVersion.VERSION_1_7
27-
}
28-
}
29-
30-
dependencies {
31-
implementation 'com.tencent.shadow.coding:lint'
32-
}
33-

projects/sdk/core/loader/build.gradle

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
apply plugin: 'com.android.library'
2-
apply plugin: 'com.tencent.shadow.internal.aar-to-jar'
1+
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'
32

43
apply plugin: 'kotlin-android'
54

@@ -8,50 +7,22 @@ apply plugin: 'kotlin-android-extensions'
87
group 'com.tencent.shadow.core'
98

109
android {
11-
compileSdkVersion project.COMPILE_SDK_VERSION
1210

1311
defaultConfig {
14-
minSdkVersion project.MIN_SDK_VERSION
15-
targetSdkVersion project.TARGET_SDK_VERSION
16-
versionCode project.VERSION_CODE
17-
versionName project.VERSION_NAME
18-
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")
19-
20-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
21-
12+
consumerProguardFiles 'plugin-loader-release.pro'
2213
}
2314

2415
buildTypes {
25-
debug {
26-
minifyEnabled false
27-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28-
consumerProguardFiles 'plugin-loader-release.pro'
29-
}
30-
3116
release {
32-
consumerProguardFiles 'plugin-loader-release.pro'
3317
minifyEnabled true
3418
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3519
}
3620
}
3721

3822
sourceSets {
39-
main.java.srcDirs += 'src/main/kotlin'
4023
main.java.srcDirs += project(':generate-delegate-code').buildDir.path + '/generated/DelegateCode/loader'
41-
test.java.srcDirs += 'src/test/kotlin'
4224
}
4325

44-
// Starting in version 4.2, AGP will use the Java 8 language level by default.
45-
// To keep the old behavior, specify Java 7 explicitly.
46-
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
47-
compileOptions {
48-
sourceCompatibility JavaVersion.VERSION_1_7
49-
targetCompatibility JavaVersion.VERSION_1_7
50-
}
51-
// For Kotlin projects, compile to Java 6 instead of 7
52-
kotlinOptions {
53-
jvmTarget = "1.6"
54-
}
5526
}
5627

5728
dependencies {
@@ -62,7 +33,6 @@ dependencies {
6233
compileOnly project(':activity-container')
6334
compileOnly project(':common')
6435
api project(':load-parameters')
65-
implementation 'com.tencent.shadow.coding:lint'
6636
}
6737

6838
preBuild.dependsOn(project(":generate-delegate-code").getTasksByName("generateDelegateCode", false).first())

projects/sdk/core/manager/build.gradle

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
1-
apply plugin: 'com.android.library'
1+
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'
22

33
group 'com.tencent.shadow.core'
44

55
android {
6-
compileSdkVersion project.COMPILE_SDK_VERSION
7-
8-
96
defaultConfig {
10-
minSdkVersion project.MIN_SDK_VERSION
11-
targetSdkVersion project.TARGET_SDK_VERSION
12-
versionCode project.VERSION_CODE
13-
versionName project.VERSION_NAME
14-
157
testInstrumentationRunner "com.tencent.shadow.core.pluginmanager.CustomAndroidJUnitRunner"
16-
17-
}
18-
buildTypes {
19-
release {
20-
minifyEnabled false
21-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22-
}
238
}
249
testOptions {
2510
animationsDisabled = true
2611
}
27-
28-
// Starting in version 4.2, AGP will use the Java 8 language level by default.
29-
// To keep the old behavior, specify Java 7 explicitly.
30-
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
31-
compileOptions {
32-
sourceCompatibility JavaVersion.VERSION_1_7
33-
targetCompatibility JavaVersion.VERSION_1_7
34-
}
3512
}
3613

3714
dependencies {
@@ -46,7 +23,6 @@ dependencies {
4623
androidTestImplementation 'commons-io:commons-io:2.5'
4724
androidTestImplementation project(':common')
4825

49-
implementation 'com.tencent.shadow.coding:lint'
5026
implementation project(':utils')
5127
compileOnly project(':common')
5228
api project(':load-parameters')

0 commit comments

Comments
 (0)