build.gradle 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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.0'
  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 'com.github.spotbugs.snom:spotbugs-gradle-plugin:4.8.0'
  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.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.40.3"
  56. markwonVersion = "4.6.2"
  57. prismVersion = "2.0.0"
  58. androidLibraryVersion = "master-SNAPSHOT"
  59. mockitoVersion = "3.12.4"
  60. mockkVersion = "1.12.1"
  61. powermockVersion = "2.0.9"
  62. byteBuddyVersion = "1.12.2"
  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 31
  106. defaultConfig {
  107. minSdkVersion 23
  108. targetSdkVersion 30
  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. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  193. buildFeatures {
  194. dataBinding true
  195. viewBinding true
  196. }
  197. kotlinOptions {
  198. jvmTarget = "1.8"
  199. }
  200. }
  201. dependencies {
  202. // dependencies for app building
  203. implementation 'androidx.multidex:multidex:2.0.1'
  204. // implementation project('nextcloud-android-library')
  205. implementation ("com.github.nextcloud:android-library:$androidLibraryVersion") {
  206. exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version
  207. }
  208. 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
  209. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  210. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  211. implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
  212. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  213. implementation 'com.google.android.material:material:1.4.0'
  214. implementation 'com.jakewharton:disklrucache:2.0.2'
  215. implementation 'androidx.appcompat:appcompat:1.3.1'
  216. implementation 'androidx.webkit:webkit:1.4.0'
  217. implementation 'androidx.cardview:cardview:1.0.0'
  218. implementation 'androidx.exifinterface:exifinterface:1.3.3'
  219. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"
  220. implementation "androidx.work:work-runtime:$workRuntime"
  221. implementation "androidx.work:work-runtime-ktx:$workRuntime"
  222. implementation "androidx.fragment:fragment-ktx:1.3.6"
  223. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  224. compileOnly 'com.google.code.findbugs:annotations:3.0.1u2'
  225. implementation 'commons-io:commons-io:2.11.0'
  226. implementation 'org.greenrobot:eventbus:3.2.0'
  227. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
  228. implementation 'org.lukhnos:nnio:0.2'
  229. implementation 'org.bouncycastle:bcpkix-jdk15to18:1.69'
  230. implementation 'com.google.code.gson:gson:2.8.9'
  231. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  232. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  233. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
  234. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  235. implementation 'com.google.android:flexbox:2.0.1'
  236. implementation 'org.parceler:parceler-api:1.1.13'
  237. kapt 'org.parceler:parceler:1.1.13'
  238. implementation('com.github.bumptech.glide:glide:3.8.0') {
  239. exclude group: "com.android.support"
  240. }
  241. implementation 'com.caverock:androidsvg:1.4'
  242. implementation 'androidx.annotation:annotation:1.3.0'
  243. implementation 'com.vanniktech:emoji-google:0.8.0'
  244. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido:$fidoVersion"
  245. implementation "com.github.cotechde.hwsecurity:hwsecurity-fido2:$fidoVersion"
  246. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
  247. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  248. implementation "com.google.dagger:dagger:$daggerVersion"
  249. implementation "com.google.dagger:dagger-android:$daggerVersion"
  250. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  251. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  252. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  253. ktlint "com.pinterest:ktlint:0.43.0"
  254. implementation 'org.conscrypt:conscrypt-android:2.5.2'
  255. implementation 'com.google.android.exoplayer:exoplayer:2.16.1'
  256. // Shimmer animation
  257. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  258. // dependencies for markdown rendering
  259. implementation "io.noties.markwon:core:$markwonVersion"
  260. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  261. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  262. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  263. implementation "io.noties.markwon:html:$markwonVersion"
  264. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  265. implementation "io.noties:prism4j:$prismVersion"
  266. kapt "io.noties:prism4j-bundler:$prismVersion"
  267. implementation ('org.mnode.ical4j:ical4j:1.0.6') {
  268. ['org.apache.commons','commons-logging'].each {
  269. exclude group: "$it"
  270. }
  271. }
  272. if (!ciBuild) {
  273. debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
  274. }
  275. // dependencies for local unit tests
  276. testImplementation 'junit:junit:4.13.2'
  277. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  278. testImplementation "androidx.test:core:$androidxTestVersion"
  279. testImplementation "org.powermock:powermock-core:$powermockVersion"
  280. testImplementation "org.powermock:powermock-module-junit4:$powermockVersion"
  281. testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
  282. testImplementation 'org.json:json:20210307'
  283. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  284. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  285. testImplementation "io.mockk:mockk:$mockkVersion"
  286. testImplementation "io.mockk:mockk-android:$mockkVersion"
  287. // dependencies for instrumented tests
  288. // JUnit4 Rules
  289. androidTestImplementation 'androidx.test.ext:junit:1.1.3'
  290. androidTestImplementation "androidx.test:rules:$androidxTestVersion"
  291. // Android JUnit Runner
  292. androidTestImplementation "androidx.test:runner:$androidxTestVersion"
  293. androidTestUtil "androidx.test:orchestrator:$androidxTestVersion"
  294. // Espresso core
  295. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  296. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  297. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  298. androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
  299. // Mocking support
  300. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  301. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  302. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  303. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
  304. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  305. }
  306. androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
  307. androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
  308. androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
  309. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  310. androidTestImplementation "com.facebook.testing.screenshot:core:0.13.0"
  311. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  312. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  313. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  314. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  315. androidTestImplementation 'tools.fastlane:screengrab:2.1.1'
  316. implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  317. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  318. implementation "com.github.stateless4j:stateless4j:2.6.0"
  319. }
  320. configurations.all {
  321. resolutionStrategy{
  322. cacheChangingModulesFor 0, 'seconds'
  323. force 'org.objenesis:objenesis:2.6'
  324. eachDependency { details ->
  325. if ('org.jacoco' == details.requested.group) {
  326. details.useVersion "$jacoco_version"
  327. }
  328. }
  329. }
  330. }
  331. tasks.withType(Test) {
  332. // increased logging for tests
  333. testLogging {
  334. events "passed", "skipped", "failed"
  335. }
  336. }
  337. android.applicationVariants.all { variant ->
  338. variant.outputs.all { output ->
  339. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  340. }
  341. }
  342. tasks.register("combinedTestReport", JacocoReport) {
  343. jacocoClasspath = configurations['jacocoAnt']
  344. reports {
  345. xml.enabled true
  346. html.enabled true
  347. csv.enabled false
  348. }
  349. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  350. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  351. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  352. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  353. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  354. ])
  355. }
  356. task ktlint(type: JavaExec, group: "verification") {
  357. description = "Check Kotlin code style."
  358. main = "com.pinterest.ktlint.Main"
  359. classpath = configurations.ktlint
  360. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  361. }
  362. task ktlintFormat(type: JavaExec, group: "formatting") {
  363. description = "Fix Kotlin code style deviations."
  364. main = "com.pinterest.ktlint.Main"
  365. classpath = configurations.ktlint
  366. args "-F", "src/**/*.kt"
  367. }
  368. task installGitHooks(type: Copy, group: "development") {
  369. description = "Install git hooks"
  370. from("${project.rootDir}/scripts/hooks") {
  371. include '*'
  372. }
  373. into '.git/hooks'
  374. }
  375. detekt {
  376. reports {
  377. xml {
  378. enabled = false
  379. }
  380. }
  381. config = files("detekt.yml")
  382. input = files("src/")
  383. }
  384. shot {
  385. showOnlyFailingTestsInReports = ciBuild
  386. }
  387. jacoco {
  388. toolVersion = "$jacoco_version"
  389. }
  390. spotbugs {
  391. ignoreFailures = true // should continue checking
  392. effort = "max"
  393. reportLevel = "medium"
  394. }
  395. tasks.withType(SpotBugsTask){task ->
  396. String variantNameCap = task.name.replace("spotbugs", "")
  397. String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
  398. dependsOn "compile${variantNameCap}Sources"
  399. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  400. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  401. reports {
  402. xml.enabled = false
  403. html {
  404. enabled = true
  405. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  406. }
  407. }
  408. }