build.gradle 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. // Gradle build file
  2. //
  3. // This project was started in Eclipse and later moved to Android Studio. In the transition, both IDEs were supported.
  4. // Due to this, the files layout is not the usual in new projects created with Android Studio / gradle. This file
  5. // merges declarations usually split in two separates build.gradle file, one for global settings of the project in
  6. // its root folder, another one for the app module in subfolder of root.
  7. import com.github.spotbugs.SpotBugsTask
  8. buildscript {
  9. ext.kotlin_version = '1.3.41'
  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:3.4.2'
  23. classpath('com.dicedmelon.gradle:jacoco-android:0.1.4') {
  24. exclude group: 'org.codehaus.groovy', module: 'groovy-all'
  25. }
  26. classpath 'gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.6'
  27. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  28. classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.0.0-RC14"
  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: 'jacoco-android'
  38. apply plugin: "com.github.spotbugs"
  39. apply plugin: "io.gitlab.arturbosch.detekt"
  40. configurations {
  41. ktlint
  42. all {
  43. exclude group: 'com.google.firebase', module: 'firebase-core'
  44. exclude group: 'com.google.firebase', module: 'firebase-analytics'
  45. exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
  46. // check for updates every build
  47. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  48. }
  49. }
  50. ext {
  51. jacocoVersion = "0.8.2"
  52. androidLibraryVersion = "master-SNAPSHOT"
  53. travisBuild = System.getenv("TRAVIS") == "true"
  54. // allows for -Dpre-dex=false to be set
  55. preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
  56. }
  57. repositories {
  58. google()
  59. jcenter()
  60. maven { url "https://jitpack.io" }
  61. maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
  62. flatDir {
  63. dirs 'libs'
  64. }
  65. }
  66. // semantic versioning for version code
  67. def versionMajor = 3
  68. def versionMinor = 8
  69. def versionPatch = 0
  70. def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable
  71. def taskRequest = getGradle().getStartParameter().getTaskRequests().toString()
  72. if (taskRequest.contains("Gplay") || taskRequest.contains("lint")) {
  73. apply from: 'gplay.gradle'
  74. }
  75. spotbugs {
  76. toolVersion = '3.1.12'
  77. }
  78. android {
  79. lintOptions {
  80. abortOnError false
  81. htmlReport true
  82. htmlOutput file("$project.buildDir/reports/lint/lint.html")
  83. disable 'MissingTranslation', 'GradleDependency', 'VectorPath', 'IconMissingDensityFolder', 'IconDensities'
  84. }
  85. dexOptions {
  86. javaMaxHeapSize "4g"
  87. }
  88. compileSdkVersion 28
  89. defaultConfig {
  90. minSdkVersion 14
  91. targetSdkVersion 28
  92. // arguments to be passed to functional tests
  93. testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
  94. testInstrumentationRunnerArgument "TEST_SERVER_URL", "${NC_TEST_SERVER_BASEURL}"
  95. testInstrumentationRunnerArgument "TEST_SERVER_USERNAME", "${NC_TEST_SERVER_USERNAME}"
  96. testInstrumentationRunnerArgument "TEST_SERVER_PASSWORD", "${NC_TEST_SERVER_PASSWORD}"
  97. multiDexEnabled true
  98. versionCode versionMajor * 10000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
  99. if (versionBuild > 89) {
  100. versionName "${versionMajor}.${versionMinor}.${versionPatch}"
  101. } else if (versionBuild > 50) {
  102. versionName "${versionMajor}.${versionMinor}.${versionPatch} RC" + (versionBuild - 50)
  103. } else {
  104. versionName "${versionMajor}.${versionMinor}.${versionPatch} Alpha" + (versionBuild + 1)
  105. }
  106. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  107. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  108. flavorDimensions "default"
  109. buildTypes {
  110. debug {
  111. testCoverageEnabled (project.hasProperty('coverage'))
  112. }
  113. }
  114. productFlavors {
  115. // used for f-droid
  116. generic {
  117. applicationId 'com.nextcloud.client'
  118. dimension "default"
  119. }
  120. gplay {
  121. applicationId 'com.nextcloud.client'
  122. dimension "default"
  123. }
  124. versionDev {
  125. applicationId "com.nextcloud.android.beta"
  126. dimension "default"
  127. versionCode 20190724
  128. versionName "20190724"
  129. }
  130. qa {
  131. applicationId "com.nextcloud.android.qa"
  132. dimension "default"
  133. versionCode 1
  134. versionName "1"
  135. }
  136. }
  137. }
  138. // adapt structure from Eclipse to Gradle/Android Studio expectations;
  139. // see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
  140. dexOptions {
  141. // Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
  142. preDexLibraries = preDexEnabled && !travisBuild
  143. }
  144. packagingOptions {
  145. exclude 'META-INF/LICENSE.txt'
  146. exclude 'META-INF/LICENSE'
  147. }
  148. tasks.register("checkstyle", Checkstyle) {
  149. configFile = file("${rootProject.projectDir}/checkstyle.xml")
  150. configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
  151. source 'src'
  152. include '**/*.java'
  153. exclude '**/gen/**'
  154. classpath = files()
  155. }
  156. tasks.register("pmd", Pmd) {
  157. ruleSetFiles = files("${project.rootDir}/ruleset.xml")
  158. ignoreFailures = false
  159. ruleSets = []
  160. source 'src'
  161. include '**/*.java'
  162. exclude '**/gen/**'
  163. reports {
  164. xml.enabled = false
  165. html.enabled = true
  166. xml {
  167. destination = file("$project.buildDir/reports/pmd/pmd.xml")
  168. }
  169. html {
  170. destination = file("$project.buildDir/reports/pmd/pmd.html")
  171. }
  172. }
  173. }
  174. android.applicationVariants.all { variant ->
  175. String variantName = variant.name
  176. String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
  177. tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
  178. ignoreFailures = false
  179. effort = "max"
  180. reportLevel = "medium"
  181. classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/compile${capVariantName}JavaWithJavac/classes/")
  182. excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
  183. pluginClasspath = project.configurations.spotbugsPlugins
  184. source = fileTree('src/main/java')
  185. classpath = files()
  186. include '**/*.java'
  187. exclude '**/gen/**'
  188. reports {
  189. xml.enabled = false
  190. html.enabled = true
  191. html {
  192. destination = file("$project.buildDir/reports/spotbugs/spotbugs.html")
  193. }
  194. }
  195. }
  196. }
  197. check.dependsOn 'checkstyle', 'spotbugs', 'pmd', 'lint', 'ktlint'
  198. compileOptions {
  199. sourceCompatibility JavaVersion.VERSION_1_8
  200. targetCompatibility JavaVersion.VERSION_1_8
  201. }
  202. }
  203. dependencies {
  204. // dependencies for app building
  205. implementation 'androidx.multidex:multidex:2.0.1'
  206. // implementation project('nextcloud-android-library')
  207. genericImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  208. gplayImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  209. versionDevImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  210. qaImplementation "com.github.nextcloud:android-library:$androidLibraryVersion"
  211. implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
  212. implementation 'androidx.legacy:legacy-support-v4:1.0.0'
  213. implementation 'com.google.android.material:material:1.0.0'
  214. implementation 'com.jakewharton:disklrucache:2.0.2'
  215. implementation 'androidx.appcompat:appcompat:1.0.2'
  216. implementation 'androidx.cardview:cardview:1.0.0'
  217. implementation 'androidx.exifinterface:exifinterface:1.0.0'
  218. implementation 'com.github.albfernandez:juniversalchardet:2.0.3' // need this version for Android <7
  219. implementation 'com.google.code.findbugs:annotations:2.0.1'
  220. implementation 'commons-io:commons-io:2.6'
  221. implementation 'com.github.tobiaskaminsky:android-job:v1.2.6.1' // 'com.github.evernote:android-job:v1.2.5'
  222. implementation 'com.jakewharton:butterknife:10.1.0'
  223. kapt 'com.jakewharton:butterknife-compiler:10.1.0'
  224. implementation 'org.greenrobot:eventbus:3.1.1'
  225. implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
  226. implementation 'org.lukhnos:nnio:0.2'
  227. implementation 'com.madgag.spongycastle:pkix:1.54.0.0'
  228. implementation 'com.google.code.gson:gson:2.8.5'
  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.15'
  232. implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
  233. implementation 'com.google.android:flexbox:1.1.0'
  234. implementation 'org.parceler:parceler-api:1.1.12'
  235. kapt 'org.parceler:parceler:1.1.12'
  236. implementation('com.github.bumptech.glide:glide:3.7.0') {
  237. exclude group: "com.android.support"
  238. }
  239. implementation 'com.caverock:androidsvg:1.4'
  240. implementation 'androidx.annotation:annotation:1.1.0'
  241. implementation 'com.google.code.gson:gson:2.8.5'
  242. implementation 'org.jetbrains:annotations:17.0.0'
  243. spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
  244. spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.6'
  245. implementation 'com.google.dagger:dagger:2.23.2'
  246. implementation 'com.google.dagger:dagger-android:2.23.2'
  247. implementation 'com.google.dagger:dagger-android-support:2.23.2'
  248. kapt 'com.google.dagger:dagger-compiler:2.23.2'
  249. kapt 'com.google.dagger:dagger-android-processor:2.23.2'
  250. compileOnly "org.projectlombok:lombok:1.18.8"
  251. annotationProcessor "org.projectlombok:lombok:1.18.8"
  252. ktlint "com.pinterest:ktlint:0.34.2"
  253. // dependencies for local unit tests
  254. testImplementation 'junit:junit:4.12'
  255. testImplementation 'org.mockito:mockito-core:3.0.0'
  256. testImplementation 'androidx.test:core:1.2.0'
  257. testImplementation 'org.powermock:powermock-core:2.0.2'
  258. testImplementation 'org.powermock:powermock-module-junit4:2.0.2'
  259. testImplementation 'org.powermock:powermock-api-mockito2:2.0.2'
  260. testImplementation 'org.json:json:20180813'
  261. testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0"
  262. // dependencies for instrumented tests
  263. // JUnit4 Rules
  264. androidTestImplementation 'androidx.test.ext:junit:1.1.1'
  265. androidTestImplementation 'androidx.test:rules:1.2.0'
  266. // Android JUnit Runner
  267. androidTestImplementation 'androidx.test:runner:1.2.0'
  268. // Espresso core
  269. androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  270. androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
  271. androidTestImplementation 'org.mockito:mockito-core:2.28.2'
  272. // UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
  273. // androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
  274. // fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
  275. //androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
  276. androidTestImplementation 'tools.fastlane:screengrab:1.2.0'
  277. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
  278. // jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  279. // jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  280. // androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  281. // androidJacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
  282. // androidJacocoAnt "org.jacoco:org.jacoco.core:${jacocoVersion}"
  283. // androidJacocoAnt "org.jacoco:org.jacoco.report:${jacocoVersion}"
  284. // androidJacocoAnt "org.jacoco:org.jacoco.agent:${jacocoVersion}"
  285. }
  286. configurations.all {
  287. resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  288. }
  289. tasks.withType(Test) {
  290. // increased logging for tests
  291. testLogging {
  292. events "passed", "skipped", "failed"
  293. }
  294. }
  295. android.applicationVariants.all { variant ->
  296. variant.outputs.all { output ->
  297. outputFileName = "${output.baseName}-${variant.versionCode}.apk"
  298. }
  299. }
  300. tasks.register("combinedTestReport", JacocoReport) {
  301. reports {
  302. xml.enabled = true
  303. html.enabled = true
  304. }
  305. def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
  306. def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/gplay/debug", excludes: fileFilter)
  307. def mainSrc = "$project.projectDir/src/main/java"
  308. sourceDirectories = files([mainSrc])
  309. classDirectories = files([debugTree])
  310. executionData = fileTree(dir: project.buildDir, includes: [
  311. 'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
  312. ])
  313. }
  314. task ktlint(type: JavaExec, group: "verification") {
  315. description = "Check Kotlin code style."
  316. main = "com.pinterest.ktlint.Main"
  317. classpath = configurations.ktlint
  318. args "--reporter=plain", "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
  319. }
  320. task ktlintFormat(type: JavaExec, group: "formatting") {
  321. description = "Fix Kotlin code style deviations."
  322. main = "com.pinterest.ktlint.Main"
  323. classpath = configurations.ktlint
  324. args "-F", "src/**/*.kt"
  325. }
  326. detekt {
  327. reports {
  328. xml {
  329. enabled = false
  330. }
  331. }
  332. config = files("detekt.yml")
  333. input = files("src/")
  334. }