2020-06-11 00:23:41 +02:00
|
|
|
import org.gradle.internal.jvm.Jvm
|
2022-06-11 15:16:54 +02:00
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
|
2020-06-11 00:23:41 +02:00
|
|
|
|
2014-11-09 18:02:29 +01:00
|
|
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
|
|
|
|
|
|
buildscript {
|
2021-06-24 03:35:01 +02:00
|
|
|
// The version for the Kotlin plugin and dependencies
|
2022-11-29 11:12:58 +01:00
|
|
|
ext.kotlin_version = '1.7.22'
|
2022-10-14 12:10:51 +02:00
|
|
|
ext.lint_version = '30.3.1'
|
2022-11-28 11:05:23 +01:00
|
|
|
ext.acra_version = '5.9.7'
|
2023-02-06 19:27:05 +01:00
|
|
|
ext.ankidroid_backend_version = '0.1.20-anki2.1.57'
|
2022-04-25 19:57:21 +02:00
|
|
|
ext.hamcrest_version = '2.2'
|
2023-02-06 14:32:59 +01:00
|
|
|
ext.junit_version = '5.9.2'
|
2022-07-14 12:14:30 +02:00
|
|
|
ext.coroutines_version = '1.6.4'
|
2022-12-21 17:51:01 +01:00
|
|
|
ext.fragments_version = "1.5.5"
|
2023-02-06 14:32:59 +01:00
|
|
|
ext.espresso_version = '3.5.1'
|
2022-11-11 16:56:00 +01:00
|
|
|
ext.androidx_test_version = '1.5.0'
|
2023-02-06 14:32:59 +01:00
|
|
|
ext.androidx_test_junit_version = '1.1.5'
|
|
|
|
ext.robolectric_version = '4.9.2'
|
2021-06-24 03:35:01 +02:00
|
|
|
|
2014-11-09 18:02:29 +01:00
|
|
|
repositories {
|
2018-06-10 17:27:18 +02:00
|
|
|
google()
|
2020-06-17 23:51:47 +02:00
|
|
|
maven {
|
|
|
|
url "https://plugins.gradle.org/m2/"
|
|
|
|
}
|
2014-11-09 18:02:29 +01:00
|
|
|
}
|
|
|
|
dependencies {
|
2023-02-06 14:32:59 +01:00
|
|
|
classpath 'com.android.tools.build:gradle:7.4.1'
|
2014-11-09 18:02:29 +01:00
|
|
|
// NOTE: Do not place your application dependencies here; they belong
|
|
|
|
// in the individual module build.gradle files
|
2020-06-17 23:51:47 +02:00
|
|
|
classpath "app.brant:amazonappstorepublisher:0.1.0"
|
2021-05-26 21:24:24 +02:00
|
|
|
|
2021-06-24 03:35:01 +02:00
|
|
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
2022-08-25 18:06:33 +02:00
|
|
|
classpath "org.jlleitschuh.gradle:ktlint-gradle:11.0.0"
|
2014-11-09 18:02:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-27 07:41:13 +02:00
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
|
|
|
}
|
|
|
|
|
|
|
|
allprojects {
|
|
|
|
apply plugin: "org.jlleitschuh.gradle.ktlint"
|
|
|
|
}
|
|
|
|
|
2022-06-28 07:27:32 +02:00
|
|
|
Properties localProperties = new Properties()
|
|
|
|
if (project.rootProject.file('local.properties').exists()) {
|
|
|
|
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
|
|
|
|
}
|
|
|
|
Boolean fatalWarnings = !(localProperties['fatal_warnings'] == "false")
|
|
|
|
|
2022-04-25 22:02:16 +02:00
|
|
|
// 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 {
|
2022-07-09 07:39:26 +02:00
|
|
|
// tell backend to avoid rollover time, and disable interval fuzzing
|
|
|
|
environment "ANKI_TEST_MODE", "1"
|
|
|
|
|
2022-05-01 19:39:18 +02:00
|
|
|
useJUnitPlatform()
|
2022-04-25 22:02:16 +02:00
|
|
|
testLogging {
|
|
|
|
events "failed", "skipped"
|
|
|
|
showStackTraces = true
|
|
|
|
exceptionFormat = "full"
|
|
|
|
}
|
|
|
|
|
|
|
|
maxParallelForks = gradleTestMaxParallelForks
|
|
|
|
forkEvery = 40
|
|
|
|
systemProperties['junit.jupiter.execution.parallel.enabled'] = true
|
|
|
|
systemProperties['junit.jupiter.execution.parallel.mode.default'] = "concurrent"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ktlint {
|
2022-04-26 01:24:54 +02:00
|
|
|
// remove version override when ktlint gradle plugin releases with 0.45+ transitive
|
2022-09-04 09:53:43 +02:00
|
|
|
// check for "ktlint" here:
|
|
|
|
// https://github.com/JLLeitschuh/ktlint-gradle/blob/master/plugin/gradle/libs.versions.toml
|
2022-04-26 01:24:54 +02:00
|
|
|
version = "0.45.2"
|
2022-04-25 22:02:16 +02:00
|
|
|
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 {
|
2022-06-28 07:27:32 +02:00
|
|
|
allWarningsAsErrors = fatalWarnings
|
2022-11-12 02:10:06 +01:00
|
|
|
freeCompilerArgs = ['-Xjvm-default=all']
|
2022-04-25 22:02:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 23:45:45 +01:00
|
|
|
ext {
|
2019-01-26 21:41:41 +01:00
|
|
|
|
2020-06-11 00:23:41 +02:00
|
|
|
jvmVersion = Jvm.current().javaVersion.majorVersion
|
2022-10-29 17:19:54 +02:00
|
|
|
if (jvmVersion != "11" && jvmVersion != "17" && jvmVersion != "18") {
|
2020-06-11 00:23:41 +02:00
|
|
|
println "\n\n\n"
|
|
|
|
println "**************************************************************************************************************"
|
|
|
|
println "\n\n\n"
|
2022-10-29 17:19:54 +02:00
|
|
|
println "ERROR: AnkiDroid builds with JVM version 11, 17 or 18."
|
2020-06-11 00:23:41 +02:00
|
|
|
println " Incompatible major version detected: '" + jvmVersion + "'"
|
|
|
|
println "\n\n\n"
|
|
|
|
println "**************************************************************************************************************"
|
|
|
|
println "\n\n\n"
|
|
|
|
System.exit(1)
|
|
|
|
}
|
2020-12-20 18:47:37 +01:00
|
|
|
ciBuild = System.getenv("CI") == "true" // works for Travis CI or Github Actions
|
2016-03-11 23:45:45 +01:00
|
|
|
// allows for -Dpre-dex=false to be set
|
2019-11-18 16:21:48 +01:00
|
|
|
preDexEnabled = "true" == System.getProperty("pre-dex", "true")
|
2020-06-15 22:11:12 +02:00
|
|
|
// allows for universal APKs to be generated
|
|
|
|
universalApkEnabled = "true" == System.getProperty("universal-apk", "false")
|
2018-11-24 21:11:48 +01:00
|
|
|
|
2022-05-13 19:35:46 +02:00
|
|
|
if (System.getProperty("os.name") == "Mac OS X") {
|
|
|
|
// macOS reports hardware cores. This is accurate for CI, Intel (halved due to SMT) and Apple Silicon
|
|
|
|
gradleTestMaxParallelForks = "sysctl -n hw.physicalcpu".execute().text.toInteger()
|
2022-05-13 19:45:43 +02:00
|
|
|
} else if (ciBuild) {
|
|
|
|
// GitHub Actions (Standard_DS2_v2) are 1:1 on Linux/Windows with two vCPU cores
|
|
|
|
// Sources:
|
|
|
|
// Standard_DS2_v2 https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#cloud-hosts-for-github-hosted-runners
|
|
|
|
// Which is 1:1 https://docs.microsoft.com/en-gb/azure/virtual-machines/acu : DS1_v2 - DS15_v2 | 1:1
|
|
|
|
gradleTestMaxParallelForks = 2
|
2022-06-11 15:16:54 +02:00
|
|
|
|
|
|
|
// separate gradle compile process is a major speed improvement, but consumes 2x RAM
|
|
|
|
// the CI machines don't have enough RAM to do that without going in to swap quite a bit
|
|
|
|
// so for CI machines only - to improve reliability despite compilation speed hit, compile kotlin in process
|
|
|
|
println "CI build detected: setting compiler execution strategy to IN_PROCESS"
|
|
|
|
tasks.withType(KotlinCompile).configureEach {
|
|
|
|
compilerExecutionStrategy.set(KotlinCompilerExecutionStrategy.IN_PROCESS)
|
|
|
|
}
|
2022-05-13 19:45:43 +02:00
|
|
|
} else {
|
2022-05-13 19:35:46 +02:00
|
|
|
// Use 50% of cores to account for SMT which doesn't help this workload
|
2018-11-24 21:11:48 +01:00
|
|
|
gradleTestMaxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
|
|
|
|
}
|
2016-10-23 10:55:19 +02:00
|
|
|
}
|