plugins {
  id 'io.freefair.maven-plugin'
  id 'net.researchgate.release'
  id 'maven-publish'
  id 'eclipse'
}

// only maven specific dependencies should be versioned, everything else should be defined by constrains in
// parent build.gradle
dependencies {
  sourceProject project(':jib-core')
  sourceProject project(':jib-plugins-common')
  ensureNoProjectDependencies()

  implementation dependencyStrings.MAVEN_EXTENSION

  implementation dependencyStrings.MAVEN_API
  implementation dependencyStrings.MAVEN_CORE

  // compileOnly + testImplementation equivalent to "provided"
  compileOnly dependencyStrings.MAVEN_PLUGIN_ANNOTATIONS
  // needed to suppress "unknown enum constant" warnings
  testImplementation dependencyStrings.MAVEN_PLUGIN_ANNOTATIONS

  // maven-plugin-testing-harness pulls in conflicting implementations of DefaultPlexusContainer
  // (sisu (correct) vs default-plexus-container (wrong)) so ensure this is first in the test classpath
  testImplementation dependencyStrings.SISU_PLEXUS
  testImplementation dependencyStrings.MAVEN_TESTING_HARNESS

  testImplementation dependencyStrings.JUNIT
  testImplementation dependencyStrings.TRUTH
  testImplementation dependencyStrings.TRUTH8
  testImplementation dependencyStrings.MOCKITO_CORE
  testImplementation dependencyStrings.SLF4J_API
  testImplementation dependencyStrings.SYSTEM_RULES

  testImplementation dependencyStrings.MAVEN_VERIFIER
  testImplementation dependencyStrings.MAVEN_COMPAT
  testImplementation dependencyStrings.SLF4J_SIMPLE

  integrationTestImplementation dependencyStrings.JBCRYPT

  testImplementation project(path:':jib-plugins-common', configuration:'tests')
  integrationTestImplementation project(path:':jib-core', configuration:'integrationTests')
}

/* TESTING */
test.dependsOn publishToMavenLocal
integrationTest.dependsOn publishToMavenLocal
/* TESTING */

/* RELEASE */
configureMavenRelease()

publishing {
  publications {
    mavenJava(MavenPublication) {
      pom {
        name = 'Jib'
        description = 'A Maven plugin for building container images for your Java applications.'
      }
    }
  }
}


release {
  tagTemplate = 'v$version-maven'
  ignoredSnapshotDependencies = [
    'com.google.cloud.tools:jib-core',
    'com.google.cloud.tools:jib-plugins-common',
  ]
  git {
    requireBranch = /^maven-release-v\d+.*$/  //regex
  }
}
/* RELEASE */

/* ECLIPSE */
eclipse.classpath.plusConfigurations += [configurations.integrationTestImplementation]
eclipse.classpath.file.whenMerged {
  entries.each {
    if (it.path == 'src/test/resources') {
      it.excludes += 'maven/projects/'
    }
  }
}
/* ECLIPSE */
