/*
 * Copyright © 2018-2019, 2022 Apple Inc. and the ServiceTalk project authors
 *
 * Licensed 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.
 */

apply plugin: "io.servicetalk.servicetalk-gradle-plugin-internal-core"
apply plugin: "java-platform"

description="ServiceTalk BOM that includes all modules"

rootProject.subprojects.findAll { !it.path.endsWith("-bom") && !it.path.endsWith("-dependencies") &&
                                  !it.path.endsWith("-benchmarks") &&
                                  !it.path.endsWith("servicetalk-gradle-plugin-internal") &&
                                  !it.path.startsWith(":servicetalk-examples")}.each {
    dependencies.constraints.add("api", it)
}

// Keep publishing and signing configuration in sync with ServiceTalkLibraryPlugin.groovy from
// servicetalk-gradle-plugin-internal
publishing {
  publications {
    mavenJava(MavenPublication) {
      // publish POM
      from components.javaPlatform
      pom {
        name = project.name
        description = project.description
        url = 'https://servicetalk.io'
        licenses {
          license {
            name = 'The Apache License, Version 2.0'
            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
          }
        }
        developers {
          developer {
            id = 'servicetalk-project-authors'
            name = 'ServiceTalk project authors'
            email = 'servicetalk-oss@group.apple.com'
          }
        }
        scm {
          connection = "scm:git:git://${scmHost}/${scmPath}.git"
          developerConnection = "scm:git:ssh://${scmHost}:${scmPath}.git"
          url = "https://${scmHost}/${scmPath}"
        }
        issueManagement {
          system = 'ServiceTalk Issues'
          url = "${issueManagementUrl}"
        }
        ciManagement {
          system = 'ServiceTalk CI'
          url = "${ciManagementUrl}"
        }
      }
    }
  }

  if (!repositories) {
    repositories {
      maven {
        name = "sonatype"
        def releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
        def snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/"
        url = project.isReleaseBuild ? releasesRepoUrl : snapshotsRepoUrl
        credentials {
          username = System.getenv("SONATYPE_USER")
          password = System.getenv("SONATYPE_TOKEN")
        }
      }
    }
  }
}

if (!!findProperty("signingKey") && !!findProperty("signingPassword")) {
  pluginManager.apply("signing")
  signing {
    def signingKey = findProperty("signingKey")
    def signingPassword = findProperty("signingPassword")
    useInMemoryPgpKeys(signingKey, signingPassword)
    sign publishing.publications.mavenJava
  }
}
