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

// Using the legacy plugin classpath for Clover so it can be loaded optionally
buildscript {
    // strictly enforce the minimum version of Java required to build and fail fast
    if (JavaVersion.current() < JavaVersion.VERSION_1_8) {
        throw new GradleException("The java version used is ${JavaVersion.current()}, but must be at least ${JavaVersion.VERSION_1_8}")
    }

    repositories {
        mavenCentral()
        google()
        gradlePluginPortal()
    }

    dependencies {
        classpath 'com.bmuschko:gradle-clover-plugin:2.2.1'
    }
}

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
    id 'pmd'
    id 'com.github.johnrengelman.shadow' version '6.1.0'
    id "com.github.spotbugs" version "4.7.1"
    id "com.diffplug.spotless" version "6.5.2"
}

description = 'Apache Thrift Java Library'

defaultTasks 'build'

// Version components for this project
group = property('thrift.groupid')

if (Boolean.parseBoolean(project.release)) {
    version = property('thrift.version')
} else {
    version = property('thrift.version') + '-SNAPSHOT'
}

// Keeping the rest of the build logic in functional named scripts for clarity
apply from: 'gradle/environment.gradle'
apply from: 'gradle/sourceConfiguration.gradle'
apply from: 'gradle/generateTestThrift.gradle'
apply from: 'gradle/unitTests.gradle'
apply from: 'gradle/cloverCoverage.gradle'
apply from: 'gradle/functionalTests.gradle'
apply from: 'gradle/publishing.gradle'
apply from: 'gradle/codeQualityChecks.gradle'
