build.gradle 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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.5.31'
  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.0.3'
  21. classpath 'com.hiya:jacoco-android:0.2'
  22. classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.5'
  23. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  24. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.1"
  25. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  26. classpath 'com.karumi:shot:5.11.2'
  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.39.1"
  56. markwonVersion = "4.6.2"
  57. prismVersion = "2.0.0"
  58. androidLibraryVersion = "master-SNAPSHOT"
  59. mockitoVersion = "3.12.4"
  60. mockkVersion = "1.10.4"
  61. powermockVersion = "2.0.9"
  62. byteBuddyVersion = "1.11.22"
  63. espressoVersion = "3.4.0"
  64. workRuntime = "2.5.0"
  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 = 19
  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. lintOptions {
  92. checkGeneratedSources = true
  93. abortOnError false
  94. htmlReport true
  95. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  96. disable 'MissingTranslation',
  97. 'GradleDependency',
  98. 'VectorPath',
  99. 'IconMissingDensityFolder',
  100. 'IconDensities',
  101. 'GoogleAppIndexingWarning',
  102. 'MissingDefaultResource',
  103. 'InvalidPeriodicWorkRequestInterval' // crashes due to a bug in lint itself
  104. }
  105. compileSdkVersion 29
  106. defaultConfig {
  107. minSdkVersion 23
  108. targetSdkVersion 29
  109. // arguments to be passed to functional tests
  110. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  111. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  112. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  113. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  114. testInstrumentationRunnerArguments disableAnalytics: 'true'
  115. multiDexEnabled true
  116. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  117. if (versionBuild > 89) {
  118. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  119. } else if (versionBuild > 50) {
  120. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  121. } else {
  122. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  123. }
  124. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  125. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  126. flavorDimensions "default"
  127. buildTypes {
  128. debug {
  129. testCoverageEnabled (project.hasProperty('coverage'))
  130. }
  131. }
  132. productFlavors {
  133. // used for f-droid
  134. generic {
  135. applicationId 'com.nextcloud.client'
  136. dimension "default"
  137. }
  138. gplay {
  139. applicationId 'com.nextcloud.client'
  140. dimension "default"
  141. }
  142. versionDev {
  143. applicationId "com.nextcloud.android.beta"
  144. dimension "default"
  145. versionCode 20200129
  146. versionName "20200129"
  147. }
  148. qa {
  149. applicationId "com.nextcloud.android.qa"
  150. dimension "default"
  151. versionCode 1
  152. versionName "1"
  153. }
  154. }
  155. testOptions {
  156. unitTests.returnDefaultValues = true
  157. animationsDisabled true
  158. }
  159. }
  160. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  161. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  162. packagingOptions {
  163. exclude 'META-INF/LICENSE.txt'
  164. exclude 'META-INF/LICENSE'
  165. }
  166. tasks.register("checkstyle", Checkstyle) {
  167. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  168. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  169. source 'src'
  170. include '**/*.java'
  171. exclude '**/gen/**'
  172. classpath = files()
  173. }
  174. tasks.register("pmd", Pmd) {
  175. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  176. ignoreFailures = true // should continue checking
  177. ruleSets = []
  178. source 'src'
  179. include '**/*.java'
  180. exclude '**/gen/**'
  181. reports {
  182. xml.enabled = false
  183. html.enabled = true
  184. xml {
  185. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  186. }
  187. html {
  188. destination = file("$project.buildDir/reports/pmd/pmd.html")
  189. }
  190. }
  191. }
  192. android.applicationVariants.all { variant ->
  193. String variantName = variant.name
  194. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  195. tasks.register("spotbugs${capVariantName}Report", SpotBugsTask) {
  196. ignoreFailures = true // should continue checking
  197. effort = "max"
  198. reportLevel = "medium"
  199. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  200. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  201. reports {
  202. xml.enabled = false
  203. html {
  204. enabled = true
  205. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  206. }
  207. }
  208. }
  209. }
  210. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  211. buildFeatures {
  212. dataBinding true
  213. viewBinding true
  214. }
  215. kotlinOptions {
  216. jvmTarget = "1.8"
  217. }
  218. }
  219. dependencies {
  220. // dependencies for app building
  221. implementation 'androidx.multidex:multidex:2.0.1'
  222. // implementation project('nextcloud-android-library')
  223. implementation ("com.github.nextcloud:android-library:$androidLibraryVersion") {
  224. exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
  225. }
  226. 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
  227. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  228. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  229. implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
  230. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  231. implementation 'com.google.android.material:material:1.4.0'
  232. implementation 'com.jakewharton:disklrucache:2.0.2'
  233. implementation 'androidx.appcompat:appcompat:1.3.1'
  234. implementation 'androidx.webkit:webkit:1.4.0'
  235. implementation 'androidx.cardview:cardview:1.0.0'
  236. implementation 'androidx.exifinterface:exifinterface:1.3.3'
  237. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
  238. implementation "androidx.work:work-runtime:$workRuntime"
  239. implementation "androidx.work:work-runtime-ktx:$workRuntime"
  240. implementation "androidx.fragment:fragment-ktx:1.3.6"
  241. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  242. compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
  243. implementation 'commons-io:commons-io:2.11.0'
  244. implementation 'org.greenrobot:eventbus:3.2.0'
  245. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
  246. implementation 'org.lukhnos:nnio:0.2'
  247. implementation 'org.bouncycastle:bcpkix-jdk15to18:1.69'
  248. implementation 'com.google.code.gson:gson:2.8.8'
  249. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  250. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  251. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
  252. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  253. implementation 'com.google.android:flexbox:2.0.1'
  254. implementation 'org.parceler:parceler-api:1.1.13'
  255. kapt 'org.parceler:parceler:1.1.13'
  256. implementation('com.github.bumptech.glide:glide:3.8.0') {
  257. exclude group: "com.android.support"
  258. }
  259. implementation 'com.caverock:androidsvg:1.4'
  260. implementation 'androidx.annotation:annotation:1.2.0'
  261. implementation 'com.vanniktech:emoji-google:0.8.0'
  262. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido:$fidoVersion"
  263. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido2:$fidoVersion"
  264. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
  265. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  266. implementation "com.google.dagger:dagger:$daggerVersion"
  267. implementation "com.google.dagger:dagger-android:$daggerVersion"
  268. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  269. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  270. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  271. ktlint "com.pinterest:ktlint:0.42.1"
  272. implementation 'org.conscrypt:conscrypt-android:2.5.2'
  273. implementation 'com.google.android.exoplayer:exoplayer:2.15.1'
  274. // Shimmer animation
  275. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  276. // dependencies for markdown rendering
  277. implementation "io.noties.markwon:core:$markwonVersion"
  278. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  279. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  280. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  281. implementation "io.noties.markwon:html:$markwonVersion"
  282. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  283. implementation "io.noties:prism4j:$prismVersion"
  284. kapt "io.noties:prism4j-bundler:$prismVersion"
  285. implementation ('org.mnode.ical4j:ical4j:1.0.6') {
  286. ['org.apache.commons','commons-logging'].each {
  287. exclude group: "$it"
  288. }
  289. }
  290. // dependencies for local unit tests
  291. testImplementation 'junit:junit:4.13.2'
  292. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  293. testImplementation "androidx.test:core:$androidxTestVersion"
  294. testImplementation "org.powermock:powermock-core:$powermockVersion"
  295. testImplementation "org.powermock:powermock-module-junit4:$powermockVersion"
  296. testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
  297. testImplementation 'org.json:json:20210307'
  298. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  299. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  300. testImplementation "io.mockk:mockk:$mockkVersion"
  301. testImplementation "io.mockk:mockk-android:$mockkVersion"
  302. // dependencies for instrumented tests
  303. // JUnit4 Rules
  304. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  305. androidTestImplementation "androidx.test:rules:$androidxTestVersion"
  306. // Android JUnit Runner
  307. androidTestImplementation "androidx.test:runner:$androidxTestVersion"
  308. androidTestUtil "androidx.test:orchestrator:$androidxTestVersion"
  309. // Espresso core
  310. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  311. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  312. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  313. androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
  314. // Mocking support
  315. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  316. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  317. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  318. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
  319. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  320. }
  321. androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
  322. androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
  323. androidTestImplementation "io.mockk:mockk-android:1.10.4"
  324. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  325. androidTestImplementation "com.facebook.testing.screenshot:core:0.13.0"
  326. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  327. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  328. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  329. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  330. androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  331. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  332. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  333. implementation "com.github.stateless4j:stateless4j:2.6.0"
  334. }
  335. configurations.all {
  336. resolutionStrategy{
  337. cacheChangingModulesFor 0, 'seconds'
  338. force 'org.objenesis:objenesis:2.6'
  339. eachDependency { details ->
  340. if ('org.jacoco' == details.requested.group) {
  341. details.useVersion "$jacoco_version"
  342. }
  343. }
  344. }
  345. }
  346. tasks.withType(Test) {
  347. // increased logging for tests
  348. testLogging {
  349. events "passed", "skipped", "failed"
  350. }
  351. }
  352. android.applicationVariants.all { variant ->
  353. variant.outputs.all { output ->
  354. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  355. }
  356. }
  357. tasks.register("combinedTestReport", JacocoReport) {
  358. jacocoClasspath = configurations['jacocoAnt']
  359. reports {
  360. xml.enabled true
  361. html.enabled true
  362. csv.enabled false
  363. }
  364. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  365. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  366. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  367. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  368. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  369. ])
  370. }
  371. task ktlint(type: JavaExec, group: "verification") {
  372. description = "Check Kotlin code style."
  373. main = "com.pinterest.ktlint.Main"
  374. classpath = configurations.ktlint
  375. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  376. }
  377. task ktlintFormat(type: JavaExec, group: "formatting") {
  378. description = "Fix Kotlin code style deviations."
  379. main = "com.pinterest.ktlint.Main"
  380. classpath = configurations.ktlint
  381. args "-F", "src/**/*.kt"
  382. }
  383. task installGitHooks(type: Copy, group: "development") {
  384. description = "Install git hooks"
  385. from("${project.rootDir}/scripts/hooks") {
  386. include '*'
  387. }
  388. into '.git/hooks'
  389. }
  390. detekt {
  391. reports {
  392. xml {
  393. enabled = false
  394. }
  395. }
  396. config = files("detekt.yml")
  397. input = files("src/")
  398. }
  399. shot {
  400. showOnlyFailingTestsInReports = ciBuild
  401. }
  402. jacoco {
  403. toolVersion = "$jacoco_version"
  404. }