Skip to content

Commit 6d70378

Browse files
committed
Replace slf4j-reload4j if log4j-slf4j2-impl is on the classpath for Spring Boot applications
1 parent 509bb31 commit 6d70378

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package nebula.plugin.resolutionrules
2+
3+
class SpringBootLog4j2Spec extends RulesBaseSpecification {
4+
5+
def setup() {
6+
def ruleFile = new File(getClass().getResource('/optional-spring-boot-log4j2.json').toURI())
7+
buildFile << """\
8+
dependencies {
9+
resolutionRules files('${ruleFile.absolutePath}')
10+
}
11+
12+
nebulaResolutionRules {
13+
optional = ['spring-boot-log4j2']
14+
}
15+
""".stripIndent()
16+
}
17+
18+
def 'check slf4j-reload4j replacement works'() {
19+
buildFile << '''\
20+
dependencies {
21+
implementation 'org.slf4j:slf4j-reload4j:latest.release'
22+
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:latest.release'
23+
}
24+
'''.stripIndent()
25+
26+
when:
27+
def result = runWithArgumentsSuccessfully('dependencies', '--configuration', 'compileClasspath')
28+
29+
then:
30+
result.output.contains 'org.slf4j:slf4j-reload4j:latest.release -> org.apache.logging.log4j:log4j-slf4j2-impl:'
31+
}
32+
33+
def 'leaves slf4j-reload4j if log4j-slf4j2-impl is not present'() {
34+
buildFile << '''\
35+
dependencies {
36+
implementation 'org.slf4j:slf4j-reload4j:latest.release'
37+
}
38+
'''.stripIndent()
39+
40+
when:
41+
def result = runWithArgumentsSuccessfully('dependencies', '--configuration', 'compileClasspath')
42+
43+
then:
44+
!result.output.contains('org.slf4j:slf4j-reload4j:latest.release -> org.apache.logging.log4j:log4j-slf4j2-impl:')
45+
}
46+
47+
}

src/main/resources/optional-spring-boot-log4j2.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
"reason" : "Spring Boot Log4J 2 configuration",
1515
"author" : "Danny Thomas",
1616
"date" : "2018-10-30"
17+
},
18+
{
19+
"module" : "org.slf4j:slf4j-reload4j",
20+
"with" : "org.apache.logging.log4j:log4j-slf4j2-impl",
21+
"reason" : "Spring Boot Log4J 2 configuration",
22+
"author" : "Asi Bross",
23+
"date" : "2025-05-30"
1724
}
1825
],
1926
"align": [],

0 commit comments

Comments
 (0)