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) {
Comment thread
bric3 marked this conversation as resolved.
// 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"
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: This actually removes spotless from the buildSrc project

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.

I moved it inside spotless convention plugin, see
To process whole dd-trace-java with single ./gradlew spotlessApply command.
Also folders like test-published-dependencies will be processed too.

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.

Imho this looks incorrect to modify these project from the main dd-trace-java.

}

// 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package datadog.gradle.plugin.spotless

import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class SpotlessConventionsPlugin : Plugin<Project> {
private companion object {
const val GOOGLE_JAVA_FORMAT_VERSION = "1.35.0"
const val TABLE_TEST_FORMATTER_VERSION = "1.1.1"
const val KTLINT_VERSION = "1.8.0"
const val SCALAFMT_VERSION = "3.11.1"

val KTLINT_EDITOR_CONFIG_OVERRIDE =
mapOf(
"ktlint_standard_trailing-comma-on-call-site" to "disabled",
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled"
)

val EXCLUDED_PROJECTS = setOf(":dd-java-agent:agent-jmxfetch")
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.

issue: This looks wrong. Spotless was applied to this module before.

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.

Hmm, as far as I understand it is external project that injected into dd-trace-java and it should have its own spotless or other way to clean code.

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.

:dd-java-agent:agent-jmxfetch is from us, but dd-java-agent/agent-jmxfetch/integrations-core is a git submodule.

}

override fun apply(project: Project) {
if (project.path in EXCLUDED_PROJECTS) {
return
}

project.pluginManager.apply("com.diffplug.spotless")

if (project == project.rootProject) {
configurePredeclaredDependencies(project)
configureRootFormatting(project)
} else {
configureProjectFormatting(project)
}
}

private fun configurePredeclaredDependencies(project: Project) {
project.extensions.configure<SpotlessExtensionPredeclare> {
java {
tableTestFormatter(TABLE_TEST_FORMATTER_VERSION)
googleJavaFormat(GOOGLE_JAVA_FORMAT_VERSION)
}

groovyGradle {
greclipse()
}

groovy {
greclipse()
}

kotlinGradle {
ktlint(KTLINT_VERSION)
}

kotlin {
ktlint(KTLINT_VERSION)
}

scala {
scalafmt(SCALAFMT_VERSION)
}
}
}

private fun configureRootFormatting(project: Project) {
project.extensions.configure<SpotlessExtension> {
configureSkipSpotless(project, this)

val rootExcludes = listOf(
"build/**",
"buildSrc/build/**",
"buildSrc/**/build/**",
"test-published-dependencies/**/build/**"
)

kotlinGradle {
toggleOffOn()
target(
"*.gradle.kts",
"buildSrc/**/*.gradle.kts",
"gradle/**/*.gradle.kts",
"test-published-dependencies/**/*.gradle.kts"
)
targetExclude(rootExcludes)
ktlint(KTLINT_VERSION)
.editorConfigOverride(KTLINT_EDITOR_CONFIG_OVERRIDE)
}

groovyGradle {
toggleOffOn()
target(
"*.gradle",
"buildSrc/**/*.gradle",
"gradle/**/*.gradle",
"test-published-dependencies/**/*.gradle"
)
targetExclude(rootExcludes)
greclipse().configFile("${project.rootDir}/gradle/enforcement/spotless-groovy.properties")
}

kotlin {
toggleOffOn()
target("buildSrc/**/*.kt")
targetExclude(rootExcludes)
ktlint(KTLINT_VERSION)
.editorConfigOverride(KTLINT_EDITOR_CONFIG_OVERRIDE)
}

java {
toggleOffOn()
target("buildSrc/**/*.java", "test-published-dependencies/**/src/**/*.java")
targetExclude(rootExcludes)
tableTestFormatter(TABLE_TEST_FORMATTER_VERSION)
googleJavaFormat(GOOGLE_JAVA_FORMAT_VERSION)
}

format("markdown") {
toggleOffOn()
target("*.md", ".github/**/*.md", "src/**/*.md", "app*/**/*.md")
leadingTabsToSpaces()
endWithNewline()
}

format("misc") {
toggleOffOn()
target(".gitignore", "*.sh", "tooling/*.sh", ".gitlab/*.sh")
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
}

private fun configureProjectFormatting(project: Project) {
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.

issue: It seems that project-local markdown and misc formats were not carried over.

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.

Not sure what is wrong, but I can see in my branch the following changes
I actually think we need to add folders like .claude, docs to process md files.
Let me know WDYT?

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.

It's just that I don;t sse markdown and misc being configured, so that seems a bit strange, compared to previous spotless.gradle.

format 'markdown', {
toggleOffOn()
target '*.md', '.github/**/*.md', 'src/**/*.md', 'application/**/*.md'
leadingTabsToSpaces()
endWithNewline()
}
format 'misc', {
toggleOffOn()
target '.gitignore', '*.sh', 'tooling/*.sh', '.gitlab/*.sh'
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}

project.extensions.configure<SpotlessExtension> {
configureSkipSpotless(project, this)

val commonExcludes = listOf("build/**", "src/test/resources/**")

kotlinGradle {
toggleOffOn()
target("*.gradle.kts")
ktlint(KTLINT_VERSION)
.editorConfigOverride(KTLINT_EDITOR_CONFIG_OVERRIDE)
}

groovyGradle {
toggleOffOn()
target("*.gradle")
greclipse().configFile("${project.rootDir}/gradle/enforcement/spotless-groovy.properties")
}

project.pluginManager.withPlugin("java") {
java {
toggleOffOn()
target("src/**/*.java", "app*/**/*.java")
targetExclude(commonExcludes)
tableTestFormatter(TABLE_TEST_FORMATTER_VERSION)
googleJavaFormat(GOOGLE_JAVA_FORMAT_VERSION)
}
}

project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
kotlin {
toggleOffOn()
target("src/**/*.kt", "app*/**/*.kt")
targetExclude(commonExcludes)
ktlint(KTLINT_VERSION)
.editorConfigOverride(KTLINT_EDITOR_CONFIG_OVERRIDE)
}
}

project.pluginManager.withPlugin("scala") {
scala {
toggleOffOn()
target("src/**/*.scala", "app*/**/*.scala")
targetExclude(commonExcludes)
scalafmt(SCALAFMT_VERSION)
.configFile("${project.rootDir}/gradle/enforcement/spotless-scalafmt.conf")
}
}

project.pluginManager.withPlugin("groovy") {
groovy {
toggleOffOn()
target("src/**/*.groovy", "app*/**/*.groovy")
targetExclude(commonExcludes)
greclipse().configFile("${project.rootDir}/gradle/enforcement/spotless-groovy.properties")
}
}
}
}

private fun configureSkipSpotless(project: Project, spotless: SpotlessExtension) {
if (project.rootProject.hasProperty("skipSpotless")) {
spotless.setEnforceCheck(false)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/**
* Convention plugin for overriding ddprof dependency version with snapshot.
*
* When the root project has the property 'ddprofUseSnapshot' set, this plugin:
* 1. Reads the calculated snapshot version from root project
* 2. Overrides all ddprof dependencies to use the snapshot version
*
* Apply this plugin only to projects that depend on ddprof.
*/
//
// Convention plugin for overriding ddprof dependency version with snapshot.
//
// When the root project has the property 'ddprofUseSnapshot' set, this plugin:
// 1. Reads the calculated snapshot version from root project
// 2. Overrides all ddprof dependencies to use the snapshot version
//
// Apply this plugin only to projects that depend on ddprof.

if (rootProject.hasProperty("ddprofUseSnapshot")) {
val ddprofSnapshotVersion = rootProject.property("ddprofSnapshotVersion").toString()
Expand Down
5 changes: 0 additions & 5 deletions dd-java-agent/agent-iast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ ext {
tasks.withType(Test).configureEach {
jvmArgs += ['-Ddd.iast.enabled=true']
}
spotless {
java {
target 'src/**/*.java'
}
}

jmh {
jmhVersion = libs.versions.jmh.get()
Expand Down
Loading