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

import javax.tools.ToolProvider


subprojects {
  plugins.withType(JavaPlugin) {
    configurations {
      customTestCompile
      compile
      dependencies {
        if (!project.name.contains('gobblin-elasticsearch-deps')) {
          compile(externalDependency.hadoopCommon) {
            exclude module: 'servlet-api'
          }
          compile externalDependency.hadoopClientCore
          compile externalDependency.hadoopAnnotations
          if (project.name.equals('gobblin-runtime') || project.name.equals('gobblin-test')) {
            compile externalDependency.hadoopClientCommon
          }
          compile(externalDependency.guava) {
              force = true
          }
        }
        compile(externalDependency.commonsCodec) {
          force = true
        }
        //Since testCompile inherit from compile, so we cannot use testCompile to import dependency for log4j
        customTestCompile externalDependency.log4j
        customTestCompile externalDependency.slf4jToLog4j

        // Required to add JDK's tool jar, which is required to run byteman tests.
        testCompile (files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()))
      }
      if (!project.name.contains('gobblin-aws') && !project.name.contains('gobblin-distribution')) {
        configurations.compile.dependencies*.each {
          //exclude this jar because we introduce log4j-over-slf4j, these two jars cannot present at the same time
          it.exclude group: 'org.slf4j', module: 'slf4j-log4j12'
          //exclude log4j related jars to provide a clean log environment
          it.exclude group: 'log4j', module: 'log4j'
          it.exclude group: 'log4j', module: 'apache-log4j-extras'
        }
      }
      all*.exclude group: 'org.apache.calcite', module: 'calcite-avatica' // replaced by org.apache.calcite.avatica:avatica-core
      //exclude this jar in test class path because we are using log4j implementation to test
      testCompile.exclude group: 'org.slf4j', module: 'log4j-over-slf4j'
    }
    test{
      //Add log4j into runtime path
      classpath += configurations.customTestCompile
      //Add log4j into compile path
      sourceSets.test.compileClasspath += configurations.customTestCompile
    }
  }

  dependencies {
    // Gradle 5 compatibility
    compileOnly externalDependency.lombok
    testCompileOnly externalDependency.lombok
    annotationProcessor externalDependency.lombok
    testAnnotationProcessor externalDependency.lombok
  }
}
