Skip to content

Commit

Permalink
build: 添加CommonAarSettingsPlugin
Browse files Browse the repository at this point in the history
消除大量重复的配置代码。

PR时原本VERSION_NAME是null,添加rlespinasse/github-slug-action@v3.x修复。
  • Loading branch information
shifujun committed Oct 28, 2021
1 parent bf33970 commit c639945
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 409 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
env:
DISABLE_TENCENT_MAVEN_MIRROR: true
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
Expand All @@ -26,7 +28,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: buildSdk
run: ./gradlew wrapper; ./gradlew buildSdk
run: ./gradlew wrapper; ./gradlew buildSdk -S
- name: lintSdk
run: ./gradlew wrapper; ./gradlew lintSdk
- name: build sample/source
Expand All @@ -49,6 +51,8 @@ jobs:
env:
DISABLE_TENCENT_MAVEN_MIRROR: true
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
Expand All @@ -65,7 +69,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: buildSdk
run: ./gradlew wrapper; ./gradlew buildSdk
run: ./gradlew wrapper; ./gradlew buildSdk -S
- name: lintSdk
run: ./gradlew wrapper; ./gradlew lintSdk
- name: build sample/source
Expand All @@ -77,6 +81,8 @@ jobs:
env:
DISABLE_TENCENT_MAVEN_MIRROR: true
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v3.x
- name: checkout
uses: actions/checkout@v2
- uses: actions/cache@v2
Expand Down
1 change: 1 addition & 0 deletions projects/sdk/coding/common-aar-settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
23 changes: 23 additions & 0 deletions projects/sdk/coding/common-aar-settings/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apply plugin: 'java-gradle-plugin'

apply plugin: 'kotlin'

group 'com.tencent.shadow.coding'

gradlePlugin {
plugins {
shadow {
id = "com.tencent.shadow.internal.common-aar-settings"
implementationClass = "com.tencent.shadow.coding.common_aar_settings.CommonAarSettingsPlugin"
}
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.android.tools.build:gradle:$build_gradle_version"
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
testImplementation 'junit:junit:4.12'
testImplementation gradleTestKit()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.tencent.shadow.coding.common_aar_settings

import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

class CommonAarSettingsPlugin : Plugin<Project> {

override fun apply(project: Project) {
project.pluginManager.apply("com.android.library")
project.pluginManager.apply("com.tencent.shadow.internal.aar-to-jar")

val android = project.extensions.getByName("android") as BaseExtension

configVersions(project, android)

keepOldAGPBehavior(android, project)

addCommonDependencies(project)
}

private fun addCommonDependencies(project: Project) {
project.dependencies.add("implementation", "com.tencent.shadow.coding:lint")
}

private fun keepOldAGPBehavior(
android: BaseExtension,
project: Project
) {
// Starting in version 4.2, AGP will use the Java 8 language level by default.
// To keep the old behavior, specify Java 7 explicitly.
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
android.compileOptions {
it.sourceCompatibility = JavaVersion.VERSION_1_7
it.targetCompatibility = JavaVersion.VERSION_1_7
}

// For Kotlin projects, compile to Java 6 instead of 7
project.afterEvaluate {
val kotlinOptions = (it.extensions.getByName("android") as ExtensionAware).extensions
.findByType(KotlinJvmOptions::class.java)
kotlinOptions?.apply {
jvmTarget = "1.6"
}
}

android.defaultConfig.buildConfigField(
"String",
"VERSION_NAME",
"\"${android.defaultConfig.versionName}\""
)
}

private fun configVersions(
project: Project,
android: BaseExtension
) {
val ext = project.extensions.getByName("ext") as ExtraPropertiesExtension

android.compileSdkVersion(ext["COMPILE_SDK_VERSION"] as Int)

android.defaultConfig {
it.minSdk = ext["MIN_SDK_VERSION"] as Int
it.targetSdk = ext["TARGET_SDK_VERSION"] as Int
it.versionCode = ext["VERSION_CODE"] as Int
it.versionName = ext["VERSION_NAME"] as String
it.testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
}

}
10 changes: 0 additions & 10 deletions projects/sdk/coding/lint/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ android {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
debug {
minifyEnabled false
}

release {
minifyEnabled false
}
}
}

dependencies {
Expand Down
3 changes: 2 additions & 1 deletion projects/sdk/coding/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include 'checks', 'lint'
include 'code-generator'
include 'aar-to-jar-plugin'
include 'aar-to-jar-plugin'
include 'common-aar-settings'
28 changes: 1 addition & 27 deletions projects/sdk/core/activity-container/build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
apply plugin: 'com.android.library'
apply plugin: 'com.tencent.shadow.internal.aar-to-jar'
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'

group 'com.tencent.shadow.core'

android {
compileSdkVersion project.COMPILE_SDK_VERSION

defaultConfig {
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

sourceSets {
main.java.srcDirs += project(':generate-delegate-code').buildDir.path + '/generated/DelegateCode/activity_container'
}

// Starting in version 4.2, AGP will use the Java 8 language level by default.
// To keep the old behavior, specify Java 7 explicitly.
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies{
implementation 'com.tencent.shadow.coding:lint'
}

preBuild.dependsOn(project(":generate-delegate-code").getTasksByName("generateDelegateCode", false).first())
1 change: 1 addition & 0 deletions projects/sdk/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ buildscript {
classpath "com.android.tools.build:gradle:$build_gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.tencent.shadow.coding:aar-to-jar-plugin'
classpath 'com.tencent.shadow.coding:common-aar-settings'
}
}
apply from: '../../../buildScripts/gradle/common.gradle'
Expand Down
29 changes: 1 addition & 28 deletions projects/sdk/core/common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
apply plugin: 'com.android.library'
apply plugin: 'com.tencent.shadow.internal.aar-to-jar'
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'

group 'com.tencent.shadow.core'

android {
compileSdkVersion project.COMPILE_SDK_VERSION

defaultConfig {
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

// Starting in version 4.2, AGP will use the Java 8 language level by default.
// To keep the old behavior, specify Java 7 explicitly.
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies{
implementation 'com.tencent.shadow.coding:lint'
}
32 changes: 1 addition & 31 deletions projects/sdk/core/load-parameters/build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
apply plugin: 'com.android.library'
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'

group 'com.tencent.shadow.core'

android {
compileSdkVersion project.COMPILE_SDK_VERSION


defaultConfig {
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME
}
buildTypes {
release {
minifyEnabled false
}
}

// Starting in version 4.2, AGP will use the Java 8 language level by default.
// To keep the old behavior, specify Java 7 explicitly.
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
implementation 'com.tencent.shadow.coding:lint'
}

34 changes: 2 additions & 32 deletions projects/sdk/core/loader/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.library'
apply plugin: 'com.tencent.shadow.internal.aar-to-jar'
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'

apply plugin: 'kotlin-android'

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

android {
compileSdkVersion project.COMPILE_SDK_VERSION

defaultConfig {
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME
buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

consumerProguardFiles 'plugin-loader-release.pro'
}

buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'plugin-loader-release.pro'
}

release {
consumerProguardFiles 'plugin-loader-release.pro'
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

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

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

dependencies {
Expand All @@ -62,7 +33,6 @@ dependencies {
compileOnly project(':activity-container')
compileOnly project(':common')
api project(':load-parameters')
implementation 'com.tencent.shadow.coding:lint'
}

preBuild.dependsOn(project(":generate-delegate-code").getTasksByName("generateDelegateCode", false).first())
26 changes: 1 addition & 25 deletions projects/sdk/core/manager/build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
apply plugin: 'com.android.library'
apply plugin: 'com.tencent.shadow.internal.common-aar-settings'

group 'com.tencent.shadow.core'

android {
compileSdkVersion project.COMPILE_SDK_VERSION


defaultConfig {
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME

testInstrumentationRunner "com.tencent.shadow.core.pluginmanager.CustomAndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
animationsDisabled = true
}

// Starting in version 4.2, AGP will use the Java 8 language level by default.
// To keep the old behavior, specify Java 7 explicitly.
// https://developer.android.com/studio/releases/gradle-plugin?hl=lt#java-8-default
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
Expand All @@ -46,7 +23,6 @@ dependencies {
androidTestImplementation 'commons-io:commons-io:2.5'
androidTestImplementation project(':common')

implementation 'com.tencent.shadow.coding:lint'
implementation project(':utils')
compileOnly project(':common')
api project(':load-parameters')
Expand Down
Loading

0 comments on commit c639945

Please sign in to comment.