/*
 * 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.
 */

// Globally exclude known bad dependencies to ensure they aren't included in any transitive dependency.

allprojects { prj ->
  // Ensure we only limit to compilation and runtime configurations for the JavaPlugin.
  // There doesn't seem to be a way to pull this out of JavaPlugin programatically.
  // https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations
  def configNames = [
      Dependency.DEFAULT_CONFIGURATION,
      JavaPlugin.API_CONFIGURATION_NAME,
      JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME,
      JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME,
      JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME,
      JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME,
      JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME,
      JavaPlugin.TEST_COMPILE_ONLY_CONFIGURATION_NAME,
      JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME,
      // gradle/validation/jar-checks.gradle uses the compile and runtime classpaths
      // to find jars so need to exclude otherwise license files are created.
      JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME,
      JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME,
      JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME,
      JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME
  ]
  configurations.matching { it.name in configNames }.all {
    exclude group: 'log4j', module: 'log4j' // use SLF4j
    exclude group: "ch.qos.logback" // use SLF4j
    exclude group: 'commons-logging', module: 'commons-logging' // use SLF4j
    exclude group: 'com.google.code.findbugs', module: 'jsr305' // Uses GPL license
    exclude group: 'com.google.code.findbugs', module: 'annotations' // Use Spotbugs Annotations as replacement
    exclude group: 'javax.annotation', module: 'javax.annotation-api' // Replaced with jakarta.annotation-api
    exclude group: 'org.slf4j', module: 'slf4j-log4j12' // don't include log4j 1.x
    exclude group: 'org.apache.yetus', module: 'audience-annotations' // Don't need annotations
    exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations' // Don't need annotations
    exclude group: 'net.jcip', module: 'jcip-annotations' // use com.github.stephenc.jcip instead
    // be conservative on what's added here.  Affects all Java project compilation and runtime.
  }
}
