|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. |
| 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 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask |
| 17 | +import com.github.jk1.license.LicenseReportExtension |
| 18 | + |
| 19 | +plugins { |
| 20 | + `java-platform` |
| 21 | + |
| 22 | + id("com.github.ben-manes.versions") |
| 23 | +} |
| 24 | + |
| 25 | +data class DependencySet(val group: String, val version: String, val modules: List<String>) |
| 26 | + |
| 27 | +val testSnapshots = rootProject.findProperty("testUpstreamSnapshots") == "true" |
| 28 | + |
| 29 | +// This is the version of the upstream instrumentation BOM |
| 30 | +val otelVersion = "2.10.0-adot2" |
| 31 | +val otelSnapshotVersion = "2.11.0" |
| 32 | +val otelAlphaVersion = if (!testSnapshots) "$otelVersion-alpha" else "$otelSnapshotVersion-alpha-SNAPSHOT" |
| 33 | +val otelJavaAgentVersion = if (!testSnapshots) otelVersion else "$otelSnapshotVersion-SNAPSHOT" |
| 34 | +// All versions below are only used in testing and do not affect the released artifact. |
| 35 | + |
| 36 | +val dependencyBoms = listOf( |
| 37 | + "com.amazonaws:aws-java-sdk-bom:1.12.599", |
| 38 | + "com.fasterxml.jackson:jackson-bom:2.16.0", |
| 39 | + "com.google.guava:guava-bom:33.0.0-jre", |
| 40 | + "com.google.protobuf:protobuf-bom:3.25.1", |
| 41 | + "com.linecorp.armeria:armeria-bom:1.26.4", |
| 42 | + "io.grpc:grpc-bom:1.59.1", |
| 43 | + "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:$otelAlphaVersion", |
| 44 | + "org.apache.logging.log4j:log4j-bom:2.21.1", |
| 45 | + "org.junit:junit-bom:5.10.1", |
| 46 | + "org.springframework.boot:spring-boot-dependencies:2.7.17", |
| 47 | + "org.testcontainers:testcontainers-bom:1.19.3", |
| 48 | + "software.amazon.awssdk:bom:2.21.33", |
| 49 | +) |
| 50 | + |
| 51 | +val dependencySets = listOf( |
| 52 | + DependencySet( |
| 53 | + "org.assertj", |
| 54 | + "3.24.2", |
| 55 | + listOf("assertj-core"), |
| 56 | + ), |
| 57 | + DependencySet( |
| 58 | + "org.curioswitch.curiostack", |
| 59 | + "2.2.0", |
| 60 | + listOf("protobuf-jackson"), |
| 61 | + ), |
| 62 | + DependencySet( |
| 63 | + "org.slf4j", |
| 64 | + "1.7.36", |
| 65 | + listOf( |
| 66 | + "slf4j-api", |
| 67 | + "slf4j-simple", |
| 68 | + ), |
| 69 | + ), |
| 70 | +) |
| 71 | + |
| 72 | +val dependencyLists = listOf( |
| 73 | + "commons-logging:commons-logging:1.2", |
| 74 | + "com.sparkjava:spark-core:2.9.4", |
| 75 | + "com.squareup.okhttp3:okhttp:4.12.0", |
| 76 | + "io.opentelemetry.contrib:opentelemetry-aws-xray:1.39.0", |
| 77 | + "io.opentelemetry.contrib:opentelemetry-aws-resources:1.39.0-alpha", |
| 78 | + "io.opentelemetry.proto:opentelemetry-proto:1.0.0-alpha", |
| 79 | + "io.opentelemetry.javaagent:opentelemetry-javaagent:$otelJavaAgentVersion", |
| 80 | + "io.opentelemetry:opentelemetry-extension-aws:1.20.1", |
| 81 | + "net.bytebuddy:byte-buddy:1.14.10", |
| 82 | +) |
| 83 | + |
| 84 | +javaPlatform { |
| 85 | + allowDependencies() |
| 86 | +} |
| 87 | + |
| 88 | +dependencies { |
| 89 | + for (bom in dependencyBoms) { |
| 90 | + api(platform(bom)) |
| 91 | + } |
| 92 | + constraints { |
| 93 | + for (set in dependencySets) { |
| 94 | + for (module in set.modules) { |
| 95 | + api("${set.group}:$module:${set.version}") |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + for (dependency in dependencyLists) { |
| 100 | + api(dependency) |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +rootProject.allprojects { |
| 106 | + plugins.withId("com.github.jk1.dependency-license-report") { |
| 107 | + configure<LicenseReportExtension> { |
| 108 | + val bomExcludes = dependencyBoms.stream() |
| 109 | + .map { it.substring(0, it.lastIndexOf(':')) } |
| 110 | + .toArray { length -> arrayOfNulls<String>(length) } |
| 111 | + excludes = bomExcludes |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +fun isNonStable(version: String): Boolean { |
| 117 | + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) } |
| 118 | + val regex = "^[0-9,.v-]+(-r|-alpha)?$".toRegex() |
| 119 | + val isGuava = version.endsWith("-jre") |
| 120 | + val isStable = stableKeyword || regex.matches(version) || isGuava |
| 121 | + return isStable.not() |
| 122 | +} |
| 123 | + |
| 124 | +tasks { |
| 125 | + named<DependencyUpdatesTask>("dependencyUpdates") { |
| 126 | + revision = "release" |
| 127 | + checkConstraints = true |
| 128 | + |
| 129 | + rejectVersionIf { |
| 130 | + isNonStable(candidate.version) |
| 131 | + } |
| 132 | + } |
| 133 | +} |
0 commit comments