buildscript {
    repositories {
        jcenter()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'net.minecraftforge.gradle.forge'

version = "1.6.15"
def env = System.getenv()
if (env.BUILD_NUMBER) {
    version = version + "-" + "${env.BUILD_NUMBER}"
}

group = "refinedstorage"
archivesBaseName = "refinedstorage"

sourceCompatibility = 1.8
targetCompatibility = 1.8

minecraft {
    version = "1.12.2-14.23.5.2838"
    runDir = "run"
    useDepAts = true
    mappings = "stable_39"

    replaceIn "RS.java"
    replace "@version@", project.version
}

repositories {
    maven {
        url "http://dvs1.progwml6.com/files/maven"
    }
    maven {
        url "http://maven.cil.li"
    }
    maven {
        name = "CurseForge"
        url = "https://minecraft.curseforge.com/api/maven/"
    }
}

dependencies {
    deobfCompile "mezz.jei:jei_1.12.2:4.15.0.287:api"
    runtime "mezz.jei:jei_1.12.2:4.15.0.287"
    deobfCompile "li.cil.oc:OpenComputers:MC1.12.2-1.7.2.67:api"
    compile "inventory-tweaks:InventoryTweaks:1.63:api"
}

processResources {
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        expand 'version': project.version, 'mcversion': project.minecraft.version
    }

    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
    }
}

jar {
    include "com/raoulvdberge/refinedstorage/**"
    include "assets/**"
    include "mcmod.info"
    include "pack.mcmeta"
}

task deobfJar(type: Jar) {
    from sourceSets.main.output
    classifier 'deobf'
}

task apiJar(type: Jar, dependsOn: 'sourceMainJava') {
    from sourceSets.main.allSource
    from sourceSets.main.output
    include 'com/raoulvdberge/refinedstorage/api/**/*'
    classifier 'api'
}

task signJar(type: SignJar, dependsOn: reobfJar) {
    onlyIf {
        project.hasProperty('keyStore')
    }

    keyStore = project.findProperty('keyStore')
    alias = project.findProperty('keyStoreAlias')
    storePass = project.findProperty('keyStorePass')
    keyPass = project.findProperty('keyStoreKeyPass')
    inputFile = jar.archivePath
    outputFile = jar.archivePath
}

build.dependsOn signJar

artifacts {
    archives deobfJar
    archives apiJar
    archives sourceJar
    archives jar
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = project.group
            artifactId = project.archivesBaseName
            version = project.version
            artifact deobfJar
            artifact sourceJar
            artifact apiJar
            artifact jar
        }
    }
}

publishing {
    repositories {
        maven {
            url "/var/www/repo"
        }
    }
}
