summaryrefslogtreecommitdiffhomepage
path: root/android/build.gradle.kts
blob: b43f4fec860dde7e07d92555000f89dbafd7754e (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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask

plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.android.library) apply false
    alias(libs.plugins.android.test) apply false
    alias(libs.plugins.dependency.check) apply false
    alias(libs.plugins.ktfmt) apply false
    alias(libs.plugins.compose) apply false
    alias(libs.plugins.play.publisher) apply false
    alias(libs.plugins.kotlin.android) apply false
    alias(libs.plugins.kotlin.ksp) apply false
    alias(libs.plugins.kotlin.parcelize) apply false
    alias(libs.plugins.protobuf.core) apply false
    alias(libs.plugins.rust.android.gradle) apply false

    alias(libs.plugins.detekt) apply true
    alias(libs.plugins.dependency.versions) apply true
}

buildscript {
    repositories {
        google()
        mavenCentral()
        maven(Repositories.GradlePlugins)
        gradlePluginPortal()
    }
    dependencies {
        // Dependency class paths are required for Gradle metadata verification to work properly,
        // see:
        // https://github.com/gradle/gradle/issues/19228s
        //noinspection UseTomlInstead
        val aapt = libs.android.gradle.aapt.get().toString()
        val aaptVersion = libs.versions.android.gradle.aapt.get()
        val agpVersion = libs.versions.android.gradle.plugin.get()
        classpath("$aapt:$agpVersion-$aaptVersion:linux")
        classpath("$aapt:$agpVersion-$aaptVersion:osx")
        classpath("$aapt:$agpVersion-$aaptVersion:windows")

        // Protoc plugin
        val protoc = libs.plugins.protobuf.protoc.get().toString()
        classpath("$protoc:linux-aarch_64@exe")
        classpath("$protoc:linux-ppcle_64@exe")
        classpath("$protoc:linux-s390_64@exe")
        classpath("$protoc:linux-x86_32@exe")
        classpath("$protoc:linux-x86_64@exe")
        classpath("$protoc:osx-aarch_64@exe")
        classpath("$protoc:osx-x86_64@exe")
        classpath("$protoc:windows-x86_32@exe")
        classpath("$protoc:windows-x86_64@exe")

        // ProtoC gen grpc java plugin
        val protocJava = libs.plugins.grpc.protoc.gen.grpc.java.get().toString()
        classpath("$protocJava:linux-aarch_64@exe")
        classpath("$protocJava:linux-ppcle_64@exe")
        classpath("$protocJava:linux-s390_64@exe")
        classpath("$protocJava:linux-x86_32@exe")
        classpath("$protocJava:linux-x86_64@exe")
        classpath("$protocJava:osx-aarch_64@exe")
        classpath("$protocJava:osx-x86_64@exe")
        classpath("$protocJava:windows-x86_32@exe")
        classpath("$protocJava:windows-x86_64@exe")

        // Kotlin Native Prebuilt
        val prebuilt = libs.kotlin.native.prebuilt.get().toString()
        classpath("$prebuilt:windows-x86_64@zip")
        classpath("$prebuilt:linux-x86_64@tar.gz")
        classpath("$prebuilt:macos-aarch64@tar.gz")
        classpath("$prebuilt:macos-x86_64@tar.gz")

        classpath("org.mozilla.rust-android-gradle:plugin:${libs.versions.rust.android.gradle}")
    }
}

val configFile = files("$rootDir/config/detekt.yml")

val projectSource = file(projectDir)
val detektExcludedPaths = listOf("**/build/**", "**/mullvad_daemon/management_interface/**")

detekt {
    buildUponDefaultConfig = true
    allRules = false
    config.setFrom(configFile)
    source.setFrom(projectSource)
    parallel = true
    ignoreFailures = false
    autoCorrect = true
}

tasks.withType<Detekt>().configureEach {
    // Ignore generated files from the build directory, e.g files created by ksp.
    exclude(detektExcludedPaths)
}

tasks.withType<DetektCreateBaselineTask>().configureEach {
    // Ignore generated files from the build directory, e.g files created by ksp.
    exclude(detektExcludedPaths)
}

allprojects {
    apply(plugin = rootProject.libs.plugins.dependency.check.get().pluginId)
    apply(plugin = rootProject.libs.plugins.ktfmt.get().pluginId)

    repositories {
        google()
        mavenCentral()
    }

    configure<org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension> {
        failBuildOnCVSS = 0F // All severity levels
        suppressionFiles =
            listOf(
                "${rootProject.projectDir}/config/dependency-check-suppression.xml",
                "${rootProject.projectDir}/config/dependency-check-suppression-agp-fixes.xml",
            )
    }

    configure<com.ncorti.ktfmt.gradle.KtfmtExtension> {
        kotlinLangStyle()
        maxWidth.set(100)
        removeUnusedImports.set(true)
    }
}

tasks.withType<DependencyUpdatesTask> {
    gradleReleaseChannel = "current"
    rejectVersionIf { candidate.version.isNonStableVersion() }
}

tasks.register("clean", Delete::class) { delete(rootProject.layout.buildDirectory) }