build.gradle 18 KB

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