summaryrefslogtreecommitdiff
path: root/build.gradle
blob: ce058638e78e012c489e3e621a3bca54a7278847 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Copyright (C) 2022 E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import foundation.e.privacycentral.buildsrc.DependencyUpdates
import foundation.e.privacycentral.buildsrc.ReleaseType

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.buildConfig = [
        'compileSdk': 31,
        'minSdk'    : 26,
        'targetSdk' : 31,
        'version'   : [
            'major': 1,
            'minor': 11,
            'patch': 0,
        ],
    ]

    ext.buildConfig.version['name'] = "${buildConfig.version.major}.${buildConfig.version.minor}.${buildConfig.version.patch}"
    ext.buildConfig.version['fullName'] = "${buildConfig.version.name}-${buildConfig.version.build}"
    ext.buildConfig.version['code'] = buildConfig.version.major * 1000000 + buildConfig.version.minor * 1000 + buildConfig.version.patch

    // Load properties either from local.properties or system environment (on CI).
    apply from: rootProject.file('load-properties.gradle')

    // Load dependencies as extra properties.
    apply from: rootProject.file('dependencies.gradle')

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath Libs.androidGradlePlugin
        classpath Libs.Kotlin.gradlePlugin

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

plugins {
    id 'com.diffplug.spotless' version '5.12.4'
    id 'com.github.ben-manes.versions' version '0.38.0'
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

allprojects {
    //Support @JvmDefault, and @OptIn
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            freeCompilerArgs = ['-Xjvm-default=enable', '-opt-in=kotlin.RequiresOptIn']

            jvmTarget = "1.8"
        }
    }

    repositories {
        google()
        mavenCentral()
        maven {
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                // Do not change the username below.
                // This should always be `mapbox` (not your username).
                username = 'mapbox'
                // Use the secret token you stored in gradle.properties as the password
                password = MAPBOX_SECRET_KEY ?: ""
            }
        }
        maven { url "https://raw.githubusercontent.com/guardianproject/gpmaven/master" }
        maven { url 'https://gitlab.e.foundation/api/v4/groups/9/-/packages/maven' }
        maven { url 'https://jitpack.io' }

        def ciJobToken = System.getenv("CI_JOB_TOKEN")
        def ciApiV4Url = System.getenv("CI_API_V4_URL")
        if (ciJobToken != null) {
            maven {
                url "${ciApiV4Url}/groups/9/-/packages/maven"
                name "GitLab"
                credentials(HttpHeaderCredentials) {
                    name = 'Job-Token'
                    value = ciJobToken
                }
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
        } else {
            mavenLocal()
            maven {
                url "https://gitlab.e.foundation/api/v4/groups/9/-/packages/maven"
                name "GitLab"
                credentials(HttpHeaderCredentials) {
                    name = 'Private-Token'
                    value = gitLabPrivateToken
                }
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
        }
    }
}

subprojects {
    apply plugin: 'com.diffplug.spotless'
    spotless {
        kotlin {
            target '**/*.kt'
            targetExclude("$buildDir/**/*.kt")
            targetExclude('bin/**/*.kt')
            targetExclude '**/spotless/*.kt'
            ktlint(Versions.ktlint)
        }
        format 'misc', {
            // define the files to apply `misc` to
            target '*.gradle', '*.md', '.gitignore'

            // define the steps to apply to those files
            trimTrailingWhitespace()
            endWithNewline()
        }
    }

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
        kotlinOptions {
            // Treat all Kotlin warnings as errors
            allWarningsAsErrors = true

            freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
            // Set JVM target to 1.8
            jvmTarget = "1.8"
        }
    }
}

/**
 * Update dependencyUpdates task to reject versions which are more 'unstable' than our
 * current version.
 */
tasks.named("dependencyUpdates").configure {
    rejectVersionIf {
        def current = DependencyUpdates.versionToRelease(it.currentVersion)
        // If we're using a SNAPSHOT, ignore since we must be doing so for a reason.
        if (current == ReleaseType.SNAPSHOT) return true

        // Otherwise we reject if the candidate is more 'unstable' than our version
        def candidate = DependencyUpdates.versionToRelease(it.candidate.version)
        return candidate.isLessStableThan(current)
    }
}

Object propOrDef(String propertyName, Object defaultValue) {
    def propertyValue = project.properties[propertyName]
    return propertyValue != null ? propertyValue : defaultValue
}

apply from: file('gradle/dependencyGraph.gradle')