build.gradle 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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.4.10'
  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.13.1"
  27. classpath "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  28. classpath 'com.karumi:shot:4.4.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.29.1"
  55. markwonVersion = "4.5.1"
  56. prismVersion = "2.0.0"
  57. butterknifeVersion = "10.2.3"
  58. androidLibraryVersion = "master-SNAPSHOT"
  59. mockitoVersion = "3.5.11"
  60. byteBuddyVersion = "1.10.15"
  61. espressoVersion = "3.3.0"
  62. travisBuild = System.getenv("TRAVIS") == "true"
  63. // allows for -D pre-dex=false to be set
  64. preDexEnabled = "true" == System.getProperty("pre-dex", "true")
  65. }
  66. repositories {
  67. google()
  68. jcenter()
  69. maven { url "https://jitpack.io" }
  70. maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
  71. flatDir {
  72. dirs 'libs'
  73. }
  74. }
  75. // semantic versioning for version code
  76. def versionMajor = 3
  77. def versionMinor = 14
  78. def versionPatch = 0
  79. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  80. for (TaskExecutionRequest tr : getGradle().getStartParameter().getTaskRequests()) {
  81. for (String arg : tr.args) {
  82. // any gplay, but only exact "build", as e.g. buildGeneric shall not apply gplay.grade
  83. if (arg.contains("Gplay") || arg.contains("lint") || arg.contains("ExecuteScreenshot") || arg == "build") {
  84. apply from: 'gplay.gradle'
  85. System.console().println("Applying gplay.gradle")
  86. break
  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. dexOptions {
  106. javaMaxHeapSize "4g"
  107. }
  108. compileSdkVersion 29
  109. defaultConfig {
  110. minSdkVersion 18
  111. targetSdkVersion 29
  112. // arguments to be passed to functional tests
  113. testInstrumentationRunner "com.nextcloud.client.ScreenshotTestRunner"
  114. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  115. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  116. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  117. testInstrumentationRunnerArguments disableAnalytics: 'true'
  118. multiDexEnabled true
  119. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  120. if (versionBuild > 89) {
  121. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  122. } else if (versionBuild > 50) {
  123. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  124. } else {
  125. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  126. }
  127. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  128. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  129. flavorDimensions "default"
  130. buildTypes {
  131. debug {
  132. testCoverageEnabled (project.hasProperty('coverage'))
  133. }
  134. }
  135. productFlavors {
  136. // used for f-droid
  137. generic {
  138. applicationId 'com.nextcloud.client'
  139. dimension "default"
  140. }
  141. gplay {
  142. applicationId 'com.nextcloud.client'
  143. dimension "default"
  144. }
  145. versionDev {
  146. applicationId "com.nextcloud.android.beta"
  147. dimension "default"
  148. versionCode 20200129
  149. versionName "20200129"
  150. }
  151. qa {
  152. applicationId "com.nextcloud.android.qa"
  153. dimension "default"
  154. versionCode 1
  155. versionName "1"
  156. }
  157. }
  158. testOptions {
  159. unitTests.returnDefaultValues = true
  160. animationsDisabled true
  161. }
  162. }
  163. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  164. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  165. dexOptions {
  166. // Skip pre-dexing when running on Travis CI or when disabled via -D pre-dex=false.
  167. preDexLibraries = preDexEnabled && !travisBuild
  168. }
  169. packagingOptions {
  170. exclude 'META-INF/LICENSE.txt'
  171. exclude 'META-INF/LICENSE'
  172. }
  173. tasks.register("checkstyle", Checkstyle) {
  174. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  175. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  176. source 'src'
  177. include '**/*.java'
  178. exclude '**/gen/**'
  179. classpath = files()
  180. }
  181. tasks.register("pmd", Pmd) {
  182. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  183. ignoreFailures = true // should continue checking
  184. ruleSets = []
  185. source 'src'
  186. include '**/*.java'
  187. exclude '**/gen/**'
  188. reports {
  189. xml.enabled = false
  190. html.enabled = true
  191. xml {
  192. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  193. }
  194. html {
  195. destination = file("$project.buildDir/reports/pmd/pmd.html")
  196. }
  197. }
  198. }
  199. android.applicationVariants.all { variant ->
  200. String variantName = variant.name
  201. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  202. tasks.register("spotbugs${capVariantName}Report", SpotBugsTask) {
  203. ignoreFailures = true // should continue checking
  204. effort = "max"
  205. reportLevel = "medium"
  206. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
  207. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  208. reports {
  209. xml.enabled = false
  210. html {
  211. enabled = true
  212. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  213. }
  214. }
  215. }
  216. }
  217. check.dependsOn 'checkstyle', 'spotbugsGplayDebugReport', 'pmd', 'lint', 'ktlint', 'detekt'
  218. compileOptions {
  219. sourceCompatibility JavaVersion.VERSION_1_8
  220. targetCompatibility JavaVersion.VERSION_1_8
  221. }
  222. buildFeatures {
  223. dataBinding true
  224. viewBinding true
  225. }
  226. }
  227. dependencies {
  228. // dependencies for app building
  229. implementation 'androidx.multidex:multidex:2.0.1'
  230. // implementation project('nextcloud-android-library')
  231. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  232. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  233. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  234. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  235. kapt 'javax.xml.bind:jaxb-api:2.3.1'
  236. kapt 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  237. kapt 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  238. annotationProcessor 'javax.xml.bind:jaxb-api:2.3.1'
  239. annotationProcessor 'org.glassfish.jaxb:jaxb-core:2.3.0.1'
  240. annotationProcessor 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
  241. 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
  242. implementation "commons-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
  243. implementation 'org.apache.jackrabbit:jackrabbit-webdav:2.13.1' // remove after entire switch to lib v2
  244. implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
  245. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  246. implementation 'com.google.android.material:material:1.2.1'
  247. implementation 'com.jakewharton:disklrucache:2.0.2'
  248. implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
  249. implementation 'androidx.cardview:cardview:1.0.0'
  250. implementation 'androidx.exifinterface:exifinterface:1.3.0'
  251. implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
  252. implementation "androidx.work:work-runtime:2.4.0"
  253. implementation "androidx.work:work-runtime-ktx:2.4.0"
  254. implementation "androidx.fragment:fragment:1.2.5"
  255. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  256. compileOnly 'com.google.code.findbugs:annotations:2.0.1'
  257. implementation 'commons-io:commons-io:2.8.0'
  258. implementation "com.jakewharton:butterknife:$butterknifeVersion"
  259. kapt "com.jakewharton:butterknife-compiler:$butterknifeVersion"
  260. implementation 'org.greenrobot:eventbus:3.2.0'
  261. implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.0'
  262. implementation 'org.lukhnos:nnio:0.2'
  263. implementation 'org.bouncycastle:bcpkix-jdk15on:1.65'
  264. implementation 'com.google.code.gson:gson:2.8.6'
  265. implementation 'com.afollestad:sectioned-recyclerview:0.5.0'
  266. implementation 'com.github.chrisbanes:PhotoView:2.3.0'
  267. implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.21'
  268. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  269. implementation 'com.google.android:flexbox:2.0.1'
  270. implementation 'org.parceler:parceler-api:1.1.13'
  271. kapt 'org.parceler:parceler:1.1.13'
  272. implementation('com.github.bumptech.glide:glide:3.8.0') {
  273. exclude group: "com.android.support"
  274. }
  275. implementation 'com.caverock:androidsvg:1.4'
  276. implementation 'androidx.annotation:annotation:1.1.0'
  277. implementation 'com.google.code.gson:gson:2.8.6'
  278. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido:4.1.0'
  279. implementation 'com.github.cotechde.hwsecurity:hwsecurity-fido2:4.1.0'
  280. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
  281. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
  282. implementation "com.google.dagger:dagger:$daggerVersion"
  283. implementation "com.google.dagger:dagger-android:$daggerVersion"
  284. implementation "com.google.dagger:dagger-android-support:$daggerVersion"
  285. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  286. kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
  287. ktlint "com.pinterest:ktlint:0.39.0"
  288. implementation 'org.conscrypt:conscrypt-android:2.5.1'
  289. // Shimmer animation
  290. implementation 'com.elyeproj.libraries:loaderviewlibrary:2.0.0'
  291. // dependencies for markdown rendering
  292. implementation "io.noties.markwon:core:$markwonVersion"
  293. implementation "io.noties.markwon:ext-strikethrough:$markwonVersion"
  294. implementation "io.noties.markwon:ext-tables:$markwonVersion"
  295. implementation "io.noties.markwon:ext-tasklist:$markwonVersion"
  296. implementation "io.noties.markwon:html:$markwonVersion"
  297. implementation "io.noties.markwon:syntax-highlight:$markwonVersion"
  298. implementation "io.noties:prism4j:$prismVersion"
  299. kapt "io.noties:prism4j-bundler:$prismVersion"
  300. // dependencies for local unit tests
  301. testImplementation 'junit:junit:4.13'
  302. testImplementation "org.mockito:mockito-core:$mockitoVersion"
  303. testImplementation 'androidx.test:core:1.3.0'
  304. testImplementation 'org.powermock:powermock-core:2.0.7'
  305. testImplementation 'org.powermock:powermock-module-junit4:2.0.7'
  306. testImplementation 'org.powermock:powermock-api-mockito2:2.0.7'
  307. testImplementation 'org.json:json:20200518'
  308. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  309. testImplementation 'androidx.arch.core:core-testing:2.1.0'
  310. testImplementation 'io.mockk:mockk:1.10.0'
  311. testImplementation 'io.mockk:mockk-android:1.10.0'
  312. // dependencies for instrumented tests
  313. // JUnit4 Rules
  314. androidTestImplementation 'androidx.test.ext:junit:1.1.2'
  315. androidTestImplementation 'androidx.test:rules:1.3.0'
  316. // Android JUnit Runner
  317. androidTestImplementation 'androidx.test:runner:1.3.0'
  318. androidTestUtil 'androidx.test:orchestrator:1.3.0'
  319. // Espresso core
  320. androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
  321. androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
  322. androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
  323. // Mocking support
  324. androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
  325. androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
  326. androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
  327. androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
  328. exclude group: "net.bytebuddy", module: "byte-buddy-android"
  329. }
  330. androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
  331. androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
  332. androidTestImplementation "io.mockk:mockk-android:1.10.0"
  333. androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
  334. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  335. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  336. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  337. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  338. androidTestImplementation 'tools.fastlane:screengrab:2.0.0'
  339. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  340. androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
  341. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  342. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  343. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  344. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  345. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  346. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  347. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  348. implementation "com.github.stateless4j:stateless4j:2.6.0"
  349. }
  350. spotbugs {
  351. toolVersion = '3.1.12'
  352. }
  353. configurations.all {
  354. resolutionStrategy{
  355. cacheChangingModulesFor 0, 'seconds'
  356. force 'org.objenesis:objenesis:2.6'
  357. }
  358. }
  359. tasks.withType(Test) {
  360. // increased logging for tests
  361. testLogging {
  362. events "passed", "skipped", "failed"
  363. }
  364. }
  365. android.applicationVariants.all { variant ->
  366. variant.outputs.all { output ->
  367. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  368. }
  369. }
  370. tasks.register("combinedTestReport", JacocoReport) {
  371. reports {
  372. xml.enabled true
  373. html.enabled true
  374. csv.enabled false
  375. }
  376. additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  377. sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
  378. classDirectories.setFrom files(subprojects.sourceSets.main.output)
  379. executionData.setFrom project.fileTree(dir: project.buildDir, includes: [
  380. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  381. ])
  382. }
  383. task ktlint(type: JavaExec, group: "verification") {
  384. description = "Check Kotlin code style."
  385. main = "com.pinterest.ktlint.Main"
  386. classpath = configurations.ktlint
  387. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  388. }
  389. task ktlintFormat(type: JavaExec, group: "formatting") {
  390. description = "Fix Kotlin code style deviations."
  391. main = "com.pinterest.ktlint.Main"
  392. classpath = configurations.ktlint
  393. args "-F", "src/**/*.kt"
  394. }
  395. detekt {
  396. reports {
  397. xml {
  398. enabled = false
  399. }
  400. }
  401. config = files("detekt.yml")
  402. input = files("src/")
  403. }