Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions log4j-samples-gradle-metadata/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
plugins {
id("application")
id "io.spring.dependency-management" version "1.1.7"
}

def log4jVersion = providers.environmentVariable("LOG4J_VERSION").getOrElse("2.25.0")
Expand Down
36 changes: 36 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@ pluginManagement {
mavenCentral()
}
}

/*
* Fail the build if any WARN/ERROR log events occur.
* Some projects forbid *any* build-time logging at these levels;
* this ensures Log4j upgrades don't get blocked by harmless noise.
*
* See: https://github.com/apache/logging-log4j2/issues/3779
*/
import org.gradle.internal.logging.events.LogEvent
import org.gradle.internal.logging.LoggingManagerInternal
def events = []
def listener = { e ->
if (e instanceof LogEvent && e.logLevel.ordinal() >= LogLevel.WARN.ordinal()) {
events << e
}
}

gradle.settingsEvaluated {
def loggingManager = gradle.services.get(LoggingManagerInternal)
loggingManager.addOutputEventListener(listener)
/*
* Note: This relies on Gradle’s internal logging APIs.
* It may break in Gradle 9.x or later, but that’s expected —
* using internal hooks is unsupported until Gradle provides a stable alternative.
*/
gradle.buildFinished {
loggingManager.removeOutputEventListener(listener)
if (!events.isEmpty()) {
println "\n* Build failed due to ${events.size()} WARN/ERROR log event(s):"
events.each { println "[${it.logLevel}] ${it.message}" }
throw new GradleException("Build aborted: disallowed WARN/ERROR log events detected.")
}
}
}


dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
Expand Down
Loading