mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 03:52:15 +02:00
fix(build): lint-rules project should use common best build practices
extract our best-practices build settings to project-level file, apply to all sub-projects Fixes #11083
This commit is contained in:
parent
45e7c19f8b
commit
25473eeaff
@ -172,10 +172,6 @@ android {
|
||||
|
||||
testOptions {
|
||||
animationsDisabled true
|
||||
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
@ -184,31 +180,12 @@ android {
|
||||
packagingOptions {
|
||||
exclude 'META-INF/DEPENDENCIES'
|
||||
}
|
||||
testOptions.unitTests.all {
|
||||
testLogging {
|
||||
events "failed", "skipped"
|
||||
showStackTraces = true
|
||||
exceptionFormat = "full"
|
||||
}
|
||||
|
||||
maxParallelForks = gradleTestMaxParallelForks
|
||||
forkEvery = 40
|
||||
maxHeapSize = "2048m"
|
||||
minHeapSize = "1024m"
|
||||
systemProperties['junit.jupiter.execution.parallel.enabled'] = true
|
||||
systemProperties['junit.jupiter.execution.parallel.mode.default'] = "concurrent"
|
||||
}
|
||||
sourceSets {
|
||||
debug {
|
||||
manifest.srcFile 'src/test/AndroidManifest.xml'
|
||||
}
|
||||
}
|
||||
ndkVersion "22.0.7026061"
|
||||
|
||||
ktlint {
|
||||
version = "0.45.1"
|
||||
disabledRules = ["no-wildcard-imports"]
|
||||
}
|
||||
}
|
||||
|
||||
play {
|
||||
@ -222,17 +199,6 @@ amazon {
|
||||
replaceEdit = true
|
||||
}
|
||||
|
||||
// Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:fallthrough" << "-Xmaxwarns" << "1000" << "-Werror"
|
||||
|
||||
// https://guides.gradle.org/performance/#compiling_java
|
||||
// 1- fork improves things over time with repeated builds, doesn't harm CI single builds
|
||||
options.fork = true
|
||||
// 2- incremental will be the default in the future and can help now
|
||||
options.incremental = true
|
||||
}
|
||||
|
||||
// Install Git pre-commit hook for Ktlint
|
||||
task installGitHook(type: Copy) {
|
||||
from new File(rootProject.rootDir, 'pre-commit')
|
||||
@ -241,29 +207,6 @@ task installGitHook(type: Copy) {
|
||||
}
|
||||
tasks.getByPath(':AnkiDroid:preBuild').dependsOn installGitHook
|
||||
|
||||
/**
|
||||
Kotlin allows concrete function implementations inside interfaces.
|
||||
For those to work when Kotlin compilation targets the JVM backend, you have to enable the interoperability via
|
||||
'freeCompilerArgs' in your gradle file, and you have to choose one of the appropriate '-Xjvm-default' modes.
|
||||
|
||||
https://kotlinlang.org/docs/java-to-kotlin-interop.html#default-methods-in-interfaces
|
||||
|
||||
and we used "all" because we don't have downstream consumers
|
||||
https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
|
||||
*/
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||
kotlinOptions {
|
||||
allWarningsAsErrors = true
|
||||
freeCompilerArgs = ['-Xjvm-default=all']
|
||||
}
|
||||
}
|
||||
|
||||
//Workaround for: https://github.com/pinterest/ktlint/issues/1216
|
||||
//To be removed when upstream gets patched
|
||||
tasks.withType(org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction) {
|
||||
workerMaxHeapSize = "2048m"
|
||||
}
|
||||
|
||||
apply from: "./robolectricDownloader.gradle"
|
||||
apply from: "./jacoco.gradle"
|
||||
apply from: "../lint.gradle"
|
||||
|
@ -25,26 +25,10 @@ android {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
testOptions {
|
||||
unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
testOptions.unitTests.all {
|
||||
testLogging {
|
||||
events "failed", "skipped"
|
||||
showStackTraces = true
|
||||
exceptionFormat = "full"
|
||||
}
|
||||
|
||||
maxParallelForks = gradleTestMaxParallelForks
|
||||
systemProperties['junit.jupiter.execution.parallel.enabled'] = true
|
||||
systemProperties['junit.jupiter.execution.parallel.mode.default'] = "concurrent"
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "../lint.gradle"
|
||||
@ -146,14 +130,3 @@ publishMavenJavaPublicationToMavenRepository.dependsOn(assemble)
|
||||
publish.dependsOn(assemble)
|
||||
generateRelease.dependsOn(publish)
|
||||
generateRelease.dependsOn(zipRelease)
|
||||
|
||||
// Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must
|
||||
tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:deprecation" << "-Xmaxwarns" << "1000" << "-Werror"
|
||||
|
||||
// https://guides.gradle.org/performance/#compiling_java
|
||||
// 1- fork improves things over time with repeated builds, doesn't harm CI single builds
|
||||
options.fork = true
|
||||
// 2- incremental will be the default in the future and can help now
|
||||
options.incremental = true
|
||||
}
|
||||
|
65
build.gradle
65
build.gradle
@ -35,6 +35,71 @@ allprojects {
|
||||
apply plugin: "org.jlleitschuh.gradle.ktlint"
|
||||
}
|
||||
|
||||
// Here we extract per-module "best practices" settings to a single top-level evaluation
|
||||
subprojects {
|
||||
afterEvaluate { project ->
|
||||
|
||||
if (project.hasProperty('android')) {
|
||||
project.android.testOptions.unitTests {
|
||||
includeAndroidResources = true
|
||||
}
|
||||
project.android.testOptions.unitTests.all {
|
||||
testLogging {
|
||||
events "failed", "skipped"
|
||||
showStackTraces = true
|
||||
exceptionFormat = "full"
|
||||
}
|
||||
|
||||
maxParallelForks = gradleTestMaxParallelForks
|
||||
forkEvery = 40
|
||||
maxHeapSize = "2048m"
|
||||
minHeapSize = "1024m"
|
||||
systemProperties['junit.jupiter.execution.parallel.enabled'] = true
|
||||
systemProperties['junit.jupiter.execution.parallel.mode.default'] = "concurrent"
|
||||
}
|
||||
}
|
||||
|
||||
// Deprecation is an error. Use @SuppressWarnings("deprecation") and justify in the PR if you must
|
||||
project.tasks.withType(JavaCompile) {
|
||||
options.compilerArgs << "-Xlint:deprecation" << "-Xlint:fallthrough" << "-Xmaxwarns" << "1000" << "-Werror"
|
||||
|
||||
// https://guides.gradle.org/performance/#compiling_java
|
||||
// 1- fork improves things over time with repeated builds, doesn't harm CI single builds
|
||||
options.fork = true
|
||||
// 2- incremental will be the default in the future and can help now
|
||||
options.incremental = true
|
||||
}
|
||||
|
||||
ktlint {
|
||||
version = "0.45.1"
|
||||
disabledRules = ["no-wildcard-imports"]
|
||||
}
|
||||
|
||||
/**
|
||||
Kotlin allows concrete function implementations inside interfaces.
|
||||
For those to work when Kotlin compilation targets the JVM backend, you have to enable the interoperability via
|
||||
'freeCompilerArgs' in your gradle file, and you have to choose one of the appropriate '-Xjvm-default' modes.
|
||||
|
||||
https://kotlinlang.org/docs/java-to-kotlin-interop.html#default-methods-in-interfaces
|
||||
|
||||
and we used "all" because we don't have downstream consumers
|
||||
https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
|
||||
*/
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||
kotlinOptions {
|
||||
allWarningsAsErrors = true
|
||||
freeCompilerArgs = ['-Xjvm-default=all']
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround for: https://github.com/pinterest/ktlint/issues/1216
|
||||
// To be removed when upstream gets patched
|
||||
tasks.withType(org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction) {
|
||||
workerMaxHeapSize = "2048m"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ext {
|
||||
|
||||
jvmVersion = Jvm.current().javaVersion.majorVersion
|
||||
|
@ -6,11 +6,6 @@ java {
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
ktlint {
|
||||
version = "0.45.1"
|
||||
disabledRules = ["no-wildcard-imports"]
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
|
Loading…
Reference in New Issue
Block a user