// Top-level build file where you can add configuration options common to all sub-projects/modules. import ca.rmen.lfrc.FrenchRevolutionaryCalendar import java.text.SimpleDateFormat ext.globalProjectName = 'bikey' buildscript { // Versions used across modules ext.versions = [:] ext.versions.with { androidGradlePlugin = '2.4.0-alpha6' gradleVersionsPlugin = '0.14.0' fabricPlugin = '1.22.1' dexCountPlugin = '0.6.4' acpgPlugin = '1.13.1' libFrc = '1.5.2' compileSdk = 24 targetSdk = 22 buildTools = '25.0.2' supportLibrary = '25.3.1' playServices = '10.2.1' espresso = '2.2.2' junit = '4.12' robolectric = '3.3.2' fest = '2.0M10' multidex = '1.0.1' rxJava = '2.0.8' rxAndroid = '2.0.1' wearCrashReport = '0.6' crashlytics = '2.6.7' androidWearable = '2.0.1' } repositories { mavenLocal() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath "com.android.tools.build:gradle:$versions.androidGradlePlugin" classpath "com.github.ben-manes:gradle-versions-plugin:$versions.gradleVersionsPlugin" classpath "ca.rmen:lib-french-revolutionary-calendar:$versions.libFrc" classpath "io.fabric.tools:gradle:$versions.fabricPlugin" classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$versions.dexCountPlugin" classpath "org.jraf:acpg-gradle-plugin:$versions.acpgPlugin" } } allprojects { repositories { mavenLocal() jcenter() mavenCentral() maven { url 'https://jitpack.io' } maven { url 'https://maven.fabric.io/public' } } // Force using our version of the support libraries, even for those we don't depend on directly (transitive dependencies) configurations.all { resolutionStrategy { force "com.android.support:appcompat-v7:$versions.supportLibrary", "com.android.support:cardview-v7:$versions.supportLibrary", "com.android.support:customtabs:$versions.supportLibrary", "com.android.support:support-v4:$versions.supportLibrary", "com.android.support:support-annotations:$versions.supportLibrary", "com.android.support:percent:$versions.supportLibrary", "com.android.support:recyclerview-v7:$versions.supportLibrary" } } // Show a report in the log when running tests tasks.withType(Test) { testLogging { events "passed", "skipped", "failed", "standardOut", "standardError" } } } task clean(type: Delete) { delete rootProject.buildDir } task wrapper(type: Wrapper) { gradleVersion = '3.5' distributionType = Wrapper.DistributionType.ALL } // Add a 'release' task that increments the build number def releaseTask = tasks.create(name: 'release', group: 'build') releaseTask.doLast { buildNumberProperties.buildNumber = (buildNumber + 1).toString() buildNumberProperties.store(buildNumberFile.newWriter(), null) } // Make the 'release' task depend on the 'assembleRelease' task of every subprojects subprojects { tasks.whenTaskAdded { task -> if (task.name == 'assembleRelease') { releaseTask.dependsOn task } } } // Run './gradlew dependencyUpdates' to see new versions of dependencies apply plugin: 'com.github.ben-manes.versions' dependencyUpdates.resolutionStrategy = { componentSelection { rules -> rules.all { selection -> boolean rejected = ['alpha', 'beta', 'rc', '20050927'].any { qualifier -> selection.candidate.version ==~ /.*-${qualifier}.*/ } if (rejected) { selection.reject('Release candidate') } } } } // Returns the name of the current git branch def gitBranch() { new ProcessBuilder('git', "--git-dir=${rootDir}/.git", "--work-tree=${rootDir}", 'rev-parse', '--abbrev-ref', 'HEAD').start().text.trim() } // Returns the SHA1 of the current git commit def gitSha1() { new ProcessBuilder('git', "--git-dir=${rootDir}/.git", "--work-tree=${rootDir}", 'rev-parse', '--short', 'HEAD').start().text.trim() } // Returns the current date/time formatted in UTC static def buildDate() { def dateFormat = new SimpleDateFormat('yyyy-MM-dd\'T\'HH:mm\'Z\'') dateFormat.setTimeZone(TimeZone.getTimeZone('UTC')) return dateFormat.format(new Date()) } // This only for amusement purposes static def getFrenchDate() { def frenchDate = new FrenchRevolutionaryCalendar(Locale.FRENCH, FrenchRevolutionaryCalendar.CalculationMethod.ROMME).getDate(GregorianCalendar.getInstance()) "Le ${frenchDate.weekdayName} ${frenchDate.dayOfMonth} ${frenchDate.monthName} de l'an ${frenchDate.year}. (${frenchDate.objectTypeName} du jour : ${frenchDate.dayOfYear})" } // Returns a file on the project's root - creates it from a sample if it doesn't exist def getAndCreateIfNotExists(String fileName) { def res = file(fileName) if (!res.exists()) { logger.warn("$fileName file does not exist: creating it now - please check its values") copy { from "${fileName}.SAMPLE" into project.projectDir rename { fileName } } } return res } // Build properties ext.buildProperties = new Properties() def buildPropertiesFile = getAndCreateIfNotExists('build.properties') buildProperties.load(new FileInputStream(buildPropertiesFile)) // Build number ext.buildNumberProperties = new Properties() ext.buildNumberFile = getAndCreateIfNotExists('build.number') buildNumberProperties.load(new FileInputStream(buildNumberFile)) ext.buildNumber = buildNumberProperties.buildNumber.toInteger() // Build info ext.gitBranch = gitBranch() ext.gitSha1 = gitSha1() ext.buildDate = buildDate() // Splash screen println """\n ====================================\u001B[95m _____ ___ ____ __ / / _ \\/ _ | / __/___ _______ _ / // / , _/ __ |/ _/_/ _ \\/ __/ _ `/ \\___/_/¦_/_/ |_/_/ (_)___/_/ \\_, / /___/ \u001B[0m Building ${globalProjectName}. ${getFrenchDate()} rootDir: ${rootDir} buildDate: ${buildDate} versionCode: ${buildNumberProperties.buildNumber} versionName: ${buildProperties.versionName} gitBranch: ${gitBranch} gitSha1: ${gitSha1} ==================================== """