plugins {
  id 'java-gradle-plugin'
  id 'org.jetbrains.kotlin.jvm'
  id 'groovy'
  id 'maven-publish'
  id 'com.gradle.plugin-publish'
  id 'com.autonomousapps.plugin-best-practices-plugin'
  id 'com.autonomousapps.dependency-analysis'
}

group = 'com.autonomousapps'
version = '0.11-SNAPSHOT'

java {
  toolchain {
    languageVersion.set(JavaLanguageVersion.of(11))
  }
  withJavadocJar()
  withSourcesJar()
}

dependencies {
  api(libs.moshi.core)
  api(libs.moshix.sealed.runtime)

  implementation platform(libs.kotlin.bom)
  implementation(libs.kotlin.stdlib.jdk8)
  implementation(libs.moshi.kotlin)
  implementation(libs.moshix.sealed.reflect)
  implementation(libs.relocated.asm) {
    because 'Bytecode analysis'
  }
  implementation('com.autonomousapps:graph-support:0.1') {
    because 'Graphs'
  }
  implementation(libs.guava) {
    because 'Graphs'
  }
}

dependencyAnalysis {
  issues {
    onAny {
      severity 'fail'
    }
    onIncorrectConfiguration {
      exclude(
        // DAGP thinks this should be on `functionalTestApi`, which might be technically correct but also makes no sense
        'org.spockframework:spock-core',
      )
    }
    onUsedTransitiveDependencies {
      exclude(
        // DAGP thinks this should be on `functionalTestApi`, which might be technically correct but also makes no sense
        'org.codehaus.groovy:groovy',
        'org.junit.jupiter:junit-jupiter-api',
      )
    }
  }
}

testing {
  suites {
    // Configure the built-in test suite
    test {
      useJUnitJupiter()
      dependencies {
        implementation 'com.google.truth:truth:1.1.3'
      }
    }

    // Create a new test suite
    functionalTest(JvmTestSuite) {
      // Use Kotlin Test test framework
      useSpock()

      targets {
        all {
          // This test suite should run after the built-in test suite has run its tests
          testTask.configure { shouldRunAfter(test) }
        }
      }
    }
  }
}

gradlePlugin {
  plugins {
    plugin {
      id = 'com.autonomousapps.plugin-best-practices-plugin'
      implementationClass = 'com.autonomousapps.GradleBestPracticesPlugin'
      displayName = 'Gradle Best Practices Plugin'
      description = 'Gradle Plugin that detects violations of Gradle best practices in Gradle Plugins'
    }
  }
}

gradlePlugin.testSourceSets(sourceSets.functionalTest)

def check = tasks.named('check') {
  dependsOn(testing.suites.functionalTest)
}

tasks.named('publishPlugins') {
  dependsOn(check)
}

pluginBundle {
  website = 'https://github.com/autonomousapps/gradle-best-practices-plugin'
  vcsUrl = 'https://github.com/autonomousapps/gradle-best-practices-plugin'
  tags = ['best practices']
}
