Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.plugins.jvm.JvmTestSuite
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.compile.GroovyCompile
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.base.TestingExtension

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

// Make compiled Kotlin classes visible to Groovy/Spock tests.
fun wireKotlinOutputToGroovy(sourceSet: SourceSet) {
val compileKotlin = tasks.named(sourceSet.getCompileTaskName("kotlin"))
tasks.named<GroovyCompile>(sourceSet.getCompileTaskName("groovy")) {
// Task-backed outputs avoid a Kotlin Gradle plugin API dependency and retain task ordering.
classpath += files(compileKotlin)
}
}

pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
val sourceSets = extensions.getByType<SourceSetContainer>()

// Having Groovy, Kotlin and Java in the same project is a bit problematic.
// Remove Kotlin from main to avoid compilation issues.
sourceSets.named(SourceSet.MAIN_SOURCE_SET_NAME) {
val kotlin = extensions.getByName("kotlin") as SourceDirectorySet
kotlin.setSrcDirs(emptyList<Any>())
java.setSrcDirs(listOf("src/main/java"))
}

// Create Kotlin output directories to make JavaCompile tasks work.
val createKotlinDirs = tasks.register("createKotlinDirs") {
val dirsToCreate = listOf(layout.buildDirectory.dir("classes/kotlin/main"))
doFirst {
dirsToCreate.forEach { it.get().asFile.mkdirs() }
}
outputs.dirs(dirsToCreate)
}

tasks.withType<JavaCompile>().configureEach {
inputs.files(createKotlinDirs)
}

// Prevent Kotlin libraries from being included in the tracer JAR.
dependencies.add("compileOnly", libs.findLibrary("kotlin").get())

pluginManager.withPlugin("groovy") {
pluginManager.withPlugin("jvm-test-suite") {
extensions.getByType<TestingExtension>().suites.withType<JvmTestSuite>().configureEach {
wireKotlinOutputToGroovy(sources)
}
}

pluginManager.withPlugin("java-test-fixtures") {
sourceSets.named("testFixtures") {
wireKotlinOutputToGroovy(this)
}
}
}
}
3 changes: 1 addition & 2 deletions dd-java-agent/agent-ci-visibility/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ plugins {
id 'dd-trace-java.version-file'
id 'dd-trace-java.module.product-subsystem'
id 'dd-trace-java.conventions.testing.scala'
id 'dd-trace-java.conventions.testing.kotlin'
}

apply from: "$rootDir/gradle/test-with-kotlin.gradle"

minimumBranchCoverage = 0.0
minimumInstructionCoverage = 0.0

Expand Down
9 changes: 3 additions & 6 deletions dd-java-agent/benchmark-integration/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
apply from: "$rootDir/gradle/java.gradle"
plugins {
id 'dd-trace-java.conventions.java'
}

description = 'Integration Level Agent benchmarks.'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

subprojects { sub ->
sub.apply plugin: 'com.gradleup.shadow'
sub.apply from: "$rootDir/gradle/java.gradle"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id 'com.gradleup.shadow'
id 'dd-trace-java.conventions.java'
}

dependencies {
implementation project(':dd-trace-api')
implementation project(':dd-java-agent:benchmark-integration')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
plugins {
id 'com.gradleup.shadow'
id 'dd-trace-java.conventions.java'
id 'org.gradle.playframework'
}

Expand Down
4 changes: 1 addition & 3 deletions dd-java-agent/benchmark/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
plugins {
id 'dd-trace-java.jmh-conventions'
id 'dd-trace-java.conventions.java'
}

apply from: "$rootDir/gradle/java.gradle"

dependencies {
jmh project(':dd-trace-api')
jmh libs.bytebuddyagent
Expand Down Expand Up @@ -48,4 +47,3 @@ tasks.named('jmh') {
(using https://github.com/brendangregg/FlameGraph)
./flamegraph.pl --color=java dd-java-agent/benchmark/build/reports/jmh/profiler-cleaned.txt > dd-java-agent/benchmark/build/reports/jmh/jmh-master.svg
*/

2 changes: 1 addition & 1 deletion dd-java-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import java.util.jar.JarFile

plugins {
id 'com.gradleup.shadow'
id 'dd-trace-java.conventions.java'

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.

note: The java convention for this module might be too large, but this follows what's existing today.

In the future, a proper convention should be created dd-trace-java.module.distributable.agent for agent jar, this might help to have multiple kind of agent jar distribution (modularization).

The following aspects appears to be needed

  • java-base
  • java-compilation (to support Java 6 (Pre Java 8) graceful degradation)
  • archives / Shadow behavior
  • javadoc
  • code-quality
  • testing
  • publishing and dependency locking

Some other "features" may not be needed.

}

description = 'dd-java-agent'

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/publish.gradle"

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ plugins {
id 'org.jetbrains.kotlin.jvm'
id 'dd-trace-java.instrumentation.testing-framework-tests'
id 'dd-trace-java.module.instrumentation'
id 'dd-trace-java.conventions.testing.kotlin'
}

apply from: "$rootDir/gradle/test-with-kotlin.gradle"

muzzle {
pass {
group = 'junit'
Expand All @@ -28,10 +27,6 @@ kotlin {

addTestSuiteForDir('latestDepTest', 'test')

tasks.named("compileLatestDepTestGroovy", GroovyCompile) {
classpath += files(tasks.named('compileLatestDepTestKotlin').map { it.destinationDirectory })
}

dependencies {
compileOnly group: 'junit', name: 'junit', version: '4.10'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'java-test-fixtures'
id 'org.jetbrains.kotlin.jvm'
id 'dd-trace-java.module.instrumentation'
id 'dd-trace-java.conventions.testing.kotlin'
}

muzzle {
Expand All @@ -26,8 +27,6 @@ muzzle {
}
}

apply from: "$rootDir/gradle/test-with-kotlin.gradle"

kotlin {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
Expand All @@ -38,18 +37,6 @@ kotlin {

addTestSuite('latestDepTest')

tasks.named("compileTestFixturesGroovy", GroovyCompile) {
classpath += files(tasks.named('compileTestFixturesKotlin').map { it.destinationDirectory })
}

tasks.named("compileTestGroovy", GroovyCompile) {
classpath += files(tasks.named('compileTestKotlin').map { it.destinationDirectory })
}

tasks.named("compileLatestDepTestGroovy", GroovyCompile) {
classpath += files(tasks.named('compileLatestDepTestKotlin').map { it.destinationDirectory })
}

dependencies {
api project(':dd-java-agent:instrumentation:java:java-concurrent:java-concurrent-1.8')
compileOnly libs.kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'dd-trace-java.module.instrumentation'
id 'dd-trace-java.conventions.testing.kotlin'
}

muzzle {
Expand All @@ -18,19 +19,15 @@ muzzle {
}
}

apply from: "$rootDir/gradle/test-with-kotlin.gradle"

testJvmConstraints {
minJavaVersion = JavaVersion.VERSION_17
}

addTestSuiteForDir('latestDepTest', 'test')

["compileTestGroovy", "compileLatestDepTestGroovy"].each { name ->
def kotlinTaskName = name.replace("Groovy", "Kotlin")
tasks.named(name, GroovyCompile) {
configureCompiler(it, 17)
classpath += files(tasks.named(kotlinTaskName).map { it.destinationDirectory })
}
}

Expand Down
4 changes: 3 additions & 1 deletion dd-java-agent/load-generator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply from: "$rootDir/gradle/java.gradle"
plugins {
id 'dd-trace-java.conventions.java'
}

dependencies {
implementation project(':dd-trace-api')
Expand Down
22 changes: 9 additions & 13 deletions gradle/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@ boolean groovySkipJavaExclude = project.hasProperty('groovySkipJavaExclude') ? g

def buildDirectoryFiles = project.layout.buildDirectory.asFileTree

// Temporary exclusions as conventions are properly setup for these projects.
def javaGradleApplyExceptions = [
':dd-java-agent',
':dd-java-agent:benchmark',
':dd-java-agent:benchmark-integration',
':dd-java-agent:load-generator',
] as Set
boolean forbidJavaGradleApply = project.rootProject.name == 'dd-trace-java' && !javaGradleApplyExceptions.contains(project.path)
def scriptApplyExceptions = [
'gradle/publish.gradle': [':dd-java-agent'] as Set,
]
boolean forbidLegacyScriptApplies = project.rootProject.name == 'dd-trace-java'
def javaGradleApplyLinePattern = ~/^\s*(?:\w+\.)?apply(?:\s+from\s*:|\s*\(\s*from\s*=).*/
// Script plugins that must be applied through a 'dd-trace-java.module.*' convention plugin instead.
def forbiddenScriptApplies = [
'gradle/java.gradle' : 'Apply a \'dd-trace-java.module.*\' convention plugin instead of applying the script plugin \'gradle/java.gradle\' directly.',
'gradle/publish.gradle': 'Apply the \'dd-trace-java.module.distributable.*\' convention plugin instead of applying the script plugin \'gradle/publish.gradle\' directly.',
]
def forbidJavaGradleApplyStep = { String text ->
if (forbidJavaGradleApply) {
def forbidLegacyScriptApplyStep = { String text ->
if (forbidLegacyScriptApplies) {
text.readLines().each { line ->
if (javaGradleApplyLinePattern.matcher(line).matches()) {
forbiddenScriptApplies.each { script, message ->
if (line.contains(script)) {
if (line.contains(script) && !scriptApplyExceptions.getOrDefault(script, []).contains(project.path)) {
throw new AssertionError(message)
}
}
Expand Down Expand Up @@ -70,7 +66,7 @@ spotless {
target '*.gradle'
}
greclipse(libs.versions.greclipse.get()).configFile(configPath + '/enforcement/spotless-groovy.properties')
custom 'forbidGradleJavaScriptPlugin', forbidJavaGradleApplyStep
custom 'forbidGradleJavaScriptPlugin', forbidLegacyScriptApplyStep
}

kotlinGradle {
Expand All @@ -82,7 +78,7 @@ spotless {
'ktlint_standard_trailing-comma-on-call-site': 'disabled',
'ktlint_standard_trailing-comma-on-declaration-site': 'disabled'
])
custom 'forbidGradleJavaScriptPlugin', forbidJavaGradleApplyStep
custom 'forbidGradleJavaScriptPlugin', forbidLegacyScriptApplyStep
}

project.pluginManager.withPlugin('groovy') {
Expand Down
47 changes: 0 additions & 47 deletions gradle/test-with-kotlin.gradle

This file was deleted.