build.gradle 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. import com.github.spotbugs.snom.SpotBugsTask
  2. // Gradle build file
  3. //
  4. // This project was started in Eclipse and later moved to Android Studio. In the transition, both IDEs were supported.
  5. // Due to this, the files layout is not the usual in new projects created with Android Studio / gradle. This file
  6. // merges declarations usually split in two separates build.gradle file, one for global settings of the project in
  7. // its root folder, another one for the app module in subfolder of root.
  8. buildscript {
  9. ext.kotlin_version = '1.3.72'
  10. repositories {
  11. google()
  12. jcenter()
  13. maven {
  14. url 'https://oss.sonatype.org/content/repositories/snapshots/'
  15. }
  16. maven {
  17. url 'https://plugins.gradle.org/m2/'
  18. }
  19. mavenCentral()
  20. }
  21. dependencies {
  22. classpath 'com.android.tools.build:gradle:4.0.1'
  23. classpath('com.hiya:jacoco-android:0.2')
  24. classpath 'gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.0'
  25. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  26. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.10.0"
  27. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  28. classpath 'com.karumi:shot:4.3.0'
  29. }
  30. }
  31. apply plugin: 'com.android.application'
  32. apply plugin: 'kotlin-android'
  33. apply plugin: 'kotlin-android-extensions'
  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. configurations {
  42. ktlint
  43. all {
  44. exclude group: 'com.google.firebase', module: 'firebase-core'
  45. exclude group: 'com.google.firebase', module: 'firebase-analytics'
  46. exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
  47. exclude group: 'org.jetbrains', module: 'annotations-java5' // via prism4j, already using annotations explicitly
  48. // check for updates every build
  49. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  50. }
  51. }
  52. ext {
  53. jacocoVersion = "0.8.2"
  54. daggerVersion = "2.28.3"
  55. markwonVersion = "4.4.0"
  56. prismVersion = "2.0.0"
  57. butterknifeVersion = "10.2.2"
  58. androidLibraryVersion = "master-SNAPSHOT"
  59. travisBuild = System.getenv("TRAVIS") == "true"
  60. // allows for -D pre-dex=false to be set
  61. preDexEnabled = "true" == System.getProperty("pre-dex", "true")
  62. }
  63. repositories {
  64. google()
  65. jcenter()
  66. maven { url "https://jitpack.io" }
  67. maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
  68. flatDir {
  69. dirs 'libs'
  70. }
  71. }
  72. // semantic versioning for version code
  73. def versionMajor = 3
  74. def versionMinor = 13
  75. def versionPatch = 0
  76. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  77. for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
  78. for (String arg : tr.args) {
  79. // any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
  80. if (arg.contains("Gplay") || arg.contains("lint") || arg.contains("ExecuteScreenshot") || arg == "build") {
  81. apply from: 'gplay.gradle'
  82. System.console().println("Applying gplay.gradle")
  83. break
  84. }
  85. }
  86. }
  87. android {
  88. lintOptions {
  89. checkGeneratedSources = true
  90. abortOnError false
  91. htmlReport true
  92. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  93. disable 'MissingTranslation',
  94. 'GradleDependency',
  95. 'VectorPath',
  96. 'IconMissingDensityFolder',
  97. 'IconDensities',
  98. 'GoogleAppIndexingWarning',
  99. 'MissingDefaultResource',
  100. 'InvalidPeriodicWorkRequestInterval' // crashes due to a bug in lint itself
  101. }
  102. dexOptions {
  103. javaMaxHeapSize "4g"
  104. }
  105. compileSdkVersion 29
  106. defaultConfig {
  107. minSdkVersion 18
  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. dexOptions {
  163. // Skip pre-dexing when running on Travis CI or when disabled via -D pre-dex=false.
  164. preDexLibraries = preDexEnabled && !travisBuild
  165. }
  166. packagingOptions {
  167. exclude 'META-INF/LICENSE.txt'
  168. exclude 'META-INF/LICENSE'
  169. }
  170. tasks.register("checkstyle", Checkstyle) {
  171. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  172. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  173. source 'src'
  174. include '**/*.java'
  175. exclude '**/gen/**'
  176. classpath = files()
  177. }
  178. tasks.register("pmd", Pmd) {
  179. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  180. ignoreFailures = true // should continue checking
  181. ruleSets = []
  182. source 'src'
  183. include '**/*.java'
  184. exclude '**/gen/**'
  185. reports {
  186. xml.enabled = false
  187. html.enabled = true
  188. xml {
  189. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  190. }
  191. html {
  192. destination = file("$project.buildDir/reports/pmd/pmd.html")
  193. }
  194. }
  195. }
  196. android.applicationVariants.all { variant ->
  197. String variantName = variant.name
  198. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  199. tasks.register("spotbugs${capVariantName}Report", SpotBugsTask) {
  200. ignoreFailures = true // should continue checking
  201. effort = "max"
  202. reportLevel = "medium"
  203. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  204. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  205. reports {
  206. xml.enabled = false
  207. html {
  208. enabled = true
  209. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  210. }
  211. }
  212. }
  213. }
  214. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  215. compileOptions {
  216. sourceCompatibility JavaVersion.VERSION_1_8
  217. targetCompatibility JavaVersion.VERSION_1_8
  218. }
  219. buildFeatures {
  220. dataBinding true
  221. viewBinding true
  222. }
  223. }
  224. dependencies {
  225. // dependencies for app building
  226. implementation 'androidx.multidex:multidex:2.0.1'
  227. // implementation project('nextcloud-android-library')
  228. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  229. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  230. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  231. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  232. kapt 'javax.xml.bind:jaxb-api:2.3.1'
  233. kapt 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  234. kapt 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  235. annotationProcessor 'javax.xml.bind:jaxb-api:2.3.1'
  236. annotationProcessor 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  237. annotationProcessor 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  238. 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
  239. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  240. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  241. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  242. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  243. implementation 'com.google.android.material:material:1.2.0'
  244. implementation 'com.jakewharton:disklrucache:2.0.2'
  245. implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
  246. implementation 'androidx.cardview:cardview:1.0.0'
  247. implementation 'androidx.exifinterface:exifinterface:1.2.0'
  248. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
  249. implementation "androidx.work:work-runtime:2.4.0"
  250. implementation "androidx.work:work-runtime-ktx:2.4.0"
  251. implementation "androidx.fragment:fragment:1.2.5"
  252. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  253. compileOnly 'com.google.code.findbugs:annotations:2.0.1'
  254. implementation 'commons-io:commons-io:2.7'
  255. implementation "com.jakewharton:butterknife:$butterknifeVersion"
  256. kapt "com.jakewharton:butterknife-compiler:$butterknifeVersion"
  257. implementation 'org.greenrobot:eventbus:3.2.0'
  258. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.0'
  259. implementation 'org.lukhnos:nnio:0.2'
  260. implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'
  261. implementation 'com.google.code.gson:gson:2.8.6'
  262. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  263. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  264. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.20'
  265. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  266. implementation 'com.google.android:flexbox:2.0.1'
  267. implementation 'org.parceler:parceler-api:1.1.13'
  268. kapt 'org.parceler:parceler:1.1.13'
  269. implementation('com.github.bumptech.glide:glide:3.8.0') {
  270. exclude group: "com.android.support"
  271. }
  272. implementation 'com.caverock:androidsvg:1.4'
  273. implementation 'androidx.annotation:annotation:1.1.0'
  274. implementation 'com.google.code.gson:gson:2.8.6'
  275. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:4.1.0'
  276. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido2:4.1.0'
  277. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
  278. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  279. implementation "com.google.dagger:dagger:$daggerVersion"
  280. implementation "com.google.dagger:dagger-android:$daggerVersion"
  281. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  282. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  283. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  284. ktlint "com.pinterest:ktlint:0.37.2"
  285. implementation 'org.conscrypt:conscrypt-android:2.4.0'
  286. // Shimmer animation
  287. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  288. // dependencies for markdown rendering
  289. implementation "io.noties.markwon:core:$markwonVersion"
  290. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  291. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  292. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  293. implementation "io.noties.markwon:html:$markwonVersion"
  294. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  295. implementation "io.noties:prism4j:$prismVersion"
  296. kapt "io.noties:prism4j-bundler:$prismVersion"
  297. // dependencies for local unit tests
  298. testImplementation 'junit:junit:4.13'
  299. testImplementation 'org.mockito:mockito-core:3.4.6'
  300. testImplementation 'androidx.test:core:1.2.0'
  301. testImplementation 'org.powermock:powermock-core:2.0.7'
  302. testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
  303. testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
  304. testImplementation 'org.json:json:20200518'
  305. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  306. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  307. testImplementation 'io.mockk:mockk:1.10.0'
  308. testImplementation 'io.mockk:mockk-android:1.10.0'
  309. // dependencies for instrumented tests
  310. // JUnit4 Rules
  311. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  312. androidTestImplementation 'androidx.test:rules:1.2.0'
  313. // Android JUnit Runner
  314. androidTestImplementation 'androidx.test:runner:1.2.0'
  315. androidTestUtil 'androidx.test:orchestrator:1.2.0'
  316. // Espresso core
  317. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  318. androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
  319. androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
  320. // Mocking support
  321. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  322. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  323. androidTestImplementation 'org.mockito:mockito-core:3.4.4'
  324. androidTestImplementation("org.mockito:mockito-android:3.4.6") {
  325. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  326. }
  327. androidTestImplementation 'net.bytebuddy:byte-buddy:1.10.14'
  328. androidTestImplementation "net.bytebuddy:byte-buddy-android:1.10.14"
  329. androidTestImplementation "io.mockk:mockk-android:1.10.0"
  330. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  331. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  332. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  333. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  334. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  335. androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
  336. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  337. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  338. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  339. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  340. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  341. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  342. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  343. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  344. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  345. implementation "com.github.stateless4j:stateless4j:2.6.0"
  346. }
  347. spotbugs {
  348. toolVersion = '3.1.12'
  349. }
  350. configurations.all {
  351. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  352. }
  353. tasks.withType(Test) {
  354. // increased logging for tests
  355. testLogging {
  356. events "passed", "skipped", "failed"
  357. }
  358. }
  359. android.applicationVariants.all { variant ->
  360. variant.outputs.all { output ->
  361. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  362. }
  363. }
  364. tasks.register("combinedTestReport", JacocoReport) {
  365. reports {
  366. xml.enabled true
  367. html.enabled true
  368. csv.enabled false
  369. }
  370. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  371. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  372. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  373. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  374. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  375. ])
  376. }
  377. task ktlint(type: JavaExec, group: "verification") {
  378. description = "Check Kotlin code style."
  379. main = "com.pinterest.ktlint.Main"
  380. classpath = configurations.ktlint
  381. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  382. }
  383. task ktlintFormat(type: JavaExec, group: "formatting") {
  384. description = "Fix Kotlin code style deviations."
  385. main = "com.pinterest.ktlint.Main"
  386. classpath = configurations.ktlint
  387. args "-F", "src/**/*.kt"
  388. }
  389. detekt {
  390. reports {
  391. xml {
  392. enabled = false
  393. }
  394. }
  395. config = files("detekt.yml")
  396. input = files("src/")
  397. }