Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): fix build issues #11096

Merged
merged 6 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ jobs:
run: java -fullversion 2>&1 | grep '11.0'
shell: bash

- name: Gradle Cache
uses: actions/cache@v3
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-v1
# Only write to the cache for builds on the 'main' branches, stops branches evicting main cache
# Builds on other branches will only read from main branch cache writes
# Comment this and the with: above out for performance testing on a branch
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

- name: Warm Gradle Cache
# This makes sure we fetch gradle network resources with a retry
Expand All @@ -67,19 +69,15 @@ jobs:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: ./gradlew :AnkiDroid:compilePlayDebugJavaWithJavac compileLint lint-rules:compileTestJava
command: ./gradlew :AnkiDroid:compilePlayDebugJavaWithJavac compileLint lint-rules:compileTestJava --daemon
mikehardy marked this conversation as resolved.
Show resolved Hide resolved

- name: Run Lint Debug
# "lint" is run under the 'Amazon' flavor, so slow in CI
# "lintPlayRelease" doesn't test androidTest
# "lintPlayDebug" doesn't test the API
run: ./gradlew lintPlayDebug :api:lintDebug

- name: Test Lint Rules
run: ./gradlew lint-rules:test

- name: Ktlint Check
run: ./gradlew ktlintCheck
uses: gradle/gradle-build-action@v2
with:
# "lint" is run under the 'Amazon' flavor, so slow in CI
# "lintPlayRelease" doesn't test androidTest
# "lintPlayDebug" doesn't test the API
arguments: lintPlayDebug :api:lintDebug ktLintCheck lint-rules:test --daemon

- name: Prettify code
uses: creyD/prettier_action@v4.2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests_emulator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
timeout_minutes: 15
retry_wait_seconds: 60
max_attempts: 3
command: ./gradlew packagePlayDebug packagePlayDebugAndroidTest
command: ./gradlew packagePlayDebug packagePlayDebugAndroidTest --daemon

# This appears to be 'Cache Size: ~1230 MB (1290026823 B)' based on watching action logs
# Repo limit is 10GB; branch caches are independent; branches may read default branch cache.
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
disable-animations: true
script: |
$ANDROID_HOME/platform-tools/adb logcat '*:D' > adb-log.txt &
./gradlew uninstallAll jacocoAndroidTestReport
./gradlew uninstallAll jacocoAndroidTestReport --daemon

- name: Compress Emulator Log
if: always()
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/tests_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@ jobs:
run: java -fullversion 2>&1 | grep '11.0'
shell: bash

- name: Gradle Cache
uses: actions/cache@v3
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-v2
# Only write to the cache for builds on the 'main' branches, stops branches evicting main cache
# Builds on other branches will only read from main branch cache writes
# Comment this and the with: above out for performance testing on a branch
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

- name: Gradle Dependency Download
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
retry_wait_seconds: 60
max_attempts: 3
command: ./gradlew robolectricSdkDownload
command: ./gradlew robolectricSdkDownload --daemon

- name: Run Unit Tests
run: ./gradlew jacocoUnitTestReport
uses: gradle/gradle-build-action@v2
with:
arguments: jacocoUnitTestReport --daemon

- name: Submit Coverage
# This can fail on timeouts etc, wrap with retry
Expand Down
73 changes: 19 additions & 54 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,27 +207,26 @@ 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']
// Issue 11078 - some emulators run, but run zero tests, and still report success
task assertNonzeroAndroidTests() {
doLast {
// androidTest currently creates one .xml file per emulator with aggregate results in this dir
File folder = file("./build/outputs/androidTest-results/connected/flavors/play")
File[] listOfFiles = folder.listFiles({ d, f -> f ==~ /.*.xml/ } as FilenameFilter)
for (File file : listOfFiles) {
// The aggregate results file currently contains a line with this pattern holding test count
String[] matches = file.readLines().findAll { it.contains('<testsuite') }
if (matches.length != 1) {
throw new GradleScriptException("Unable to determine count of tests executed for " + file.name + ". Regex pattern out of date?", null)
}
if (!(matches[0] ==~ /.* tests="\d+" .*/) || matches[0].contains('tests="0"')) {
throw new GradleScriptException("androidTest executed 0 tests for " + file.name + " - Probably a bug with the emulator. Try another image.", null)
}
}
}
}

//Workaround for: https://github.com/pinterest/ktlint/issues/1216
//To be removed when upstream gets patched
mikehardy marked this conversation as resolved.
Show resolved Hide resolved
tasks.withType(org.jlleitschuh.gradle.ktlint.worker.KtLintWorkAction) {
workerMaxHeapSize = "2048m"
afterEvaluate {
tasks.getByPath(':AnkiDroid:connectedPlayDebugAndroidTest').finalizedBy(assertNonzeroAndroidTests)
}

apply from: "./robolectricDownloader.gradle"
Expand Down Expand Up @@ -348,7 +313,7 @@ dependencies {
testImplementation 'org.junit.vintage:junit-vintage-engine:5.8.2'
testImplementation 'org.mockito:mockito-inline:4.5.1'
testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation "org.hamcrest:hamcrest:$hamcrest_version"
testImplementation 'net.lachlanmckee:timber-junit-rule:1.0.1'
// robolectricDownloader.gradle *may* need a new SDK jar entry if they release one or if we change targetSdk. Instructions in that gradle file.
testImplementation "org.robolectric:robolectric:4.7.3"
Expand Down
4 changes: 2 additions & 2 deletions AnkiDroid/jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import groovy.transform.Memoized
apply plugin: 'jacoco'

jacoco {
toolVersion = "0.8.7"
toolVersion = "0.8.8"
mikehardy marked this conversation as resolved.
Show resolved Hide resolved

}

android {
jacoco {
version = "0.8.7"
version = "0.8.8"
}
}

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
}
62 changes: 62 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
ext.lint_version = '30.1.3'
ext.acra_version = '5.7.0'
ext.ankidroid_backend_version = '0.1.10'
ext.hamcrest_version = '2.2'

repositories {
google()
Expand All @@ -34,6 +35,67 @@ 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 {
// remove version override when ktlint gradle plugin releases with 0.45+ transitive
// check here https://github.com/JLLeitschuh/ktlint-gradle/blob/ddd465e28d77b879384886e1eef5666ebe518b4d/plugin/gradle/libs.versions.toml#L3
version = "0.45.2"
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']
}
}
}
}

ext {

jvmVersion = Jvm.current().javaVersion.majorVersion
Expand Down
10 changes: 3 additions & 7 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 All @@ -20,10 +15,11 @@ dependencies {
compileOnly "com.android.tools.lint:lint-api:$lint_version"
compileOnly "com.android.tools.lint:lint:$lint_version"

testImplementation "junit:junit:4.13.2"
testImplementation "org.hamcrest:hamcrest:$hamcrest_version"
testImplementation "org.hamcrest:hamcrest-library:$hamcrest_version"
testImplementation 'junit:junit:4.13.2'
testImplementation "com.android.tools.lint:lint:$lint_version"
testImplementation "com.android.tools.lint:lint-api:$lint_version"
testImplementation "com.android.tools.lint:lint-tests:$lint_version"
mikehardy marked this conversation as resolved.
Show resolved Hide resolved
testImplementation 'org.hamcrest:hamcrest-all:1.3'
}
apply from: "./kotlinMigration-lint.gradle"