Skip to content

Commit 2c5960b

Browse files
authored
Convert settings and main build to kotlin (#9216)
1 parent 01063fa commit 2c5960b

File tree

4 files changed

+744
-697
lines changed

4 files changed

+744
-697
lines changed

build.gradle

Lines changed: 0 additions & 132 deletions
This file was deleted.

build.gradle.kts

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

0 commit comments

Comments
 (0)