Skip to content

Commit

Permalink
fix(build): lint-rules project should use common best build practices
Browse files Browse the repository at this point in the history
extract our best-practices build settings to project-level file, apply
to all sub-projects

Fixes #11083
  • Loading branch information
mikehardy committed Apr 25, 2022
1 parent a5c7441 commit 099b229
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 89 deletions.
57 changes: 0 additions & 57 deletions AnkiDroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ android {

testOptions {
animationsDisabled true

unitTests {
includeAndroidResources = true
}
}

compileOptions {
Expand All @@ -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 {
Expand All @@ -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')
Expand All @@ -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"
Expand Down
27 changes: 0 additions & 27 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 changes: 65 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions lint-rules/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}

ktlint {
version = "0.45.1"
disabledRules = ["no-wildcard-imports"]
}

repositories {
google()
mavenCentral()
Expand Down

0 comments on commit 099b229

Please sign in to comment.