plugins {
    id 'java'
    id 'java-library'
    id 'maven-publish'
    id 'signing'
    id 'com.github.johnrengelman.shadow' version '4.0.2'
}

shadowJar {
    classifier = "jar"
    dependencies {
        include(dependency(fileTree(dir: 'lib', include: '*.jar')))
//        exclude(dependency('com.google.code.gson:gson:2.8.6'))
//        relocate 'com.google.code.gson', 'irs.com.google.code.gson'
    }
}
sourceSets {
    main {
        java {
            srcDirs 'src/main/base', 'src/main/analysis', 'src/main/asm', 'src/main/crypto', 'src/main/entry', 'src/main/gen', 'src/main/pythongen', 'src/main/DOIP', 'src/main/config'
        }
        resources {
            srcDir 'src/main/resources'
        }
    }
    test {
        java {
            srcDir 'src/test/java'
        }
        resources {
            srcDir 'src/test/resources'
        }
    }
}
sourceCompatibility = 1.8

dependencies {
    api 'org.bdware.bdcontract:gmhelper:0.2.0'
    api 'berkeleydb:je:3.2.76'
    //   api 'com.fifesoft:rsyntaxtextarea:3.1.3'
    api 'commons-io:commons-io:2.11.0'
    api 'io.netty:netty-all:4.1.72.Final'
    api 'org.antlr:antlr4:4.9.2'
    api 'commons-codec:commons-codec:1.5'
    api 'org.apache.logging.log4j:log4j-core:2.17.2'
    api 'org.apache.logging.log4j:log4j-api:2.17.2'
    //api 'org.apache.velocity:velocity-engine-core:2.3'
    api 'org.rocksdb:rocksdbjni:7.3.1'

    // api fileTree(dir: 'lib', include: '*.jar')

    testImplementation 'junit:junit:4.13.2'
}
group = "org.bdware.sc"
version = "1.5.9"

tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)

task copyLibs(type: Copy) {
    from configurations.runtimeClasspath
    into "./build/output/libs/"
}

task copyJar(type: Copy) {
    from "./build/libs/$project.name-${version}.jar"
    into "./build/output/"
    rename { String fileName -> "yjs.jar" }
}
//task classJar(type: Jar, dependsOn: classes) {
//    classifier = "jar"
//}
tasks.withType(Copy).all {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.withType(Jar).all {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
task sourceJar(type: Jar, dependsOn: classes) {
    archiveClassifier = "sources"
    classifier = "sources"
    from sourceSets.main.allSource
}
tasks.withType(Javadoc) {
    options.addStringOption('Xdoclint:none', '-quiet')
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    archiveClassifier = 'javadoc'
    classifier = "javadoc"
    exclude { details -> details.file.getAbsolutePath().contains("/gm/")
    }
    from javadoc.destinationDir
}


publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId project.group
            artifactId "common"
            version "${version}"
            from components.java
            artifact sourceJar
            artifact javadocJar
            artifact shadowJar
            pom {
                name = "bdware-common"
                description = "common"
                url = "https://gitee.com/BDWare/common"
                licenses {
                    license {
                        name = "Mulan PSL v2"
                        url = "http://license.coscl.org.cn/MulanPSL2"
                    }
                }
                developers {
                    developer {
                        id = "dataware"
                        email = "caihq@pku.edu.cn"
                    }
                }
                scm {
                    connection = "scm:git:https://gitee.com/BDWare/common.git"
                    developerConnection = "scm:git:https://gitee.com/BDWare/common.git"
                    url = "https://gitee.com/BDWare/common"
                }
            }

        }
    }
    repositories {
        maven {
            name 'bdwareSnapshotRepository'
            url 'https://oss.sonatype.org/content/repositories/snapshots'
            credentials {
                username = "${NEXUS_USERNAME}"
                password = "${NEXUS_PASSWORD}"
            }
        }
        maven {
            name 'bdwareRepository'
            url 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
            credentials {
                username = "${NEXUS_USERNAME}"
                password = "${NEXUS_PASSWORD}"
            }
        }
    }
}
signing {
    sign publishing.publications.mavenJava
}