|
| 1 | +import com.diffplug.gradle.spotless.SpotlessExtension |
| 2 | + |
| 3 | +plugins { |
| 4 | + id("datadog.gradle-debug") |
| 5 | + id("datadog.dependency-locking") |
| 6 | + |
| 7 | + id("com.diffplug.spotless") version "6.13.0" |
| 8 | + id("com.github.spotbugs") version "5.0.14" |
| 9 | + id("de.thetaphi.forbiddenapis") version "3.8" |
| 10 | + |
| 11 | + id("org.shipkit.shipkit-auto-version") version "2.1.2" |
| 12 | + id("io.github.gradle-nexus.publish-plugin") version "2.0.0" |
| 13 | + |
| 14 | + id("com.gradleup.shadow") version "8.3.6" apply false |
| 15 | + id("me.champeau.jmh") version "0.7.0" apply false |
| 16 | + id("org.gradle.playframework") version "0.13" apply false |
| 17 | + id("info.solidsoft.pitest") version "1.9.11" apply false |
| 18 | +} |
| 19 | + |
| 20 | +description = "dd-trace-java" |
| 21 | + |
| 22 | + |
| 23 | +val isCI = providers.environmentVariable("CI") |
| 24 | + |
| 25 | +apply(from = rootDir.resolve("gradle/repositories.gradle")) |
| 26 | + |
| 27 | +spotless { |
| 28 | + // only resolve the spotless dependencies once in the build |
| 29 | + predeclareDeps() |
| 30 | +} |
| 31 | + |
| 32 | +with(extensions["spotlessPredeclare"] as SpotlessExtension) { |
| 33 | + // these need to align with the types and versions in gradle/spotless.gradle |
| 34 | + java { |
| 35 | + removeUnusedImports() |
| 36 | + |
| 37 | + // This is the last Google Java Format version that supports Java 8 |
| 38 | + googleJavaFormat("1.7") |
| 39 | + } |
| 40 | + groovyGradle { |
| 41 | + greclipse() |
| 42 | + } |
| 43 | + groovy { |
| 44 | + greclipse() |
| 45 | + } |
| 46 | + kotlinGradle { |
| 47 | + ktlint("0.41.0") |
| 48 | + } |
| 49 | + kotlin { |
| 50 | + ktlint("0.41.0") |
| 51 | + } |
| 52 | + scala { |
| 53 | + scalafmt("2.7.5") |
| 54 | + } |
| 55 | +} |
| 56 | +apply(from = rootDir.resolve("gradle/spotless.gradle")) |
| 57 | + |
| 58 | +val compileTask = tasks.register("compile") |
| 59 | + |
| 60 | +val repoVersion = version |
| 61 | + |
| 62 | +allprojects { |
| 63 | + group = "com.datadoghq" |
| 64 | + version = repoVersion |
| 65 | + |
| 66 | + if (isCI.isPresent) { |
| 67 | + layout.buildDirectory = providers.provider { |
| 68 | + val newProjectCIPath = projectDir.path.replace( |
| 69 | + rootDir.path, |
| 70 | + "" |
| 71 | + ) |
| 72 | + rootDir.resolve("workspace/$newProjectCIPath/build/") |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + apply(from = rootDir.resolve("gradle/dependencies.gradle")) |
| 77 | + apply(from = rootDir.resolve("gradle/util.gradle")) |
| 78 | + |
| 79 | + compileTask.configure { |
| 80 | + dependsOn(tasks.withType<AbstractCompile>()) |
| 81 | + } |
| 82 | + |
| 83 | + tasks.configureEach { |
| 84 | + if (this is JavaForkOptions) { |
| 85 | + maxHeapSize = System.getProperty("datadog.forkedMaxHeapSize") |
| 86 | + minHeapSize = System.getProperty("datadog.forkedMinHeapSize") |
| 87 | + jvmArgs( |
| 88 | + "-XX:ErrorFile=/tmp/hs_err_pid%p.log", |
| 89 | + "-XX:+HeapDumpOnOutOfMemoryError", |
| 90 | + "-XX:HeapDumpPath=/tmp" |
| 91 | + ) |
| 92 | + } |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +tasks.register("latestDepTest") |
| 97 | + |
| 98 | +nexusPublishing { |
| 99 | + repositories { |
| 100 | + val forceLocal = providers.gradleProperty("forceLocal").getOrElse("false").toBoolean() |
| 101 | + if (forceLocal && !isCI.isPresent) { |
| 102 | + // For testing, use with https://hub.docker.com/r/sonatype/nexus |
| 103 | + // $ docker run --rm -d -p 8081:8081 --name nexus sonatype/nexus:oss |
| 104 | + // $ ./gradlew publishToLocal -PforceLocal=true |
| 105 | + // Doesn't work for testing releases though... (due to staging), |
| 106 | + // however, it's possible to explore http://localhost:8081/nexus/ |
| 107 | + register("local") { |
| 108 | + nexusUrl = uri("http://localhost:8081/nexus/content/repositories/releases/") |
| 109 | + snapshotRepositoryUrl = uri("http://localhost:8081/nexus/content/repositories/snapshots/") |
| 110 | + username = "admin" |
| 111 | + password = "admin123" |
| 112 | + allowInsecureProtocol = true |
| 113 | + } |
| 114 | + } else { |
| 115 | + // see https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-central |
| 116 | + // For official documentation: |
| 117 | + // staging repo publishing https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#configuration |
| 118 | + // snapshot publishing https://central.sonatype.org/publish/publish-portal-snapshots/#publishing-via-other-methods |
| 119 | + sonatype { |
| 120 | + nexusUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/") |
| 121 | + snapshotRepositoryUrl = uri("https://central.sonatype.com/repository/maven-snapshots/") |
| 122 | + username = providers.environmentVariable("MAVEN_CENTRAL_USERNAME") |
| 123 | + password = providers.environmentVariable("MAVEN_CENTRAL_PASSWORD") |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +val writeMainVersionFileTask = tasks.register("writeMainVersionFile") { |
| 130 | + val versionFile = rootProject.layout.buildDirectory.file("main.version") |
| 131 | + inputs.property("version", project.version) |
| 132 | + outputs.file(versionFile) |
| 133 | + doFirst { |
| 134 | + require(versionFile.get().asFile.parentFile.mkdirs() || versionFile.get().asFile.parentFile.isDirectory) |
| 135 | + versionFile.get().asFile.writeText(project.version.toString()) |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | +allprojects { |
| 140 | + tasks.withType<PublishToMavenLocal>().configureEach { |
| 141 | + finalizedBy(writeMainVersionFileTask) |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +apply(from = "$rootDir/gradle/ci_jobs.gradle") |
0 commit comments