Skip to content

Commit 1fdb5b2

Browse files
authored
[ISSUE #4700] Remove logging backends from runtime deps (#4719)
* [ISSUE #4700] Remove logging backends from runtime deps This PR removes all the logging backends from the Maven artifacts. As explained in #4700 libraries should only depend on logging APIs, not logging implementations the same way web applications depend on the Servlet API, not its implementations. The logging backends are added to the `dist` folder to be included in the TAR binary distribution. * Fix licenses * Fix Logback exclusions * Fix license check * Fix `printProjects` according to the review * Add logging backend to `eventmesh-starter` * Remove task description * Fix task dependencies of task `installPlugin` * Fix `installPlugin` task * Add comment about exclusions * Minimize changes to current configuration This commit minimizes the changes to EventMesh dependencies. Since a global exclusion is not an effective way to stop propagating logging backends as **transitive** dependencies we: * explictly remove logging backends from third-party dependencies that include them: RocketMQ, Pulsar, Spring Boot and Zookeeper, * restore Log4j Core as dependency of `eventmesh-common`, * exclude Log4j Core as dependency of `eventmesh-sdk-java`. * Add comments to remove exclusions after upgrade * Make `installPlugin` independent from `dist` * Make `copy` tasks easier to understand * Add `eventmesh-common` to EventMesh OpenConnect deps * Refactor RocketMQ deps * Delete `output.dirs` * Fix typo * Remove last `outputs.dir` * Remove dependencies from `installPlugin` * Add `eventmesh-common` to OpenConnect artifacts
1 parent 9aba654 commit 1fdb5b2

File tree

27 files changed

+189
-251
lines changed

27 files changed

+189
-251
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ node_modules
2727
h2/db.mv.db
2828

2929
# license check tmp file
30-
all-dependencies.txt
30+
/tools/dependency-check/all-dependencies.txt
3131
self-modules.txt
3232
third-party-dependencies.txt
3333

@@ -50,4 +50,4 @@ bld/
5050
**/org/apache/eventmesh/connector/jdbc/antlr4/autogeneration/*
5151

5252
#rust
53-
Cargo.lock
53+
Cargo.lock

build.gradle

Lines changed: 83 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,58 @@ allprojects {
139139
}
140140
}
141141

142-
task tar(type: Tar) {
142+
tasks.register('dist') {
143+
subprojects.forEach { subProject ->
144+
dependsOn("${subProject.path}:jar")
145+
}
146+
def includedProjects =
147+
["eventmesh-common",
148+
"eventmesh-meta:eventmesh-meta-api",
149+
"eventmesh-metrics-plugin:eventmesh-metrics-api",
150+
"eventmesh-protocol-plugin:eventmesh-protocol-api",
151+
"eventmesh-retry:eventmesh-retry-api",
152+
"eventmesh-runtime",
153+
"eventmesh-security-plugin:eventmesh-security-api",
154+
"eventmesh-spi",
155+
"eventmesh-starter",
156+
"eventmesh-storage-plugin:eventmesh-storage-api",
157+
"eventmesh-trace-plugin:eventmesh-trace-api",
158+
"eventmesh-webhook:eventmesh-webhook-api",
159+
"eventmesh-webhook:eventmesh-webhook-admin",
160+
"eventmesh-webhook:eventmesh-webhook-receive"]
161+
doLast {
162+
includedProjects.each {
163+
def subProject = findProject(it)
164+
logger.lifecycle('Install module: module: {}', subProject.name)
165+
copy {
166+
from subProject.jar.archivePath
167+
into rootProject.file('dist/apps')
168+
}
169+
copy {
170+
from subProject.file('bin')
171+
into rootProject.file('dist/bin')
172+
}
173+
copy {
174+
from subProject.file('conf')
175+
from subProject.sourceSets.main.resources.srcDirs
176+
into rootProject.file('dist/conf')
177+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
178+
exclude 'META-INF'
179+
}
180+
copy {
181+
from subProject.configurations.runtimeClasspath
182+
into rootProject.file('dist/lib')
183+
exclude 'eventmesh-*'
184+
}
185+
}
186+
copy {
187+
from 'tools/third-party-licenses'
188+
into rootProject.file('dist')
189+
}
190+
}
191+
}
192+
193+
tasks.register('tar', Tar) {
143194
archiveBaseName.set(project.name)
144195
archiveVersion.set(project.version.toString())
145196
archiveExtension.set('tar.gz')
@@ -150,7 +201,7 @@ task tar(type: Tar) {
150201
}
151202
}
152203

153-
task zip(type: Zip) {
204+
tasks.register('zip', Zip) {
154205
archiveBaseName.set(project.name)
155206
archiveVersion.set(project.version.toString())
156207
archiveExtension.set('zip')
@@ -160,50 +211,39 @@ task zip(type: Zip) {
160211
}
161212
}
162213

163-
task installPlugin() {
164-
if (!new File("${rootDir}/dist").exists()) {
165-
return
214+
tasks.register('installPlugin') {
215+
var pluginProjects = subprojects.findAll {
216+
it.file('gradle.properties').exists()
217+
&& it.properties.containsKey('pluginType')
218+
&& it.properties.containsKey('pluginName')
219+
}
220+
doLast {
221+
String[] libJars = java.util.Optional.ofNullable(file('dist/lib').list()).orElse(new String[0])
222+
pluginProjects.forEach(subProject -> {
223+
var pluginType = subProject.properties.get('pluginType')
224+
var pluginName = subProject.properties.get('pluginName')
225+
logger.lifecycle('Install plugin: pluginType: {}, pluginInstanceName: {}, module: {}', pluginType,
226+
pluginName, subProject.name)
227+
copy {
228+
from subProject.jar.archivePath
229+
into rootProject.file("dist/plugin/${pluginType}/${pluginName}")
230+
}
231+
copy {
232+
from subProject.configurations.runtimeClasspath
233+
into rootProject.file("dist/plugin/${pluginType}/${pluginName}")
234+
exclude(libJars)
235+
}
236+
copy {
237+
from subProject.file('conf')
238+
from subProject.sourceSets.main.resources.srcDirs
239+
into rootProject.file("dist/conf")
240+
exclude 'META-INF'
241+
}
242+
})
166243
}
167-
String[] libJars = java.util.Optional.ofNullable(new File("${rootDir}/dist/lib").list()).orElseGet(() -> new String[0])
168-
getAllprojects().forEach(subProject -> {
169-
var file = new File("${subProject.projectDir}/gradle.properties")
170-
if (!file.exists()) {
171-
return
172-
}
173-
var properties = new Properties()
174-
properties.load(new FileInputStream(file))
175-
var pluginType = properties.getProperty("pluginType")
176-
var pluginName = properties.getProperty("pluginName")
177-
if (pluginType == null || pluginName == null) {
178-
return
179-
}
180-
var pluginFile = new File("${rootDir}/dist/plugin/${pluginType}/${pluginName}")
181-
if (pluginFile.exists()) {
182-
return
183-
}
184-
pluginFile.mkdirs()
185-
println String.format(
186-
"install plugin, pluginType: %s, pluginInstanceName: %s, module: %s", pluginType, pluginName, subProject.getName()
187-
)
188-
189-
copy {
190-
into "${rootDir}/dist/plugin/${pluginType}/${pluginName}"
191-
from "${subProject.getProjectDir()}/dist/apps"
192-
}
193-
copy {
194-
into "${rootDir}/dist/plugin/${pluginType}/${pluginName}"
195-
from "${subProject.getProjectDir()}/dist/lib/"
196-
exclude(libJars)
197-
}
198-
copy {
199-
into "${rootDir}/dist/conf"
200-
from "${subProject.getProjectDir()}/dist/conf"
201-
exclude 'META-INF'
202-
}
203-
})
204244
}
205245

206-
task printProjects() {
246+
tasks.register('printProjects') {
207247
getAllprojects().forEach(subProject -> {
208248
if ("EventMesh".equals(subProject.getName())) {
209249
return
@@ -303,77 +343,6 @@ subprojects {
303343
}
304344
}
305345

306-
task dist(dependsOn: ['jar']) {
307-
doFirst {
308-
new File("${projectDir}/dist/bin").mkdirs()
309-
new File("${projectDir}/dist/apps").mkdirs()
310-
new File("${projectDir}/dist/conf").mkdirs()
311-
new File("${projectDir}/dist/lib").mkdirs()
312-
new File("${projectDir}/dist/licenses").mkdirs()
313-
}
314-
Set<String> rootProject = ["eventmesh-common",
315-
"eventmesh-storage-api",
316-
"eventmesh-metrics-api",
317-
"eventmesh-meta-api",
318-
"eventmesh-trace-api",
319-
"eventmesh-retry-api",
320-
"eventmesh-runtime",
321-
"eventmesh-security-api",
322-
"eventmesh-protocol-api",
323-
"eventmesh-starter",
324-
"eventmesh-spi",
325-
"eventmesh-webhook-api",
326-
"eventmesh-webhook-admin",
327-
"eventmesh-webhook-receive"]
328-
doLast {
329-
copy {
330-
into("${projectDir}/dist/apps")
331-
from project.jar.getArchivePath()
332-
}
333-
copy {
334-
into("${projectDir}/dist/lib")
335-
from project.configurations.runtimeClasspath
336-
}
337-
copy {
338-
into("${projectDir}/dist/bin")
339-
from 'bin'
340-
}
341-
copy {
342-
into("${projectDir}/dist/conf")
343-
from 'conf', sourceSets.main.resources.srcDirs
344-
setDuplicatesStrategy(DuplicatesStrategy.EXCLUDE)
345-
exclude 'META-INF'
346-
}
347-
if (rootProject.contains(project.name)) {
348-
new File("${rootDir}/dist/apps").mkdirs()
349-
new File("${rootDir}/dist/lib").mkdirs()
350-
new File("${rootDir}/dist/bin").mkdirs()
351-
new File("${rootDir}/dist/conf").mkdirs()
352-
copy {
353-
into("${rootDir}/dist/apps")
354-
from "${projectDir}/dist/apps"
355-
}
356-
copy {
357-
into "${rootDir}/dist/lib"
358-
from "${projectDir}/dist/lib"
359-
exclude "eventmesh-*"
360-
}
361-
copy {
362-
into "${rootDir}/dist/bin"
363-
from "${projectDir}/dist/bin"
364-
}
365-
copy {
366-
into "${rootDir}/dist/conf"
367-
from "${projectDir}/dist/conf"
368-
}
369-
}
370-
copy {
371-
into "${rootDir}/dist"
372-
from "${rootDir}/tools/third-party-licenses"
373-
}
374-
}
375-
}
376-
377346
javadoc {
378347
source = sourceSets.main.java
379348
destinationDir = reporting.file("javadoc")
@@ -491,7 +460,6 @@ subprojects {
491460
dependency "org.apache.logging.log4j:log4j-api:${log4jVersion}"
492461
dependency "org.apache.logging.log4j:log4j-core:${log4jVersion}"
493462
dependency "org.apache.logging.log4j:log4j-slf4j2-impl:${log4jVersion}"
494-
dependency "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}" // used with SLF4J 1.7.x or older for third-party dependencies
495463

496464
dependency "com.lmax:disruptor:3.4.2"
497465

eventmesh-common/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ dependencies {
3232

3333
api "com.alibaba.fastjson2:fastjson2"
3434

35-
implementation "org.apache.logging.log4j:log4j-api"
36-
implementation "org.apache.logging.log4j:log4j-core"
37-
implementation "org.apache.logging.log4j:log4j-slf4j2-impl"
35+
runtimeOnly "org.apache.logging.log4j:log4j-core"
36+
runtimeOnly "org.apache.logging.log4j:log4j-slf4j2-impl"
3837

3938
implementation 'com.github.seancfoley:ipaddress'
4039

eventmesh-connectors/eventmesh-connector-pravega/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
configurations {
19-
implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
20-
implementation.exclude group: 'log4j', module: 'log4j'
21-
}
22-
2318
dependencies {
2419
api project(":eventmesh-openconnect:eventmesh-openconnect-java")
2520
implementation project(":eventmesh-common")

eventmesh-connectors/eventmesh-connector-pulsar/build.gradle

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,27 @@
1515
* limitations under the License.
1616
*/
1717

18-
List pulsar = [
19-
"org.apache.pulsar:pulsar-client:$pulsar_version"
20-
]
2118
dependencies {
2219
implementation project(":eventmesh-openconnect:eventmesh-openconnect-java")
23-
implementation pulsar
20+
21+
/*
22+
* TODO: This is a shaded artifact that contains 20 MiB of external libraries. It could probably be replaced by:
23+
*
24+
* implementation "org.apache.pulsar:pulsar-client-api:$pulsar_version"
25+
* runtimeOnly "org.apache.pulsar:pulsar-client-original:$pulsar_version"
26+
*
27+
* The exclusions can be removed after an upgrade of the transitive:
28+
*
29+
* "org.apache.bookkeeper:bookkeeper"
30+
*
31+
* dependency to 4.15.4 or higher (used by Pulsar 2.11.2 or higher).
32+
*/
33+
implementation("org.apache.pulsar:pulsar-client:$pulsar_version") {
34+
// Remove logging backend implementations
35+
exclude group: 'org.apache.logging.log4j', module: 'log4j-core'
36+
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
37+
}
38+
2439
compileOnly 'org.projectlombok:lombok'
2540
annotationProcessor 'org.projectlombok:lombok'
2641
}

eventmesh-connectors/eventmesh-connector-rabbitmq/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
*/
1717

1818

19-
configurations {
20-
implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
21-
implementation.exclude group: 'log4j', module: 'log4j'
22-
}
23-
2419
dependencies {
2520
api project(":eventmesh-openconnect:eventmesh-openconnect-java")
2621
implementation project(":eventmesh-common")

eventmesh-connectors/eventmesh-connector-rocketmq/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ List rocketmq = [
3434
dependencies {
3535
api project(":eventmesh-openconnect:eventmesh-openconnect-java")
3636
implementation project(":eventmesh-common")
37-
implementation rocketmq
37+
/*
38+
* The exclusions can be removed after this issue is fixed:
39+
* https://github.com/apache/rocketmq/issues/5347
40+
*/
41+
rocketmq.each {
42+
implementation(it) {
43+
exclude group: 'ch.qos.logback', module: 'logback-classic'
44+
}
45+
}
46+
3847
compileOnly 'org.projectlombok:lombok'
3948
annotationProcessor 'org.projectlombok:lombok'
4049
testImplementation "org.mockito:mockito-core"

eventmesh-connectors/eventmesh-connector-slack/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
configurations {
19-
implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
20-
implementation.exclude group: 'log4j', module: 'log4j'
21-
testImplementation.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
22-
}
23-
2418
dependencies {
2519
implementation project(":eventmesh-common")
2620
implementation project(":eventmesh-sdks:eventmesh-sdk-java")

eventmesh-connectors/eventmesh-connector-spring/build.gradle

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
* limitations under the License.
1616
*/
1717

18-
configurations {
19-
implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
20-
implementation.exclude group: 'log4j', module: 'log4j'
21-
implementation.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
22-
testImplementation.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
23-
}
24-
2518
dependencies {
2619
api project(":eventmesh-openconnect:eventmesh-openconnect-java")
2720
implementation project(":eventmesh-common")
2821
implementation project(":eventmesh-sdks:eventmesh-sdk-java")
29-
implementation "org.springframework.boot:spring-boot-starter:$spring_boot_version"
30-
implementation "org.springframework.boot:spring-boot-starter-validation:$spring_boot_version"
22+
23+
/*
24+
* TODO: Are these dependencies necessary? The source code only requires these two dependencies
25+
* that do not propagate logging backends:
26+
*
27+
* api "org.springframework:spring-context:$spring_version"
28+
* implementation "org.springframework.boot:spring-boot-autoconfigure:$spring_boot_version"
29+
*/
30+
implementation("org.springframework.boot:spring-boot-starter-validation:$spring_boot_version") {
31+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
32+
}
3133
implementation "org.springframework:spring-messaging:$spring_version"
34+
3235
compileOnly 'org.projectlombok:lombok'
3336
annotationProcessor 'org.projectlombok:lombok'
3437

eventmesh-connectors/eventmesh-connector-wechat/build.gradle

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
configurations {
19-
implementation.exclude group: 'ch.qos.logback', module: 'logback-classic'
20-
implementation.exclude group: 'log4j', module: 'log4j'
21-
testImplementation.exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
22-
}
23-
2418
dependencies {
2519
implementation project(":eventmesh-common")
2620
implementation project(":eventmesh-sdks:eventmesh-sdk-java")

0 commit comments

Comments
 (0)