buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "https://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.0-SNAPSHOT'
    }
}

apply plugin: 'idea'
apply plugin: 'forge'
apply plugin: 'scala'
apply plugin: 'maven'
apply plugin: 'maven-publish'

ext.buildProps = file "build.properties"

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

group = "resonantinduction"
archivesBaseName = "${System.getenv().JOB_NAME}"

minecraft {
    version = "${rootProject.config.version.minecraft}-${rootProject.config.version.forge}"

    replaceIn "Reference.java"
    replace "@MAJOR@", rootProject.config.version.mod.major
    replace "@MINOR@", rootProject.config.version.mod.minor
    replace "@REVIS@", rootProject.config.version.mod.revis
    replace "@BUILD@", "${System.getenv().BUILD_NUMBER}"
}

subprojects*.apply plugin: 'java'
subprojects*.apply plugin: 'scala'

allprojects {
    version = "${config.version.mod.major}.${config.version.mod.minor}.${config.version.mod.revis}"

    if (System.getenv("BUILD_NUMBER") != null)
        version += ".${System.getenv("BUILD_NUMBER")}"

    repositories {
        maven {
            name = "tilera"
            url = "https://data.tilera.xyz/maven"
        }
        maven {
            name = "forge"
            url = "https://files.minecraftforge.net/maven"
        }
        ivy {
            name 'FMP'
            artifactPattern "https://files.minecraftforge.net/[module]/[module]-dev-[revision].[ext]"
        }
        maven {
            name "chickenbones"
            url "http://chickenbones.net/maven"
        }
        mavenCentral()
    }

    dependencies {
        compile fileTree(dir: 'lib', include: '*.jar')
        compile "codechicken:CodeChickenLib:${config.version.minecraft}-${config.version.cclib}:dev"
        compile "codechicken:ForgeMultipart:${config.version.minecraft}-${config.version.fmp}:dev"
        compile "codechicken:CodeChickenCore:${config.version.minecraft}-${config.version.cccore}:dev"
        compile "codechicken:NotEnoughItems:${config.version.minecraft}-${config.version.nei}:dev"
        compile "resonant:Universal-Electricity:3.1.0.101:dev"
        compile "resonant:Resonant-Engine:1.2.0:dev"
    }

    jar {
		classifier = project.name
        dependsOn ":copyBuildXml"
        destinationDir = file (rootProject.getRootDir().getPath() + '/output')
    }

	publishing {
		publications {
			mavenJava(MavenPublication) {
				artifact jar
			}
		}
		repositories {
			maven {
				url "file://var/www/maven"
			}
		}
	}
}

subprojects {
    archivesBaseName = "${System.getenv().JOB_NAME}"
	sourceSets.main.compileClasspath += rootProject.sourceSets.api.output
    dependencies {
        compile rootProject
    }

    rootProject.tasks.reobf {
        reobf(tasks.jar) { spec ->
            spec.classpath = sourceSets.main.compileClasspath
        }
    }
}

processResources {
	from 'build.properties'
}

task copyBuildXml(type: Copy) {
    from 'build.properties'
    into 'output'
}

task apiZip(type: Zip) {
    classifier = 'api'
    from sourceSets*.allSource
    include 'resonantinduction/api/**'
    destinationDir = file 'output'
}

artifacts {
    archives apiZip
}

import net.minecraftforge.gradle.tasks.dev.ChangelogTask
import net.minecraftforge.gradle.common.Constants
import net.minecraftforge.gradle.delayed.*

build.dependsOn "apiZip", "copyBuildXml"
