plugins {
  id 'groovy'
  id 'maven-publish'
  id 'jacoco'
  id 'pl.allegro.tech.build.axion-release' version '1.13.3'
  id 'com.gradle.plugin-publish' version '0.15.0'
  id "java-gradle-plugin"
  id "io.github.gradle-nexus.publish-plugin" version '1.1.0'
}

sourceCompatibility = JavaVersion.VERSION_1_8

configurations {
  provided
}

repositories {
  mavenCentral()
  google()
}

dependencies {
  implementation gradleApi()
  implementation localGroovy()

  compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

  testImplementation(group: 'org.spockframework', name: 'spock-core', version: '2.0-M3-groovy-3.0') {
    exclude group: 'org.codehaus.groovy', module: 'groovy-all'
  }
  testImplementation 'com.android.tools.build:gradle:7.0.2'
  testImplementation 'commons-io:commons-io:2.4'
  testImplementation 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21'
}

scmVersion {
  tag {
    prefix = 'jacoco-android-release-'
  }
  versionCreator "versionWithBranch"
}

group = 'com.dicedmelon.gradle'
version = scmVersion.version

test {
  testLogging {
    exceptionFormat "full"
  }
}

jacocoTestReport {
  reports {
    html.enabled false
    xml.enabled true
  }
}

task sourcesJar(type: Jar) {
  archiveClassifier.set('sources')
  from sourceSets.main.allSource
}

publishing {
  publications {
    plugin(MavenPublication) {
      from components.java

      artifact sourcesJar
    }
  }
}

gradlePlugin {
  plugins {
    jacocoAndroidGradlePlugin {
      id = 'com.dicedmelon.gradle.jacoco-android'
      displayName = 'Plugin for simplifying JacocoReport configuration for Android projects'
      description =
          'A Gradle plugin that adds fully configured JacocoReport tasks for unit tests of each Android application and library project variant.'
      implementationClass = 'com.dicedmelon.gradle.jacoco.android.JacocoAndroidPlugin'
    }
  }
}

pluginBundle {
  website = 'https://github.com/arturdm/jacoco-android-gradle-plugin'
  vcsUrl = 'https://github.com/arturdm/jacoco-android-gradle-plugin'
  tags = ['android', 'jacoco', 'testing', 'coverage', 'integrationtesting']

  plugins {
    jacocoAndroidGradlePlugin
  }
}

nexusPublishing {
  repositories {
    sonatype {
      nexusUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
      snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
    }
  }
}
