Move common gradle setup to a single file

Original idea by @TacoTheDank
This commit is contained in:
ByteHamster 2021-05-11 22:14:56 +02:00
parent 65bf8bf70c
commit c72fd81886
12 changed files with 137 additions and 494 deletions

View File

@ -3,34 +3,17 @@ plugins {
id('com.getkeepsafe.dexcount') id('com.getkeepsafe.dexcount')
id('com.github.triplet.play') version '2.7.5' apply false id('com.github.triplet.play') version '2.7.5' apply false
} }
apply from: "../common.gradle"
apply from: "../playFlavor.gradle"
android { android {
compileSdkVersion rootProject.ext.compileSdkVersion
viewBinding {
enabled = true
}
lintOptions {
checkGeneratedSources = true
}
defaultConfig { defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
// Version code schema: // Version code schema:
// "1.2.3-beta4" -> 1020304 // "1.2.3-beta4" -> 1020304
// "1.2.3" -> 1020395 // "1.2.3" -> 1020395
versionCode 2020003 versionCode 2020003
versionName "2.2.0-beta3" versionName "2.2.0-beta3"
multiDexEnabled false
vectorDrawables.useSupportLibrary true
vectorDrawables.generatedDensities = []
testApplicationId "de.test.antennapod"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
def commit = "" def commit = ""
try { try {
def hashStdOut = new ByteArrayOutputStream() def hashStdOut = new ByteArrayOutputStream()
@ -91,13 +74,6 @@ android {
applicationIdSuffix ".debug" applicationIdSuffix ".debug"
resValue "string", "provider_authority", "de.danoeh.antennapod.debug.provider" resValue "string", "provider_authority", "de.danoeh.antennapod.debug.provider"
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
dexcount { dexcount {
if (project.hasProperty("enableDexcountInDebug")) { if (project.hasProperty("enableDexcountInDebug")) {
runOnEachPackage enableDexcountInDebug.toBoolean() runOnEachPackage enableDexcountInDebug.toBoolean()
@ -110,52 +86,24 @@ android {
resValue "string", "provider_authority", "de.danoeh.antennapod.provider" resValue "string", "provider_authority", "de.danoeh.antennapod.provider"
minifyEnabled true minifyEnabled true
shrinkResources true shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), "proguard.cfg"
signingConfig signingConfigs.releaseConfig signingConfig signingConfigs.releaseConfig
} }
} }
packagingOptions {
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
}
lintOptions { lintOptions {
disable 'ObsoleteLintCustomCheck', 'CheckResult', 'UnusedAttribute', 'BatteryLife', 'InflateParams', disable 'ObsoleteLintCustomCheck', 'CheckResult', 'UnusedAttribute', 'BatteryLife', 'InflateParams',
'GradleDependency', 'RestrictedApi', 'TrustAllX509TrustManager', 'ExportedReceiver', 'AllowBackup', 'RestrictedApi', 'TrustAllX509TrustManager', 'ExportedReceiver', 'AllowBackup', 'VectorDrawableCompat',
'StaticFieldLeak', 'UseCompoundDrawables', 'NestedWeights', 'Overdraw', 'UselessParent', 'TextFields', 'StaticFieldLeak', 'UseCompoundDrawables', 'NestedWeights', 'Overdraw', 'UselessParent', 'TextFields',
'AlwaysShowAction', 'Autofill', 'ClickableViewAccessibility', 'ContentDescription', 'AlwaysShowAction', 'Autofill', 'ClickableViewAccessibility', 'ContentDescription',
'KeyboardInaccessibleWidget', 'LabelFor', 'SetTextI18n', 'HardcodedText', 'RelativeOverlap', 'KeyboardInaccessibleWidget', 'LabelFor', 'SetTextI18n', 'HardcodedText', 'RelativeOverlap',
'RtlCompat', 'RtlHardcoded', 'MissingMediaBrowserServiceIntentFilter', 'VectorPath', 'RtlCompat', 'RtlHardcoded', 'MissingMediaBrowserServiceIntentFilter', 'VectorPath',
'InvalidPeriodicWorkRequestInterval', 'VectorDrawableCompat' 'InvalidPeriodicWorkRequestInterval'
checkDependencies true
warningsAsErrors true
abortOnError true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
} }
aaptOptions { aaptOptions {
additionalParameters "--no-version-vectors" additionalParameters "--no-version-vectors"
} }
testOptions {
animationsDisabled = true
}
flavorDimensions "market"
productFlavors {
free {
dimension "market"
}
play {
dimension "market"
}
}
dexOptions { dexOptions {
jumboMode true jumboMode true
} }

View File

@ -20,44 +20,6 @@ allprojects {
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
jcenter() jcenter()
} }
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint"
}
}
apply plugin: 'com.github.spotbugs'
spotbugs {
effort = 'max'
reportLevel = 'medium'
excludeFilter = rootProject.file('config/spotbugs/exclude.xml')
ignoreFailures = true // Handled by printing task
}
gradle.taskGraph.beforeTask { task ->
if (task.name.toLowerCase().contains('spotbugs')) {
task.doLast {
def reportFile = task.project.file("build/reports/spotbugs/playDebug.xml")
if (!reportFile.exists()) return
def slurped = new XmlSlurper().parse(reportFile)
def foundErrors = false
slurped['BugInstance'].each { bug ->
logger.error "[SpotBugs] ${bug['LongMessage']} [${bug.@'type'}]"
bug['SourceLine'].each { line ->
logger.error "[SpotBugs] ${line['Message']}"
foundErrors = true
}
}
if (foundErrors) {
throw new TaskExecutionException(task,
new Exception("SpotBugs violations were found. See output above for details."))
}
}
}
}
} }
// Disable predex if requested (we can"t predex in Circle CI // Disable predex if requested (we can"t predex in Circle CI
@ -76,10 +38,6 @@ subprojects {
} }
project.ext { project.ext {
compileSdkVersion = 30
minSdkVersion = 16
targetSdkVersion = 30
// AndroidX // AndroidX
annotationVersion = "1.1.0" annotationVersion = "1.1.0"
appcompatVersion = "1.2.0" appcompatVersion = "1.2.0"

105
common.gradle Normal file
View File

@ -0,0 +1,105 @@
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 16
targetSdkVersion 30
multiDexEnabled false
vectorDrawables.useSupportLibrary true
vectorDrawables.generatedDensities = []
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
packagingOptions {
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
animationsDisabled = true
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable "GradleDependency"
checkDependencies true
warningsAsErrors true
abortOnError true
checkGeneratedSources = true
}
viewBinding {
enabled = true
}
}
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "skipped", "passed", "failed"
showStandardStreams true
displayGranularity 2
}
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint"
}
}
apply plugin: 'com.github.spotbugs'
spotbugs {
effort = 'max'
reportLevel = 'medium'
excludeFilter = rootProject.file('config/spotbugs/exclude.xml')
ignoreFailures = true // Handled by printing task
}
gradle.taskGraph.beforeTask { task ->
if (task.name.toLowerCase().contains('spotbugs')) {
task.doLast {
def reportFile = task.project.file("build/reports/spotbugs/playDebug.xml")
if (!reportFile.exists()) return
def slurped = new XmlSlurper().parse(reportFile)
def foundErrors = false
slurped['BugInstance'].each { bug ->
logger.error "[SpotBugs] ${bug['LongMessage']} [${bug.@'type'}]"
bug['SourceLine'].each { line ->
logger.error "[SpotBugs] ${line['Message']}"
foundErrors = true
}
}
if (foundErrors) {
throw new TaskExecutionException(task,
new Exception("SpotBugs violations were found. See output above for details."))
}
}
}
}

View File

@ -1,75 +1,22 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../common.gradle"
apply from: "../playFlavor.gradle"
android { android {
compileSdkVersion rootProject.ext.compileSdkVersion lintOptions {
disable "InvalidPeriodicWorkRequestInterval", "ObsoleteLintCustomCheck", "DefaultLocale", "UnusedAttribute",
"ParcelClassLoader", "Typos", "ExtraTranslation", "ImpliedQuantity", "CheckResult",
"PluralsCandidate", "UnusedQuantity", "StringFormatCount", "TrustAllX509TrustManager",
"StaticFieldLeak", "TypographyEllipsis", "IconDensities", "IconDuplicates"
}
defaultConfig { defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false
vectorDrawables.useSupportLibrary true
vectorDrawables.generatedDensities = []
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions { javaCompileOptions {
annotationProcessorOptions { annotationProcessorOptions {
arguments = [eventBusIndex: 'de.danoeh.antennapod.core.ApCoreEventBusIndex'] arguments = [eventBusIndex: 'de.danoeh.antennapod.core.ApCoreEventBusIndex']
} }
} }
} }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
packagingOptions {
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "market"
productFlavors {
free {
dimension "market"
}
play {
dimension "market"
}
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable "InvalidPeriodicWorkRequestInterval", "ObsoleteLintCustomCheck", "DefaultLocale", "UnusedAttribute",
"GradleDependency", "ParcelClassLoader", "Typos", "ExtraTranslation", "ImpliedQuantity",
"PluralsCandidate", "UnusedQuantity", "StringFormatCount", "TrustAllX509TrustManager",
"StaticFieldLeak", "TypographyEllipsis", "IconDensities", "IconDuplicates", "CheckResult"
checkDependencies true
warningsAsErrors true
abortOnError true
}
} }
dependencies { dependencies {
@ -124,12 +71,3 @@ dependencies {
androidTestImplementation "androidx.test:runner:$runnerVersion" androidTestImplementation "androidx.test:runner:$runnerVersion"
androidTestImplementation "androidx.test:rules:$rulesVersion" androidTestImplementation "androidx.test:rules:$rulesVersion"
} }
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "skipped", "passed", "failed"
showStandardStreams true
displayGranularity 2
}
}

View File

@ -1,50 +1,5 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../common.gradle"
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
vectorDrawables.useSupportLibrary false
multiDexEnabled false
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
warningsAsErrors true
abortOnError true
}
}
dependencies { dependencies {
annotationProcessor "androidx.annotation:annotation:$annotationVersion" annotationProcessor "androidx.annotation:annotation:$annotationVersion"

View File

@ -1,60 +1,6 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../../common.gradle"
android { apply from: "../../playFlavor.gradle"
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
flavorDimensions "market"
productFlavors {
free {
dimension "market"
}
play {
dimension "market"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
checkDependencies true
warningsAsErrors true
abortOnError true
}
}
dependencies { dependencies {
annotationProcessor "androidx.annotation:annotation:$annotationVersion" annotationProcessor "androidx.annotation:annotation:$annotationVersion"

View File

@ -1,50 +1,5 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../../../common.gradle"
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
checkDependencies true
warningsAsErrors true
abortOnError true
}
}
dependencies { dependencies {
implementation project(':net:sync:model') implementation project(':net:sync:model')

View File

@ -1,50 +1,5 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../../../common.gradle"
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
checkDependencies true
warningsAsErrors true
abortOnError true
}
}
dependencies { dependencies {
implementation project(':model') implementation project(':model')

11
playFlavor.gradle Normal file
View File

@ -0,0 +1,11 @@
android {
flavorDimensions "market"
productFlavors {
free {
dimension "market"
}
play {
dimension "market"
}
}
}

View File

@ -1,50 +1,5 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../../common.gradle"
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
checkDependencies true
warningsAsErrors true
abortOnError true
}
}
dependencies { dependencies {
annotationProcessor "androidx.annotation:annotation:$annotationVersion" annotationProcessor "androidx.annotation:annotation:$annotationVersion"

View File

@ -1,50 +1,5 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../../common.gradle"
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled false
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
checkDependencies true
warningsAsErrors true
abortOnError true
}
}
dependencies { dependencies {
annotationProcessor "androidx.annotation:annotation:$annotationVersion" annotationProcessor "androidx.annotation:annotation:$annotationVersion"

View File

@ -1,48 +1,10 @@
apply plugin: "com.android.library" apply plugin: "com.android.library"
apply from: "../../common.gradle"
android { android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig { defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
vectorDrawables.useSupportLibrary false vectorDrawables.useSupportLibrary false
multiDexEnabled false vectorDrawables.generatedDensities = null
testApplicationId "de.danoeh.antennapod.core.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt")
}
debug {
// debug build has method count over 64k single-dex threshold.
// For building debug build to use on Android < 21 (pre-Android 5) devices,
// you need to manually change class
// de.danoeh.antennapod.PodcastApp to extend MultiDexApplication .
// See Issue #2813
multiDexEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
lintOptions {
disable 'GradleDependency'
warningsAsErrors true
abortOnError true
} }
} }