buildscript {
	if ("jcenter".equals(mavenRepo)) {
		repositories {
			jcenter()
		}
	} else if ("mavenCentral".equals(mavenRepo)) {
		repositories {
			mavenCentral()
		}
	} else if ("ali".equals(mavenRepo)) {
		repositories {
			maven {
				url aliRepoUrl
			}
		}
	} else if ("local".equals(mavenRepo)) {
		repositories {
			maven {
				url localPluginRepoUrl
			}
		}
		configurations.all {
			resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
		}
		dependencies {
			classpath "com.beecode:mk-gradle-plugin:1.1.0"
		}
	} else {
		// default
		repositories {
			jcenter()
		}
	}
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.4.RELEASE")
	}
}

ext {
	springVersion            = "4.3.6.RELEASE"
	springBootVersion        = "1.4.4.RELEASE"
	springSecurityVersion    = "4.2.2.RELEASE"
	springSessionVersion     = "1.3.0.RELEASE"
	hibernate5Version        = "5.2.8.Final"
	dom4jVersion             = "2.0.0"
	commonsCompressVersion   = "1.13"
	jacksonVersion           = "2.8.5"
	mozillaRhinoVersion      = "1.7.7.1"
	javatuplesVersion        = "1.2"
	jgitVersion              = "4.6.1.201703071140-r"
	slf4jVersion             = "1.7.22"
	logbackVersion           = "1.1.9"
	junitVersion             = "4.12"
	mockitoVersion           = "1.10.19"
	h2Version                = "1.4.193"
	jsonVersion              = "20160810"

	aminoVersion             = "1.0.+"
	bap2Version              = "1.0.+"
	inzVersion               = "1.0.+"
}

apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'eclipse'

war {
	baseName = 'inz'
}

repositories {
	if ("jcenter".equals(mavenRepo)) {
		jcenter()
	} else if ("mavenCentral".equals(mavenRepo)) {
		mavenCentral()
	} else if ("ali".equals(mavenRepo)) {
		maven {
			url aliRepoUrl
		}
	} else if ("local".equals(mavenRepo)) {
		maven {
			url localRepoUrl
		}
	} else {
		// default
		jcenter()
	}
}

configurations.all {
	resolutionStrategy {
		force "org.hibernate:hibernate-core:${hibernate5Version}"
		force "org.dom4j:dom4j:${dom4jVersion}"
		force "org.apache.commons:commons-compress:${commonsCompressVersion}"
		force "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
		force "org.slf4j:slf4j-api:${slf4jVersion}"
		force "ch.qos.logback:logback-classic:${logbackVersion}"
		force "junit:junit:${junitVersion}"
		force "org.mockito:mockito-core:${mockitoVersion}"
		force "com.h2database:h2:${h2Version}"
		exclude group: "dom4j", module: "dom4j"
	}
}

compileJava.options*.compilerArgs = [
	"-Xlint:serial", "-Xlint:varargs", "-Xlint:cast", "-Xlint:classfile",
	"-Xlint:dep-ann", "-Xlint:divzero", "-Xlint:empty", "-Xlint:finally",
	"-Xlint:overrides", "-Xlint:path", "-Xlint:processing", "-Xlint:static",
	"-Xlint:try", "-Xlint:fallthrough", "-Xlint:rawtypes", "-Xlint:deprecation",
	"-Xlint:unchecked", "-Xlint:-options", "-Werror"
]

compileTestJava.options*.compilerArgs = [
	"-Xlint:serial", "-Xlint:-varargs", "-Xlint:cast", "-Xlint:classfile",
	"-Xlint:dep-ann", "-Xlint:divzero", "-Xlint:empty", "-Xlint:finally",
	"-Xlint:overrides", "-Xlint:path", "-Xlint:processing", "-Xlint:static",
	"-Xlint:try", "-Xlint:-fallthrough", "-Xlint:-rawtypes", "-Xlint:-deprecation",
	"-Xlint:-unchecked", "-Xlint:-options"
]

compileJava {
	sourceCompatibility = 1.8
	targetCompatibility = 1.8
	options.encoding = 'UTF-8'
}

compileTestJava {
	sourceCompatibility = 1.8
	targetCompatibility = 1.8
	options.encoding = 'UTF-8'
	options.compilerArgs += "-parameters"
}

dependencies {
	compile "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
//	compile "org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}"
	compile "org.thymeleaf.extras:thymeleaf-extras-springsecurity4:2.1.+"
	compile "org.springframework.security:spring-security-core:${springSecurityVersion}"
	compile "org.springframework.security:spring-security-config:${springSecurityVersion}"
	compile "org.springframework.security:spring-security-web:${springSecurityVersion}"
	compile "org.hibernate:hibernate-core:${hibernate5Version}"
	compile "mysql:mysql-connector-java:5.1.39"

	compile "org.springframework.boot:spring-boot-starter-data-redis:${springBootVersion}"
	compile "org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}"
	compile "org.springframework.boot:spring-boot-starter-security:${springBootVersion}"
	compile "org.springframework.session:spring-session:${springSessionVersion}"

	compile "com.beecode:amino.boot:${aminoVersion}"
	compile "com.beecode:amino.boot.web:${aminoVersion}"
	compile "com.beecode:amino.shell:${aminoVersion}"
	compile "com.beecode:amino.tenant:${aminoVersion}"
	compile "com.beecode:bcp.store:${aminoVersion}"

	compile "com.beecode:inz.authentication:${inzVersion}"


	providedCompile "org.springframework.boot:spring-boot-starter-tomcat"
}

def projName = name
def projVersion = version
def warPath = war.archivePath.absolutePath
task generateResultInfo() {
	if (outFile != null && !outFile.isEmpty()) {
		doLast {
			def builder = new groovy.xml.StreamingMarkupBuilder()
			builder.encoding = 'UTF-8'
			def resultInfo = {
				mkp.xmlDeclaration()
				it.build {
					it.project(name: projName, version: projVersion) {
						it.artifact(path: warPath)
					}
				}
			}
			def writer = new FileWriter(outFile)
			try {
				writer << builder.bind(resultInfo)
			} finally {
				writer.close()
			}
		}
	}
}
build.dependsOn 'generateResultInfo'