Skip to content

Commit b9fde86

Browse files
authored
Add JApiCmd plugin to ease up spotting api differences for muzzle (#10233)
* Add jcmp plugin to ease up spotting api differences for muzzle * spotless
1 parent 39b2cbd commit b9fde86

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

build.gradle.kts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
id("dd-trace-java.ci-jobs")
1313

1414
id("com.diffplug.spotless") version "8.1.0"
15+
id("me.champeau.gradle.japicmp") version "0.4.3"
1516
id("com.github.spotbugs") version "6.4.7"
1617
id("de.thetaphi.forbiddenapis") version "3.10"
1718
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
@@ -156,3 +157,29 @@ testAggregate(
156157
":dd-java-agent:agent-debugger"
157158
)
158159
)
160+
161+
// JApiCmp configuration example
162+
// Usage: ./gradlew japicmp -Partifact=groupId:artifactId -Pbaseline=1.0.0 -Ptarget=2.0.0
163+
tasks.register<me.champeau.gradle.japicmp.JapicmpTask>("japicmp") {
164+
val artifact = providers.gradleProperty("artifact").orNull
165+
val baseline = providers.gradleProperty("baseline").orNull
166+
val target = providers.gradleProperty("target").orNull
167+
168+
if (artifact != null && baseline != null && target != null) {
169+
oldClasspath.from(
170+
configurations.detachedConfiguration(
171+
dependencies.create("$artifact:$baseline")
172+
)
173+
)
174+
newClasspath.from(
175+
configurations.detachedConfiguration(
176+
dependencies.create("$artifact:$target")
177+
)
178+
)
179+
onlyModified.set(true)
180+
failOnModification.set(false)
181+
ignoreMissingClasses.set(true)
182+
txtOutputFile.set(layout.buildDirectory.file("reports/japicmp.txt"))
183+
htmlOutputFile.set(layout.buildDirectory.file("reports/japicmp.html"))
184+
}
185+
}

docs/how_instrumentations_work.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,44 @@ To run muzzle on your instrumentation, run:
9191

9292
> [!WARNING]
9393
> Muzzle does _not_ run tests.
94-
> It checks that the types and methods used by the instrumentation are present in particular versions of libraries.
95-
> It can be subverted with `MethodHandle` and reflection -- in other words, having the `muzzle` task passing is not enough
94+
> It checks that the types and methods used by the instrumentation are present in particular versions of libraries.
95+
> It can be subverted with `MethodHandle` and reflection -- in other words, having the `muzzle` task passing is not enough
9696
> to validate an instrumentation.
9797
9898
By default, all the muzzle directives are checked against all the instrumentations included in a module.
99-
However, there can be situations in which its only needed to check one specific directive on an instrumentation.
99+
However, there can be situations in which it's only needed to check one specific directive on an instrumentation.
100100
At this point the instrumentation should override the method `muzzleDirective()` by returning the name of the directive to execute.
101101

102+
### Identifying Breaking Changes with JApiCmp
103+
104+
Before defining muzzle version ranges, you can use the JApiCmp plugin to compare different versions of a library and
105+
identify breaking API changes. This helps determine where to split version ranges in your muzzle directives.
106+
107+
The `japicmp` task compares two versions of a Maven artifact and reports:
108+
- Removed classes and methods (breaking changes)
109+
- Added classes and methods (non-breaking changes)
110+
- Modified methods with binary compatibility status
111+
112+
#### Usage
113+
114+
Compare two versions of any Maven artifact:
115+
116+
```shell
117+
./gradlew japicmp -Partifact=groupId:artifactId -Pbaseline=oldVersion -Ptarget=newVersion
118+
```
119+
120+
For example, to compare MongoDB driver versions:
121+
122+
```shell
123+
./gradlew japicmp -Partifact=org.mongodb:mongodb-driver-sync -Pbaseline=3.11.0 -Ptarget=4.0.0
124+
```
125+
126+
#### Output
127+
128+
The task generates two reports:
129+
130+
- **Text report**: `build/reports/japicmp.txt` - Detailed line-by-line comparison
131+
- **HTML report**: `build/reports/japicmp.html` - Browsable visual report
102132

103133
## Instrumentation classes
104134

0 commit comments

Comments
 (0)