apply plugin: 'application'

if (project.statusIsRelease && project.hasProperty("sdkman_consumer_key")) {
    apply from: rootProject.file('gradle/sdkman.gradle')
}

dependencies {
  implementation(project(':asciidoctorj-cli')) {
    exclude group: 'org.jruby'
  }

  implementation("org.asciidoctor:asciidoctorj-epub3:$asciidoctorjEpub3Version") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-diagram:$asciidoctorjDiagramVersion") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-diagram-ditaamini:$asciidoctorjDiagramDitaaMiniVersion") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-diagram-plantuml:$asciidoctorjDiagramPlantumlVersion") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-diagram-jsyntrax:$asciidoctorjDiagramJsyntraxVersion") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-diagram-batik:$asciidoctorjDiagramBatikVersion") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-pdf:$asciidoctorjPdfVersion") {
    transitive = false
  }
  implementation("org.asciidoctor:asciidoctorj-revealjs:$asciidoctorjRevealJsVersion") {
    transitive = false
  }
  implementation "org.jruby:jruby-complete:$jrubyVersion"

  testImplementation (project(':asciidoctorj-test-support')) {
    exclude group: 'junit', module: 'junit'
  }
  testImplementation "org.apache.pdfbox:pdfbox:$pdfboxVersion"
  testImplementation "org.jsoup:jsoup:$jsoupVersion"
}

jar.enabled = false

configurations.archives.with {
  //We need to remove the (non-existing) jar artifact, otherwise signing will fail
  artifacts.removeAll{ it.type.equals("jar") }
}

tasks.withType(AbstractArchiveTask) {
  archiveBaseName.set(rootProject.name)
  eachFile { it.path = it.path.replaceFirst('-bin(?=/)', '') }
  //destinationDir = ...
}

startScripts {
  unixStartScriptGenerator.template = resources.text.fromFile('src/main/resources/customUnixStartScript.txt')

  applicationName = rootProject.name
  mainClass.set('org.asciidoctor.cli.jruby.AsciidoctorInvoker')
  defaultJvmOpts = [
    '--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED',
    '--add-opens', 'java.base/java.io=ALL-UNNAMED',
    '-client', '-Xmn128m', '-Xms256m', '-Xmx256m', '-Djava.awt.headless=true',
    '-Xverify:none', '-XX:+TieredCompilation', '-XX:TieredStopAtLevel=1', '-XX:+DisableExplicitGC', '-Djruby.compile.mode=OFF'
  ]
}

project.ext.publicationName = "mavenAsciidoctorJ"
// This module wants to add an artifact to the publication configured for the module asciidoctorj
// I am unaware right now how to enforce the configuration order, so it could theoretically happen that
// the publication is not available yet. In that case fail the build and find some other way to fix it...
def publication = rootProject.project('asciidoctorj').extensions.findByName('publishing').publications.findByName(project.ext.publicationName)
if (!publication) {
  throw new ProjectConfigurationException("Publication ${project.ext.publicationName} not configured yet", [])
}

publication.each {
    it.artifact(distZip) {
      classifier 'bin'
    }
}
