plugins {
	id 'maven-publish'
	id 'com.github.hierynomus.license' version '0.16.1' apply false
	id 'fabric-loom' version '1.11-SNAPSHOT' apply false

	// https://github.com/ReplayMod/preprocessor
	// https://github.com/Fallen-Breath/preprocessor
	id 'com.replaymod.preprocess' version 'd452ef7612'

	// https://github.com/Fallen-Breath/yamlang
	id 'me.fallenbreath.yamlang' version '1.5.0' apply false
}

preprocess {
	strictExtraMappings = false

	def mc114  = createNode('1.14.4', 1_14_04, '')
	def mc115  = createNode('1.15.2', 1_15_02, '')
	def mc116  = createNode('1.16.5', 1_16_05, '')
	def mc117  = createNode('1.17.1', 1_17_01, '')
	def mc118  = createNode('1.18.2', 1_18_02, '')
	def mc119  = createNode('1.19.4', 1_19_04, '')
	def mc1204 = createNode('1.20.4', 1_20_04, '')
	def mc1206 = createNode('1.20.6', 1_20_06, '')
	def mc1211 = createNode('1.21.1', 1_21_01, '')
	def mc1213 = createNode('1.21.3', 1_21_03, '')
	def mc1214 = createNode('1.21.4', 1_21_04, '')
	def mc1215 = createNode('1.21.5', 1_21_05, '')
	def mc1218 = createNode('1.21.8', 1_21_08, '')
	def mc12110 = createNode('1.21.10', 1_21_10, '')

	mc115 .link(mc114 , null)
	mc115 .link(mc116 , null)
	mc116 .link(mc117 , null)
	mc117 .link(mc118 , null)
	mc118 .link(mc119 , null)
	mc119 .link(mc1204, null)
	mc1204.link(mc1206, null)
	mc1206.link(mc1211, null)
	mc1211.link(mc1213, null)
	mc1213.link(mc1214, null)
	mc1214.link(mc1215, null)
	mc1215.link(mc1218, null)
	mc1218.link(mc12110, null)
}

tasks.register('buildAndGather') {
	subprojects {
		dependsOn project.tasks.named('build').get()
	}
	doFirst {
		println 'Gathering builds'
		def buildLibs = {
			p -> p.buildDir.toPath().resolve('libs')
		}
		delete fileTree(buildLibs(rootProject)) {
			include '*'
		}
		subprojects {
			copy {
				from(buildLibs(project)) {
					include '*.jar'
					exclude '*-dev.jar', '*-sources.jar', '*-shadow.jar'
				}
				into buildLibs(rootProject)
				duplicatesStrategy = DuplicatesStrategy.INCLUDE
			}
		}
	}
}
