build.gradle 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. import com.github.spotbugs.snom.SpotBugsTask
  2. import org.gradle.internal.jvm.Jvm
  3. // Gradle build file
  4. //
  5. // This project was started in Eclipse and later moved to Android Studio. In the transition, both IDEs were supported.
  6. // Due to this, the files layout is not the usual in new projects created with Android Studio / gradle. This file
  7. // merges declarations usually split in two separates build.gradle file, one for global settings of the project in
  8. // its root folder, another one for the app module in subfolder of root.
  9. buildscript {
  10. ext.kotlin_version = '1.6.10'
  11. ext.jacoco_version = '0.8.7'
  12. repositories {
  13. google()
  14. maven {
  15. url 'https://plugins.gradle.org/m2/'
  16. }
  17. mavenCentral()
  18. }
  19. dependencies {
  20. classpath 'com.android.tools.build:gradle:7.1.0'
  21. classpath 'com.hiya:jacoco-android:0.2'
  22. classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.5'
  23. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  24. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0"
  25. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  26. classpath 'com.karumi:shot:5.13.0'
  27. classpath "org.jacoco:org.jacoco.core:$jacoco_version"
  28. classpath "org.jacoco:org.jacoco.report:$jacoco_version"
  29. classpath "org.jacoco:org.jacoco.agent:$jacoco_version"
  30. }
  31. }
  32. apply plugin: 'com.android.application'
  33. apply plugin: 'kotlin-android'
  34. apply plugin: 'kotlin-kapt'
  35. apply plugin: 'checkstyle'
  36. apply plugin: 'pmd'
  37. apply plugin: 'com.hiya.jacoco-android'
  38. apply plugin: 'com.github.spotbugs'
  39. apply plugin: 'io.gitlab.arturbosch.detekt'
  40. apply plugin: 'shot'
  41. println "Gradle uses Java ${Jvm.current()}"
  42. configurations {
  43. ktlint
  44. all {
  45. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
  46. // check for updates every build
  47. resolutionStrategy {
  48. cacheChangingModulesFor 0, 'seconds'
  49. exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug"
  50. }
  51. }
  52. }
  53. ext {
  54. androidxTestVersion = "1.4.0"
  55. daggerVersion = "2.40.5"
  56. markwonVersion = "4.6.2"
  57. prismVersion = "2.0.0"
  58. androidLibraryVersion = "master-SNAPSHOT"
  59. mockitoVersion = "4.3.1"
  60. mockkVersion = "1.12.2"
  61. powermockVersion = "2.0.9"
  62. byteBuddyVersion = "1.12.7"
  63. espressoVersion = "3.4.0"
  64. workRuntime = "2.7.1"
  65. fidoVersion = "4.1.0"
  66. ciBuild = System.getenv("CI") == "true"
  67. }
  68. repositories {
  69. google()
  70. maven { url "https://jitpack.io" }
  71. mavenCentral()
  72. maven {
  73. url 'https://plugins.gradle.org/m2/'
  74. }
  75. }
  76. // semantic versioning for version code
  77. def versionMajor = 3
  78. def versionMinor = 20
  79. def versionPatch = 0
  80. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  81. for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
  82. for (String arg : tr.args) {
  83. // any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
  84. if (arg.contains("Gplay") || arg.contains("lint") || arg.contains("ExecuteScreenshot") || arg == "build") {
  85. apply from: 'gplay.gradle'
  86. System.console().println("Applying gplay.gradle")
  87. }
  88. }
  89. }
  90. android {
  91. compileSdkVersion 31
  92. defaultConfig {
  93. minSdkVersion 23
  94. targetSdkVersion 30
  95. // arguments to be passed to functional tests
  96. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  97. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  98. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  99. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  100. testInstrumentationRunnerArguments disableAnalytics: 'true'
  101. multiDexEnabled true
  102. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  103. if (versionBuild > 89) {
  104. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  105. } else if (versionBuild > 50) {
  106. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  107. } else {
  108. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  109. }
  110. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  111. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  112. flavorDimensions "default"
  113. buildTypes {
  114. debug {
  115. testCoverageEnabled (project.hasProperty('coverage'))
  116. }
  117. }
  118. productFlavors {
  119. // used for f-droid
  120. generic {
  121. applicationId 'com.nextcloud.client'
  122. dimension "default"
  123. }
  124. gplay {
  125. applicationId 'com.nextcloud.client'
  126. dimension "default"
  127. }
  128. huawei {
  129. applicationId 'com.nextcloud.client'
  130. dimension "default"
  131. }
  132. versionDev {
  133. applicationId "com.nextcloud.android.beta"
  134. dimension "default"
  135. versionCode 20200129
  136. versionName "20200129"
  137. }
  138. qa {
  139. applicationId "com.nextcloud.android.qa"
  140. dimension "default"
  141. versionCode 1
  142. versionName "1"
  143. }
  144. }
  145. testOptions {
  146. unitTests.returnDefaultValues = true
  147. animationsDisabled true
  148. }
  149. }
  150. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  151. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  152. packagingOptions {
  153. resources {
  154. excludes += ['META-INF/LICENSE.txt', 'META-INF/LICENSE']
  155. }
  156. }
  157. tasks.register("checkstyle", Checkstyle) {
  158. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  159. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  160. source 'src'
  161. include '**/*.java'
  162. exclude '**/gen/**'
  163. classpath = files()
  164. }
  165. tasks.register("pmd", Pmd) {
  166. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  167. ignoreFailures = true // should continue checking
  168. ruleSets = []
  169. source 'src'
  170. include '**/*.java'
  171. exclude '**/gen/**'
  172. reports {
  173. xml.enabled = false
  174. html.enabled = true
  175. xml {
  176. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  177. }
  178. html {
  179. destination = file("$project.buildDir/reports/pmd/pmd.html")
  180. }
  181. }
  182. }
  183. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  184. buildFeatures {
  185. dataBinding true
  186. viewBinding true
  187. }
  188. kotlinOptions {
  189. jvmTarget = "1.8"
  190. }
  191. lint {
  192. abortOnError false
  193. checkGeneratedSources true
  194. disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities', 'GoogleAppIndexingWarning', 'MissingDefaultResource', 'InvalidPeriodicWorkRequestInterval', 'StringFormatInvalid', 'MissingQuantity'
  195. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  196. htmlReport true
  197. }
  198. }
  199. dependencies {
  200. // dependencies for app building
  201. implementation 'androidx.multidex:multidex:2.0.1'
  202. // implementation project('nextcloud-android-library')
  203. implementation ("com.github.nextcloud:android-library:$androidLibraryVersion") {
  204. exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
  205. }
  206. compileOnly 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2' // remove after entire switch to lib v2
  207. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  208. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.5' // remove after entire switch to lib v2
  209. implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
  210. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  211. implementation 'com.google.android.material:material:1.5.0'
  212. implementation 'com.jakewharton:disklrucache:2.0.2'
  213. implementation 'androidx.appcompat:appcompat:1.4.1'
  214. implementation 'androidx.webkit:webkit:1.4.0'
  215. implementation 'androidx.cardview:cardview:1.0.0'
  216. implementation 'androidx.exifinterface:exifinterface:1.3.3'
  217. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
  218. implementation "androidx.work:work-runtime:$workRuntime"
  219. implementation "androidx.work:work-runtime-ktx:$workRuntime"
  220. implementation "androidx.fragment:fragment-ktx:1.4.1"
  221. implementation 'com.github.albfernandez:juniversalchardet:2.3.2' // need this version for Android <7
  222. compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
  223. implementation 'commons-io:commons-io:2.11.0'
  224. implementation 'org.greenrobot:eventbus:3.3.1'
  225. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
  226. implementation 'org.lukhnos:nnio:0.2'
  227. implementation 'org.bouncycastle:bcpkix-jdk15to18:1.70'
  228. implementation 'com.google.code.gson:gson:2.8.9'
  229. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  230. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  231. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
  232. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.4' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  233. implementation 'com.google.android:flexbox:2.0.1'
  234. implementation 'org.parceler:parceler-api:1.1.13'
  235. kapt 'org.parceler:parceler:1.1.13'
  236. implementation('com.github.bumptech.glide:glide:3.8.0') {
  237. exclude group: "com.android.support"
  238. }
  239. implementation 'com.caverock:androidsvg:1.4'
  240. implementation 'androidx.annotation:annotation:1.3.0'
  241. implementation 'com.vanniktech:emoji-google:0.8.0'
  242. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido:$fidoVersion"
  243. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido2:$fidoVersion"
  244. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
  245. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  246. implementation "com.google.dagger:dagger:$daggerVersion"
  247. implementation "com.google.dagger:dagger-android:$daggerVersion"
  248. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  249. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  250. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  251. ktlint "com.pinterest:ktlint:0.43.2"
  252. implementation 'org.conscrypt:conscrypt-android:2.5.2'
  253. implementation 'com.google.android.exoplayer:exoplayer:2.16.1'
  254. // Shimmer animation
  255. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  256. // dependencies for markdown rendering
  257. implementation "io.noties.markwon:core:$markwonVersion"
  258. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  259. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  260. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  261. implementation "io.noties.markwon:html:$markwonVersion"
  262. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  263. implementation "io.noties:prism4j:$prismVersion"
  264. kapt "io.noties:prism4j-bundler:$prismVersion"
  265. implementation ('org.mnode.ical4j:ical4j:1.0.8') {
  266. ['org.apache.commons','commons-logging'].each {
  267. exclude group: "$it"
  268. }
  269. }
  270. if (!ciBuild) {
  271. debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
  272. }
  273. // dependencies for local unit tests
  274. testImplementation 'junit:junit:4.13.2'
  275. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  276. testImplementation "androidx.test:core:$androidxTestVersion"
  277. testImplementation "org.powermock:powermock-core:$powermockVersion"
  278. testImplementation "org.powermock:powermock-module-junit4:$powermockVersion"
  279. testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
  280. testImplementation 'org.json:json:20211205'
  281. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  282. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  283. testImplementation "io.mockk:mockk:$mockkVersion"
  284. testImplementation "io.mockk:mockk-android:$mockkVersion"
  285. // dependencies for instrumented tests
  286. // JUnit4 Rules
  287. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  288. androidTestImplementation "androidx.test:rules:$androidxTestVersion"
  289. // Android JUnit Runner
  290. androidTestImplementation "androidx.test:runner:$androidxTestVersion"
  291. androidTestUtil "androidx.test:orchestrator:$androidxTestVersion"
  292. // Espresso core
  293. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  294. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  295. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  296. androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
  297. // Mocking support
  298. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  299. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  300. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  301. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
  302. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  303. }
  304. androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
  305. androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
  306. androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
  307. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  308. androidTestImplementation "com.facebook.testing.screenshot:core:0.13.0"
  309. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  310. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  311. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  312. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  313. androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  314. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  315. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  316. implementation "com.github.stateless4j:stateless4j:2.6.0"
  317. }
  318. configurations.all {
  319. resolutionStrategy{
  320. cacheChangingModulesFor 0, 'seconds'
  321. force 'org.objenesis:objenesis:2.6'
  322. eachDependency { details ->
  323. if ('org.jacoco' == details.requested.group) {
  324. details.useVersion "$jacoco_version"
  325. }
  326. }
  327. }
  328. }
  329. tasks.withType(Test) {
  330. // increased logging for tests
  331. testLogging {
  332. events "passed", "skipped", "failed"
  333. }
  334. }
  335. android.applicationVariants.all { variant ->
  336. variant.outputs.all { output ->
  337. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  338. }
  339. }
  340. tasks.register("combinedTestReport", JacocoReport) {
  341. jacocoClasspath = configurations['jacocoAnt']
  342. reports {
  343. xml.enabled true
  344. html.enabled true
  345. csv.enabled false
  346. }
  347. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  348. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  349. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  350. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  351. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  352. ])
  353. }
  354. task ktlint(type: JavaExec, group: "verification") {
  355. description = "Check Kotlin code style."
  356. main = "com.pinterest.ktlint.Main"
  357. classpath = configurations.ktlint
  358. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  359. }
  360. task ktlintFormat(type: JavaExec, group: "formatting") {
  361. description = "Fix Kotlin code style deviations."
  362. main = "com.pinterest.ktlint.Main"
  363. classpath = configurations.ktlint
  364. args "-F", "src/**/*.kt"
  365. }
  366. task installGitHooks(type: Copy, group: "development") {
  367. description = "Install git hooks"
  368. from("${project.rootDir}/scripts/hooks") {
  369. include '*'
  370. }
  371. into '.git/hooks'
  372. }
  373. detekt {
  374. reports {
  375. xml {
  376. enabled = false
  377. }
  378. }
  379. config = files("detekt.yml")
  380. input = files("src/")
  381. }
  382. shot {
  383. showOnlyFailingTestsInReports = ciBuild
  384. // CI environment renders some shadows slightly different from local VMs
  385. // Add a 0.5% tolerance to account for that
  386. tolerance = ciBuild ? 0.5: 0
  387. }
  388. jacoco {
  389. toolVersion = "$jacoco_version"
  390. }
  391. spotbugs {
  392. ignoreFailures = true // should continue checking
  393. effort = "max"
  394. reportLevel = "medium"
  395. }
  396. tasks.withType(SpotBugsTask){task ->
  397. String variantNameCap = task.name.replace("spotbugs", "")
  398. String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
  399. dependsOn "compile${variantNameCap}Sources"
  400. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  401. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  402. reports {
  403. xml.enabled = false
  404. html {
  405. enabled = true
  406. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  407. }
  408. }
  409. }