|
| 1 | +/* |
| 2 | + * Copyright 2024, TeamDev. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Redistribution and use in source and/or binary forms, with or without |
| 11 | + * modification, must retain the above copyright notice and the following |
| 12 | + * disclaimer. |
| 13 | + * |
| 14 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | + */ |
| 26 | + |
| 27 | +/** |
| 28 | + * This script uses two declarations of the constant [licenseReportVersion] because |
| 29 | + * currently there is no way to define a constant _before_ a build script of `buildSrc`. |
| 30 | + * We cannot use imports or do something else before the `buildscript` or `plugin` clauses. |
| 31 | + */ |
| 32 | + |
| 33 | +plugins { |
| 34 | + java |
| 35 | + groovy |
| 36 | + `kotlin-dsl` |
| 37 | + kotlin("jvm") version "1.8.20" apply false |
| 38 | + |
| 39 | + // https://github.com/jk1/Gradle-License-Report/releases |
| 40 | + id("com.github.jk1.dependency-license-report").version("1.16") |
| 41 | + // https://github.com/johnrengelman/shadow/releases |
| 42 | + id("com.github.johnrengelman.shadow").version("6.1.0") |
| 43 | +} |
| 44 | + |
| 45 | +repositories { |
| 46 | + mavenLocal() |
| 47 | + gradlePluginPortal() |
| 48 | + mavenCentral() |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * The version of Spine Bootstrap plugin, |
| 53 | + * applied within this `buildSrc`. |
| 54 | + * |
| 55 | + * It is expected that this version is the same, |
| 56 | + * as the versions of Spine server- and client-related libraries |
| 57 | + * on top of which the Spine application is running. |
| 58 | + * |
| 59 | + * See `Spine` dependency object. |
| 60 | + */ |
| 61 | +val spineVersion = "1.9.0" |
| 62 | + |
| 63 | +/** |
| 64 | + * The version of Jackson used by `buildSrc`. |
| 65 | + * |
| 66 | + * Please keep this value in sync with [io.spine.internal.dependency.Jackson.version]. |
| 67 | + * It is not a requirement but would be good in terms of consistency. |
| 68 | + */ |
| 69 | +val jacksonVersion = "2.14.3" |
| 70 | + |
| 71 | +/** |
| 72 | + * The version of Google Artifact Registry used by `buildSrc`. |
| 73 | + * |
| 74 | + * The version `2.1.5` is the latest before `2.2.0`, which introduces breaking changes. |
| 75 | + * |
| 76 | + * @see <a href="https://mvnrepository.com/artifact/com.google.cloud.artifactregistry/artifactregistry-auth-common"> |
| 77 | + * Google Artifact Registry at Maven</a> |
| 78 | + */ |
| 79 | +val googleAuthToolVersion = "2.1.5" |
| 80 | + |
| 81 | +val licenseReportVersion = "1.16" |
| 82 | + |
| 83 | +val grGitVersion = "4.1.1" |
| 84 | + |
| 85 | +/** |
| 86 | + * The version of the Kotlin Gradle plugin and Kotlin binaries used by the build process. |
| 87 | + * |
| 88 | + * This version may change from the [version of Kotlin][io.spine.internal.dependency.Kotlin.version] |
| 89 | + * used by the project. |
| 90 | + */ |
| 91 | +val kotlinVersion = "1.8.22" |
| 92 | + |
| 93 | +/** |
| 94 | + * The version of Guava used in `buildSrc`. |
| 95 | + * |
| 96 | + * Always use the same version as the one specified in [io.spine.internal.dependency.Guava]. |
| 97 | + * Otherwise, when testing Gradle plugins, clashes may occur. |
| 98 | + */ |
| 99 | +val guavaVersion = "31.1-jre" |
| 100 | + |
| 101 | +/** |
| 102 | + * The version of ErrorProne Gradle plugin. |
| 103 | + * |
| 104 | + * Please keep in sync. with [io.spine.internal.dependency.ErrorProne.GradlePlugin.version]. |
| 105 | + * |
| 106 | + * @see <a href="https://github.com/tbroyer/gradle-errorprone-plugin/releases"> |
| 107 | + * Error Prone Gradle Plugin Releases</a> |
| 108 | + */ |
| 109 | +val errorPronePluginVersion = "3.1.0" |
| 110 | + |
| 111 | +/** |
| 112 | + * The version of Protobuf Gradle Plugin. |
| 113 | + * |
| 114 | + * Please keep in sync. with [io.spine.internal.dependency.Protobuf.GradlePlugin.version]. |
| 115 | + * |
| 116 | + * @see <a href="https://github.com/google/protobuf-gradle-plugin/releases"> |
| 117 | + * Protobuf Gradle Plugins Releases</a> |
| 118 | + */ |
| 119 | +//val protobufPluginVersion = "0.8.19" |
| 120 | + |
| 121 | +/** |
| 122 | + * The version of Dokka Gradle Plugins. |
| 123 | + * |
| 124 | + * Please keep in sync with [io.spine.internal.dependency.Dokka.version]. |
| 125 | + * |
| 126 | + * @see <a href="https://github.com/Kotlin/dokka/releases"> |
| 127 | + * Dokka Releases</a> |
| 128 | + */ |
| 129 | +val dokkaVersion = "1.9.20" |
| 130 | + |
| 131 | +/** |
| 132 | + * The version of Detekt Gradle Plugin. |
| 133 | + * |
| 134 | + * @see <a href="https://github.com/detekt/detekt/releases">Detekt Releases</a> |
| 135 | + */ |
| 136 | +val detektVersion = "1.23.0" |
| 137 | + |
| 138 | +/** |
| 139 | + * @see [io.spine.internal.dependency.Kotest] |
| 140 | + */ |
| 141 | +val kotestJvmPluginVersion = "0.3.8" |
| 142 | + |
| 143 | +/** |
| 144 | + * @see [io.spine.internal.dependency.Kover] |
| 145 | + */ |
| 146 | +val koverVersion = "0.6.1" |
| 147 | + |
| 148 | +configurations.all { |
| 149 | + resolutionStrategy { |
| 150 | + force( |
| 151 | + "com.google.guava:guava:${guavaVersion}", |
| 152 | + |
| 153 | + // Force Kotlin lib versions avoiding using those bundled with Gradle. |
| 154 | + "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion", |
| 155 | + "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVersion", |
| 156 | + "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion" |
| 157 | + ) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +val jvmVersion = JavaLanguageVersion.of(11) |
| 162 | + |
| 163 | +java { |
| 164 | + toolchain.languageVersion.set(jvmVersion) |
| 165 | +} |
| 166 | + |
| 167 | +tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { |
| 168 | + kotlinOptions { |
| 169 | + jvmTarget = jvmVersion.toString() |
| 170 | + freeCompilerArgs += "-Xskip-metadata-version-check" |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +dependencies { |
| 175 | + api("com.github.jk1:gradle-license-report:$licenseReportVersion") |
| 176 | + dependOnAuthCommon() |
| 177 | + |
| 178 | + listOf( |
| 179 | + "io.spine.tools:spine-bootstrap:$spineVersion", |
| 180 | + "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion", |
| 181 | + "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jacksonVersion", |
| 182 | + "com.github.jk1:gradle-license-report:$licenseReportVersion", |
| 183 | + "com.google.guava:guava:$guavaVersion", |
| 184 | + "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektVersion", |
| 185 | + "io.kotest:kotest-gradle-plugin:$kotestJvmPluginVersion", |
| 186 | + // https://github.com/srikanth-lingala/zip4j |
| 187 | + "net.lingala.zip4j:zip4j:2.10.0", |
| 188 | + "net.ltgt.gradle:gradle-errorprone-plugin:${errorPronePluginVersion}", |
| 189 | + "org.ajoberstar.grgit:grgit-core:${grGitVersion}", |
| 190 | + "org.jetbrains.dokka:dokka-base:${dokkaVersion}", |
| 191 | + "org.jetbrains.dokka:dokka-gradle-plugin:${dokkaVersion}", |
| 192 | + "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion", |
| 193 | + "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion", |
| 194 | + "org.jetbrains.kotlinx.kover:org.jetbrains.kotlinx.kover.gradle.plugin:$koverVersion", |
| 195 | + "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:$kotlinVersion" |
| 196 | + ).forEach { |
| 197 | + implementation(it) |
| 198 | + } |
| 199 | +} |
| 200 | + |
| 201 | +buildscript { |
| 202 | + repositories { |
| 203 | + mavenCentral() |
| 204 | + gradlePluginPortal() |
| 205 | + } |
| 206 | + |
| 207 | + /** |
| 208 | + * The version of the Shadow Plugin. |
| 209 | + * |
| 210 | + * `6.1.0` is the last version compatible with Gradle 6.9. Newer versions require Gradle v7+. |
| 211 | + * |
| 212 | + * @see <a href="https://github.com/johnrengelman/shadow/releases">Shadow Plugin releases</a> |
| 213 | + */ |
| 214 | + val shadowVersion = "6.1.0" |
| 215 | + |
| 216 | + /** |
| 217 | + * @see [io.spine.internal.dependency.Kover] |
| 218 | + */ |
| 219 | + val koverVersion = "0.6.1" |
| 220 | + |
| 221 | + dependencies { |
| 222 | + classpath("com.github.jengelman.gradle.plugins:shadow:$shadowVersion") |
| 223 | + classpath("org.jetbrains.kotlinx.kover:org.jetbrains.kotlinx.kover.gradle.plugin:$koverVersion") |
| 224 | + } |
| 225 | +} |
| 226 | + |
| 227 | +apply(plugin = "com.github.johnrengelman.shadow") |
| 228 | + |
| 229 | +dependOnBuildSrcJar() |
| 230 | + |
| 231 | +/** |
| 232 | + * Adds a dependency on a `buildSrc.jar`, iff: |
| 233 | + * 1) the `src` folder is missing, and |
| 234 | + * 2) `buildSrc.jar` is present in `buildSrc/` folder instead. |
| 235 | + * |
| 236 | + * This approach is used in the scope of integration testing. |
| 237 | + */ |
| 238 | +fun Project.dependOnBuildSrcJar() { |
| 239 | + val srcFolder = this.rootDir.resolve("src") |
| 240 | + val buildSrcJar = rootDir.resolve("buildSrc.jar") |
| 241 | + if (!srcFolder.exists() && buildSrcJar.exists()) { |
| 242 | + logger.info("Adding the pre-compiled 'buildSrc.jar' to 'implementation' dependencies.") |
| 243 | + dependencies { |
| 244 | + implementation(files("buildSrc.jar")) |
| 245 | + } |
| 246 | + } |
| 247 | +} |
| 248 | + |
| 249 | +/** |
| 250 | + * Includes the `implementation` dependency on `artifactregistry-auth-common`, |
| 251 | + * with the version defined in [googleAuthToolVersion]. |
| 252 | + * |
| 253 | + * `artifactregistry-auth-common` has transitive dependency on Gson and Apache `commons-codec`. |
| 254 | + * Gson from version `2.8.6` until `2.8.9` is vulnerable to Deserialization of Untrusted Data |
| 255 | + * (https://devhub.checkmarx.com/cve-details/CVE-2022-25647/). |
| 256 | + * |
| 257 | + * Apache `commons-codec` before 1.13 is vulnerable to information exposure |
| 258 | + * (https://devhub.checkmarx.com/cve-details/Cxeb68d52e-5509/). |
| 259 | + * |
| 260 | + * We use Gson `2.10.1` and we force it in `forceProductionDependencies()`. |
| 261 | + * We use `commons-code` with version `1.16.0`, forcing it in `forceProductionDependencies()`. |
| 262 | + * |
| 263 | + * So, we should be safe with the current version `artifactregistry-auth-common` until |
| 264 | + * we migrate to a later version. |
| 265 | + */ |
| 266 | +fun DependencyHandlerScope.dependOnAuthCommon() { |
| 267 | + @Suppress("VulnerableLibrariesLocal", "RedundantSuppression") |
| 268 | + implementation( |
| 269 | + "com.google.cloud.artifactregistry:artifactregistry-auth-common:$googleAuthToolVersion" |
| 270 | + ) { |
| 271 | + exclude(group = "com.google.guava") |
| 272 | + } |
| 273 | +} |
0 commit comments