Commit 2068d0d
authored
Prevent duplicate class inclusion in runtime artifacts (#11853)
fix(build): Stop publishing extra source-set output twice
The `TracerJavaExtension.addSourceSetFor` added the extra source-set
output to the `implementation` configuration.
A project dependency on the runtime classpath resolves the producer's
`runtimeElements` variant. That variant publishes the project jar and
runtime dependencies derived from `implementation`, so consumers
(the instrumentation project in particular) received the same classes
twice:
1. once from the jar configured with
`jar.from(mainForJavaVersionSourceSet.output)`,
2. once from the raw class directory published as a dependency
This change keeps the additional source set local to the producer
module's _compile_ and _test_ classpaths respectively with
`compileOnly` and `testImplementation`.
The jar remains the runtime artifact consumed by downstream aggregating
projects, and it still contains the additional source-set classes.
What was considered: dropping the `jar.from(output)` config, it would
remove the duplicate, but it would make the consumed module jar
incomplete and leave consuming projects relying on class directories
instead of the artifact. This would also a the side effect of making
Gradle to track individual classes for up-to-date tracking, which
consumes more memory.
This keeps the existing "jar contract" and only prevent publishing
the additional source-set output through `runtimeElements`.
This removes the exception-profiling and instrumentation duplicate
exclusions that were needed in the instrumentation `shadowJar`.
fix(build): Stop publishing agent-installer source-set output twice
The `agent-installer` project added its Java-version-specific source-set
outputs to the `runtimeOnly` configuration.
A project dependency on the runtime classpath resolves the producer's
`runtimeElements` variant. That variant publishes the project jar and
runtime dependencies derived from `runtimeOnly`, so consumers
(the instrumentation project in particular) received the same classes
twice:
1. once from the jar configured with
`from sourceSets.main_java11.output` and
`from sourceSets.main_java25.output`,
2. once from the raw class directories published as runtime dependencies
This change keeps the Java-version-specific source sets local to the
producer module's test classpath with `testImplementation`.
The jar remains the runtime artifact consumed by downstream aggregating
projects, and it still contains the Java 11 and Java 25 source-set
classes.
Dropping the jar configuration would remove the duplicate, but it would
make the consumed `agent-installer` jar incomplete and leave consuming
projects relying on class directories instead of the artifact.
This keeps the existing "jar contract" and only prevents publishing
the Java-version-specific source-set output through `runtimeElements`.
This removes the agent-installer duplicate exclusions that were needed
in the instrumentation `shadowJar`.
fix(build): Keep servlet5 relocated jar off `runtimeElements`
The `jakarta-servlet-5.0` project added the relocated javax-to-jakarta
advice jar to the `implementation` configuration. And a project
dependency on the runtime classpath resolves the producer's
`runtimeElements` variant. That variant publishes the project jar and
its runtime dependencies that are derived from `implementation`, so
consumers (the instrumentation project in particular) received the same
classes twice:
1. once from the module jar configured with
`from zipTree(relocatedJavaxJar.outputs.files.asPath)`,
2. once from the relocated jar published as a runtime dependency
This change keeps the relocated jar local to the producer module's
_compile_ and _test_ classpaths with `compileOnly` and
`testImplementation` respectively.
The module jar remains the runtime artifact consumed by downstream
projects, and it still contains the relocated servlet5 advice classes.
With this, the last duplicate is gone, so drop the remaining
`filesMatching { EXCLUDE }` workaround and refresh the comment.
chore(build): Use lazy API on jakarta-servlet-5.0 shadow jar task
fix(build): Muzzle supports projects having jars outside runtimeClasspath
Teach `MuzzleTask` to include an extra classpath (if provided). The goal
is to allow it to see the relocated servlet5 jar.
It is done by introducing `extraAgentClasspath` on the `MuzzelTask`.
Another approach would have been to include the relcated jar on the
runtimeClasspath: `sourceSets.main.runtimeClasspath += files(relocatedJavaxJarFile)`
However this approach creates confusion ; anything that consume this
configuration would see the relocated jar (e.g. during debug).
Co-authored-by: brice.dutheil <brice.dutheil@datadoghq.com>1 parent bb6b14a commit 2068d0d
5 files changed
Lines changed: 78 additions & 32 deletions
File tree
- buildSrc/src/main/kotlin/datadog/gradle/plugin/muzzle/tasks
- dd-java-agent
- agent-installer
- instrumentation
- servlet/jakarta-servlet-5.0
- gradle
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
| |||
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
122 | | - | |
| 127 | + | |
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
45 | 58 | | |
46 | 59 | | |
| 60 | + | |
| 61 | + | |
47 | 62 | | |
48 | 63 | | |
49 | | - | |
50 | | - | |
| 64 | + | |
51 | 65 | | |
52 | 66 | | |
53 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 122 | + | |
128 | 123 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
133 | 127 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
147 | 131 | | |
148 | 132 | | |
149 | 133 | | |
| |||
Lines changed: 26 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
55 | 71 | | |
56 | 72 | | |
57 | 73 | | |
| |||
76 | 92 | | |
77 | 93 | | |
78 | 94 | | |
79 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
80 | 103 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
111 | 113 | | |
112 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
113 | 132 | | |
114 | | - | |
| 133 | + | |
| 134 | + | |
115 | 135 | | |
116 | 136 | | |
117 | 137 | | |
| |||
0 commit comments