buildscript {
    repositories {
        jcenter()
        maven { url = "http://files.minecraftforge.net/maven" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
		classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.0.9'
    }
}


apply plugin: 'scala'
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'idea'
apply plugin: 'com.matthewprenger.cursegradle'


ext.buildProps = file "build.properties"

buildProps.withReader {
    def prop = new Properties()
    prop.load(it)
    ext.config = new ConfigSlurper().parse prop
}

version = "${config.version.minecraft}-${config.version.mod.major}.${config.version.mod.minor}.${config.version.mod.revis}." + getBuildNumber()
group = "extracells"
archivesBaseName = "ExtraCells"
def actualVersion = version


task outputVersionToFile {
	def versionFile = new File("version.txt")
	versionFile.write("${config.version.mod.major}.${config.version.mod.minor}.${config.version.mod.revis}")
	
	def oldVersion = new File("versionOld.txt")
	if(!oldVersion.exists()) {
		oldVersion.write("0.0.0")
	}
}
//build.dependsOn outputVersionToFile


sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly.
compileJava {
    sourceCompatibility = targetCompatibility = "1.8"
}

logger.lifecycle "$archivesBaseName-$version"
logger.lifecycle "" + version

minecraft {
    version = "${config.version.minecraft}-${config.version.forge}"
    runDir = "../../MinecraftDebug/run_client"
	mappings = "${config.version.mappings}"
	
	replace '@VERSION@', "${config.version.mod.major}.${config.version.mod.minor}.${config.version.mod.revis}"
}
	
repositories {
	maven {
		name 'prog'
		url "https://dvs1.progwml6.com/files/maven"
	}
	
	maven {
        name 'amadornes'
        url "https://maven.amadornes.com/"
    }

	maven  {
		name "BuildCraft Maven"
		url "https://mod-buildcraft.com/maven"
	}

	maven {
		name = "tehnut"
		url = "https://maven.tehnut.info"
	}

	maven {
		name = "CoFH Maven"
		url = "https://maven.covers1624.net"
	}

	maven {
        name = 'IGW'
        url = "https://maven.k-4u.nl/"
    }

    maven {
        name = "CurseForge"
        url = "https://minecraft.curseforge.com/api/maven/"
    }
	
	maven {
		name 'Open Computers'
		url "https://maven.cil.li/"
	}
}

dependencies {
	deobfCompile ("mcp.mobius.waila:Hwyla:${config.version.waila}") {
		transitive = false
	}

	deobfCompile "cofh:RedstoneFlux:${config.version.rf}:universal"
	
	compileOnly ("cofh:CoFHCore:${config.version.cofh}:deobf") {
		transitive = false
	}
	
	deobfCompile ("li.cil.oc:OpenComputers:${config.version.oc}")

	deobfProvided "mezz.jei:jei_${config.version.minecraft}:${config.version.jei}:api"
	runtime "mezz.jei:jei_${config.version.minecraft}:${config.version.jei}"

	deobfProvided "com.mod-buildcraft:buildcraft-api:${config.version.bc}"
	runtime "com.mod-buildcraft:buildcraft:${config.version.bc}"
	
	deobfCompile "igwmod:IGW-Mod-${config.version.minecraft}:${config.version.igw}:universal"

	deobfCompile "mekanism:Mekanism:${config.version.me}"
    deobfCompile "p455w0rd:p455w0rdslib:${config.version.pl}"
    deobfCompile "p455w0rd:AE2WTLib:${config.version.wt}"
	deobfCompile "p455w0rd:WirelessCraftingTerminal:${config.version.wc}"
	
	deobfCompile ("appeng:appliedenergistics2:${config.version.ae}"){
		transitive = false
	}
	
	deobfCompile "MCMultiPart2:MCMultiPart:${config.version.mcmp}"
	deobfCompile "baubles:Baubles:1.12:${config.version.baubles}"
}

processResources {
    from(sourceSets.main.resources.srcDirs) {
        include '**/*.lang'
        include '**/*.info'
        include '**/*.properties'

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

    from(sourceSets.main.resources.srcDirs) {
        include '**/*.lang'
        include '**/*.info'
        include '**/*.properties'

        expand 'version': "${config.version.mod.major}.${config.version.mod.minor}.${config.version.mod.revis}", 'mcversion': project.minecraft.version
    }
}

task apiJar(type: Jar) {
    from sourceSets.main.output
    from sourceSets.main.scala
    from sourceSets.main.java
    classifier = 'api'
	include 'extracells/api/**'
}

if (System.getenv("CURSEFORGE_API_KEY") != null) {
	curseforge {
	  apiKey = System.getenv("CURSEFORGE_API_KEY")
	  project {
		id = config.cf.project.id
		addGameVersion config.version.minecraft
		changelog = file('changelog.txt')
		releaseType = config.cf.project.type
		relations {
			requiredLibrary 'applied-energistics-2'
		}
		addArtifact(apiJar) {
			releaseType = 'alpha'
		}
		mainArtifact(jar) {
			displayName = "$archivesBaseName-${config.version.minecraft}-${config.version.mod.major}.${config.version.mod.minor}.${config.version.mod.revis}"
		}
	  }
	}
}

artifacts {
    archives apiJar
}

def getBuildNumber() {
    if (System.getenv("BUILD_NUMBER") != null) {
        return "${System.getenv("BUILD_NUMBER")}"
    }
    else if (System.getenv("DRONE_BUILD_NUMBER") != null) {
        return "${System.getenv("DRONE_BUILD_NUMBER")}"
    }
	else if (System.getenv("APPVEYOR_BUILD_NUMBER") != null) {
        return "${System.getenv("APPVEYOR_BUILD_NUMBER")}"
    }
    return "NIGHTLY"
}

idea {
    module {
        outputDir = file('build/classes/main')
    }
}
