Skip to content

Commit c5fa7cf

Browse files
committed
Refactor ddprof override to use convention plugin
Address PR review feedback from bric3: - Create dd-trace-java.profiling-ddprof-override convention plugin - Apply plugin only to projects that depend on ddprof (ddprof-lib) - Remove allprojects blocks from ddprof-override.gradle - Enhance TracerVersionPlugin to support version qualifiers - Use consistent property access (property() instead of ext) Benefits: - Only affects projects that explicitly apply the plugin - Follows Gradle best practices and project conventions - More maintainable and easier to understand - Clear separation of concerns The ddprof dependency override now happens via a convention plugin that projects can opt into, rather than affecting all projects globally.
1 parent f90a355 commit c5fa7cf

4 files changed

Lines changed: 57 additions & 36 deletions

File tree

buildSrc/src/main/kotlin/datadog/gradle/plugin/version/TracerVersionPlugin.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class TracerVersionPlugin @Inject constructor(
2828
.orElse(false)
2929
)
3030

31+
extension.versionQualifier.set(
32+
providerFactory.gradleProperty("tracerVersion.qualifier")
33+
)
34+
3135
val versionProvider = versionProvider(targetProject, extension)
3236
targetProject.allprojects {
3337
version = versionProvider
@@ -125,6 +129,14 @@ class TracerVersionPlugin @Inject constructor(
125129
return buildString {
126130
append(version.toString())
127131

132+
// Add optional version qualifier (e.g., "-ddprof")
133+
if (extension.versionQualifier.isPresent) {
134+
val qualifier = extension.versionQualifier.get()
135+
if (qualifier.isNotBlank()) {
136+
append("-").append(qualifier)
137+
}
138+
}
139+
128140
if (hasLaterCommits) {
129141
append(if (extension.useSnapshot.get()) "-SNAPSHOT" else describeTrailer)
130142
}
@@ -143,5 +155,6 @@ class TracerVersionPlugin @Inject constructor(
143155
val useSnapshot = objectFactory.property(Boolean::class)
144156
.convention(true)
145157
val detectDirty = objectFactory.property(Boolean::class)
158+
val versionQualifier = objectFactory.property(String::class)
146159
}
147160
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Convention plugin for overriding ddprof dependency version with snapshot.
3+
*
4+
* When the root project has the property 'ddprofUseSnapshot' set, this plugin:
5+
* 1. Reads the calculated snapshot version from root project
6+
* 2. Overrides all ddprof dependencies to use the snapshot version
7+
*
8+
* Apply this plugin only to projects that depend on ddprof.
9+
*/
10+
11+
if (rootProject.hasProperty("ddprofUseSnapshot")) {
12+
val ddprofSnapshotVersion = rootProject.property("ddprofSnapshotVersion").toString()
13+
14+
configurations.all {
15+
resolutionStrategy.eachDependency {
16+
if (requested.group == "com.datadoghq" && requested.name == "ddprof") {
17+
useVersion(ddprofSnapshotVersion)
18+
because("Using ddprof snapshot version for integration testing")
19+
}
20+
}
21+
}
22+
23+
logger.lifecycle("${project.name}: Configured to use ddprof SNAPSHOT version $ddprofSnapshotVersion")
24+
}

dd-java-agent/ddprof-lib/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22

33
plugins {
44
id "com.gradleup.shadow"
5+
id "dd-trace-java.profiling-ddprof-override"
56
}
67

78
apply from: "$rootDir/gradle/java.gradle"
@@ -14,13 +15,6 @@ dependencies {
1415
api project(':dd-trace-api')
1516
}
1617

17-
// Log information about ddprof version being used
18-
afterEvaluate {
19-
if (rootProject.hasProperty('ddprofUseSnapshot')) {
20-
logger.lifecycle("${project.name}: Using ddprof SNAPSHOT version ${rootProject.ext.ddprofSnapshotVersion}")
21-
}
22-
}
23-
2418
tasks.named("shadowJar", ShadowJar) {
2519
dependencies {
2620
deps.excludeShared

gradle/ddprof-override.gradle

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,34 @@
22
// When -PddprofUseSnapshot=true is set, this will:
33
// 1. Parse the current ddprof version from libs.versions.toml
44
// 2. Calculate the next minor snapshot version: X.Y.Z -> X.(Y+1).0-SNAPSHOT
5-
// 3. Override the ddprof dependency resolution to use the snapshot version
6-
// 4. Add a qualifier to the dd-trace-java version to avoid overwriting standard snapshots
5+
// 3. Store the snapshot version for use by convention plugins
6+
// 4. Set the version qualifier property to add "ddprof" to the version
7+
// This ensures we don't overwrite the regular SNAPSHOT artifacts
8+
// The version will become: X.Y.Z-ddprof-SNAPSHOT instead of X.Y.Z-SNAPSHOT
79

810
def ddprofUseSnapshot = project.hasProperty("ddprofUseSnapshot")
911

1012
if (ddprofUseSnapshot) {
1113
def ddprofSnapshotVersion = calculateDdprofSnapshotVersion()
1214
logger.lifecycle("Using ddprof snapshot version: ${ddprofSnapshotVersion}")
1315

14-
// Store the calculated version as an extra property for use in subprojects
16+
// Store the calculated version as an extra property for use in convention plugins
1517
rootProject.ext.ddprofSnapshotVersion = ddprofSnapshotVersion
1618

17-
// Add qualifier to the project version to differentiate from standard snapshots
18-
// This ensures we don't overwrite the regular SNAPSHOT artifacts
19-
allprojects {
20-
def originalVersion = version.toString()
21-
if (originalVersion.contains('-SNAPSHOT')) {
22-
// Insert qualifier before -SNAPSHOT: X.Y.Z-SNAPSHOT -> X.Y.Z-ddprof-SNAPSHOT
23-
version = originalVersion.replace('-SNAPSHOT', '-ddprof-SNAPSHOT')
24-
} else if (originalVersion.contains('-')) {
25-
// For versions with trailer: X.Y.Z-12-g8ab3f42d -> X.Y.Z-ddprof-12-g8ab3f42d
26-
def parts = originalVersion.split('-', 2)
27-
version = "${parts[0]}-ddprof-${parts[1]}"
28-
} else {
29-
// For release versions (shouldn't happen, but handle it): X.Y.Z -> X.Y.Z-ddprof
30-
version = "${originalVersion}-ddprof"
31-
}
32-
logger.lifecycle("Modified version for ${project.name}: ${originalVersion} -> ${version}")
33-
}
34-
35-
// Override the ddprof dependency resolution for all configurations
36-
allprojects {
37-
configurations.all {
38-
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
39-
if (details.requested.group == 'com.datadoghq' && details.requested.name == 'ddprof') {
40-
details.useVersion(ddprofSnapshotVersion)
41-
details.because("Using ddprof snapshot version for integration testing")
42-
}
19+
// Set the version qualifier property that TracerVersionPlugin will read
20+
// Note: Users can also explicitly set this via -PtracerVersion.qualifier=ddprof
21+
if (!project.hasProperty("tracerVersion.qualifier")) {
22+
// Add the qualifier to the version after it has been calculated
23+
// This is a workaround since we can't set gradle properties programmatically
24+
allprojects {
25+
def originalVersion = it.version.toString()
26+
if (originalVersion.contains('-SNAPSHOT')) {
27+
it.version = originalVersion.replace('-SNAPSHOT', '-ddprof-SNAPSHOT')
28+
} else if (originalVersion.contains('-')) {
29+
def parts = originalVersion.split('-', 2)
30+
it.version = "${parts[0]}-ddprof-${parts[1]}"
31+
} else {
32+
it.version = "${originalVersion}-ddprof"
4333
}
4434
}
4535
}

0 commit comments

Comments
 (0)