/*
 * Copyright Thoughtworks, Inc.
 *
 * 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.
 */

plugins {
  id 'maven-publish'
}

description = 'Interfaces necessary for GoCD to access plugins'

compileJava {
  // Use older source compatibility for Plugin API consumed by plugins. No need to break this compatibility
  // for a while yet, so plugins work on older versions.
  options.release.set(11)
}

dependencies {
  api project(':plugin-infra:go-plugin-api-internal')
  testImplementation project.deps.junit5Api
  testRuntimeOnly project.deps.junit5Engine
  testRuntimeOnly project.deps.junit5PlatformLauncher
  testImplementation project.deps.mockitoCore
  testImplementation project.deps.assertJ
  testImplementation(testFixtures(project(':test:test-utils')))
}

tasks.register('sourcesJar', Jar) {
  dependsOn classes
  archiveClassifier = 'sources'
  from sourceSets.main.allSource
}

javadoc {
  title = 'GoCD Plugin API'

  options {
    windowTitle = 'GoCD Plugin API'
    docTitle = 'GoCD Plugin API'
    header = 'GoCD Plugin API'
    bottom = "Copyright &copy; Thoughtworks, Inc. GoCD Version: ${project.version}"

    addBooleanOption('Xdoclint:-missing', true)
  }
}

tasks.register('javadocJar', Jar) {
  dependsOn javadoc
  archiveClassifier = 'javadoc'
  from javadoc.destinationDir
}

assemble.dependsOn sourcesJar, javadocJar

publishing {
  publications {
    mavenJava(MavenPublication) {
      groupId = 'cd.go.plugin'
      from components.java

      // Clear the dependencyManagement and compileOnly dependencies
      pom.withXml {
        asNode().dependencyManagement.replaceNode {}
        asNode().dependencies.replaceNode {}
      }
    }
  }
}

tasks.withType(GenerateModuleMetadata).configureEach {
  enabled = false
}
