File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
log4j-samples-gradle-metadata Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1616 */
1717plugins {
1818 id(" application" )
19+ id " io.spring.dependency-management" version " 1.1.7"
1920}
2021
2122def log4jVersion = providers. environmentVariable(" LOG4J_VERSION" ). getOrElse(" 2.25.0" )
Original file line number Diff line number Diff line change @@ -21,6 +21,42 @@ pluginManagement {
2121 mavenCentral()
2222 }
2323}
24+
25+ /*
26+ * Fail the build if any WARN/ERROR log events occur.
27+ * Some projects forbid *any* build-time logging at these levels;
28+ * this ensures Log4j upgrades don't get blocked by harmless noise.
29+ *
30+ * See: https://github.com/apache/logging-log4j2/issues/3779
31+ */
32+ import org.gradle.internal.logging.events.LogEvent
33+ import org.gradle.internal.logging.LoggingManagerInternal
34+ def events = []
35+ def listener = { e ->
36+ if (e instanceof LogEvent && e. logLevel. ordinal() >= LogLevel . WARN . ordinal()) {
37+ events << e
38+ }
39+ }
40+
41+ gradle. settingsEvaluated {
42+ def loggingManager = gradle. services. get(LoggingManagerInternal )
43+ loggingManager. addOutputEventListener(listener)
44+ /*
45+ * Note: This relies on Gradle’s internal logging APIs.
46+ * It may break in Gradle 9.x or later, but that’s expected —
47+ * using internal hooks is unsupported until Gradle provides a stable alternative.
48+ */
49+ gradle. buildFinished {
50+ loggingManager. removeOutputEventListener(listener)
51+ if (! events. isEmpty()) {
52+ println " \n * Build failed due to ${ events.size()} WARN/ERROR log event(s):"
53+ events. each { println " [${ it.logLevel} ] ${ it.message} " }
54+ throw new GradleException (" Build aborted: disallowed WARN/ERROR log events detected." )
55+ }
56+ }
57+ }
58+
59+
2460dependencyResolutionManagement {
2561 repositoriesMode. set(RepositoriesMode . FAIL_ON_PROJECT_REPOS )
2662 repositories {
You can’t perform that action at this time.
0 commit comments