Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,9 @@ spotless:
stage: tests
needs: []
variables:
GRADLE_MEMORY_MAX: 6G
# Give spotlessCheck more heap and fewer parallel workers — it OOMs on CI otherwise.
GRADLE_MEMORY_MAX: 8G
GRADLE_WORKERS: 2
script:
- ./gradlew --version
- ./gradlew spotlessCheck $GRADLE_ARGS
Expand Down
35 changes: 1 addition & 34 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import datadog.gradle.plugin.ci.testAggregate

plugins {
Expand All @@ -10,8 +9,8 @@ plugins {
id("dd-trace-java.dump-hanged-test")
id("dd-trace-java.config-inversion-linter")
id("dd-trace-java.ci-jobs")
id("dd-trace-java.spotless-conventions")

id("com.diffplug.spotless") version "8.4.0"
id("me.champeau.gradle.japicmp") version "0.4.3"
id("com.github.spotbugs") version "6.5.0"
id("de.thetaphi.forbiddenapis") version "3.10"
Expand All @@ -28,38 +27,6 @@ val isCI = providers.environmentVariable("CI")
apply(from = rootDir.resolve("gradle/repositories.gradle"))
apply(from = rootDir.resolve("gradle/ddprof-override.gradle"))

spotless {
// only resolve the spotless dependencies once in the build
predeclareDeps()
}

with(extensions["spotlessPredeclare"] as SpotlessExtension) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: 8.5.0 allows to use spotlessPredeclare {} directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, but finally I applied a bit different approach.

// these need to align with the types and versions in gradle/spotless.gradle
java {
removeUnusedImports()

googleJavaFormat("1.35.0")
tableTestFormatter("1.1.1")
}
groovyGradle {
greclipse()
}
groovy {
greclipse()
}
kotlinGradle {
ktlint("1.8.0")
}
kotlin {
ktlint("1.8.0")
}
scala {
// TODO: For some reason Scala format is working correctly with this version only.
scalafmt("3.8.6")
}
}
apply(from = rootDir.resolve("gradle/spotless.gradle"))

val compileTask = tasks.register("compile")

allprojects {
Expand Down
37 changes: 33 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
import org.gradle.api.attributes.java.TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
import org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8

plugins {
`java-gradle-plugin`
`kotlin-dsl`
`jvm-test-suite`
id("com.diffplug.spotless") version "8.4.0"
}

// The buildSrc still needs to target Java 8 as build time instrumentation and muzzle plugin
// allow to schedule workers on different JDK version.
// Compile with a modern JDK toolchain (21), but keep the emitted bytecode at Java 8.
// Rationale: the build-time instrumentation and muzzle plugins schedule Gradle workers
// on different JDK versions, including Java 8, so any class loaded from buildSrc must
// remain Java 8 compatible.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

// Same split for Kotlin: compile on JDK 21 but target the Java 8 bytecode level so the
// Kotlin output can be loaded by the same Java-8 workers described above.
kotlin {
jvmToolchain(21)

compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
jvmTarget.set(JVM_1_8)
}
}

// Advertise Java 17 as the target JVM version when *resolving* dependencies. Several
// modern Gradle plugins (notably Spotless 8.x) publish only Java 17+ variants via Gradle
// Module Metadata; without this attribute, resolution fails with "no matching variant"
// because our targetCompatibility above declares Java 8. This affects dependency
// resolution only — it does not change the bytecode level we emit, which stays at Java 8.
configurations.configureEach {
if (isCanBeResolved) {
attributes.attribute(TARGET_JVM_VERSION_ATTRIBUTE, 17)
}
}

Expand Down Expand Up @@ -63,6 +86,11 @@ gradlePlugin {
id = "dd-trace-java.instrumentation-naming"
implementationClass = "datadog.gradle.plugin.naming.InstrumentationNamingPlugin"
}

create("spotless-conventions") {
id = "dd-trace-java.spotless-conventions"
implementationClass = "datadog.gradle.plugin.spotless.SpotlessConventionsPlugin"
}
}
}

Expand All @@ -78,6 +106,7 @@ dependencies {
implementation(gradleApi())

implementation("net.bytebuddy", "byte-buddy-gradle-plugin", "1.18.8")
implementation("com.diffplug.spotless:spotless-plugin-gradle:8.5.0")

implementation("org.eclipse.aether", "aether-connector-basic", "1.1.0")
implementation("org.eclipse.aether", "aether-transport-http", "1.1.0")
Expand Down
12 changes: 0 additions & 12 deletions buildSrc/call-site-instrumentation-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
java
id("com.diffplug.spotless") version "8.4.0"
id("com.gradleup.shadow") version "8.3.9"
}

Expand All @@ -9,17 +8,6 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}

spotless {
java {
toggleOffOn()
// set explicit target to workaround https://github.com/diffplug/spotless/issues/1163
target("src/**/*.java")
// ignore embedded test projects
targetExclude("src/test/resources/**")
googleJavaFormat("1.35.0")
}
}

apply {
from("$rootDir/../gradle/repositories.gradle")
}
Expand Down
Loading