buildscript {
    ext.kotlin_version = '1.4.0'

    repositories {
        mavenCentral()
        maven {
            name 'JFrog OSS snapshot repo'
            url  'https://oss.jfrog.org/oss-snapshot-local/'
        }
        jcenter()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

ext.antlr_version='4.8-1'
ext.kolasu_version='v1.0.0'

def kanvasVersion = '0.2.5-SNAPSHOT'

task version {
    doLast {
        print "Version ${kanvasVersion}"
    }
}

allprojects {

    apply plugin: 'kotlin'
    apply plugin: 'java'
    apply plugin: 'antlr'
    apply plugin: 'maven'
    apply plugin: 'idea'

    group = 'me.tomassetti.kanvas'
    version = kanvasVersion    

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }

}

subprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    task javadocJar(type: Jar) {
        classifier = 'javadoc'
        from javadoc
    }

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

    if (JavaVersion.current().isJava8Compatible()) {
        allprojects {
            tasks.withType(Javadoc) {
                options.addStringOption('Xdoclint:none', '-quiet')
            }
        }
    }

    artifacts {
        archives javadocJar, sourcesJar
    }

    task generatePom {
        doLast {
            def generatedPom = pom {
                project {
                    name project.name
                    description 'Kanvas is a framework to create flexible desktop editors'
                    version kanvasVersion
                    packaging 'jar'
                    url 'https://github.com/ftomassetti/kanvas'

                    scm {
                        connection 'scm:git:https://github.com/ftomassetti/kanvas.git'
                        developerConnection 'scm:git:git@github.com:ftomassetti/kanvas.git'
                        url 'https://github.com/ftomassetti/kanvas.git'
                    }

                    licenses {
                        license {
                            name 'The MIT License (MIT)'
                            url 'http://opensource.org/licenses/MIT'
                            distribution 'repo'
                        }
                    }

                    developers {
                        developer {
                            id = 'ftomassetti'
                            name = 'Federico Tomassetti'
                            email = 'federico@tomassetti.me'
                        }
                    }
                }
            }
            generatedPom.writeTo("$buildDir/pom.xml")
        }
    }
}

task sign(type:Exec) {
    doLast {
        String home = System.getProperty("user.home")
        String passphrase = new File(home + '/.gnupg/passphrase.txt').text
        commandLine 'gpg2', '--passphrase', passphrase, '--batch', '--yes', '--no-tty', '-ab', 'java-symbol-solver-core/build/pom.xml'
    }
}
