blob: 40b922c9891d4cba47c1293eac04338b4e691349 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
/*
* Fail the build if any 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.ERROR.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()} ERROR log event(s):"
events.each { println "[${it.logLevel}] ${it.message}" }
throw new GradleException("Build aborted: disallowed ERROR log events detected.")
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// Points to the correct Apache staging repository
var apacheSnapshots = 'https://repository.apache.org/snapshots'
var repositoryUrl = providers.environmentVariable('LOG4J_REPOSITORY_URL')
.filter { !it.isEmpty() }
.getOrElse(apacheSnapshots)
maven {
name = 'Log4j Repository'
url = repositoryUrl
mavenContent {
// Only use this repository for Apache Logging Services artifacts
includeGroupAndSubgroups('org.apache.logging')
// Only use this repository for either snapshots or releases
repositoryUrl == apacheSnapshots ? snapshotsOnly() : releasesOnly()
}
}
}
}
rootProject.name = 'logging-log4j-samples'
def log4jVersion = providers.environmentVariable("LOG4J_VERSION")
.orElse(providers.gradleProperty("log4jVersion"))
.get()
gradle.beforeProject { Project it ->
it.ext.log4jVersion = log4jVersion
}
// Android example
include ':app'
project(':app').projectDir = file('log4j-samples-android/app')
// Gradle Metadata example
include ':log4j-samples-gradle-metadata'