@@ -11,6 +11,7 @@ buildscript {
1111 dependencies {
1212 classpath " gradle.plugin.com.matthewprenger:CurseGradle:1.4.+"
1313 classpath ' org.spongepowered:mixingradle:0.7.+'
14+ classpath " org.tomlj:tomlj:1.1.1"
1415 }
1516}
1617
@@ -25,6 +26,11 @@ apply plugin: 'idea'
2526apply plugin : ' maven-publish'
2627apply plugin : " com.matthewprenger.cursegradle"
2728apply plugin : ' org.spongepowered.mixin'
29+ apply from : ' gradle/template-config.gradle'
30+
31+ def enabledFeatures = project. ext. enabledFeatures
32+ def templateRepositories = project. ext. templateRepositories
33+ def templateDependencies = project. ext. templateDependencies
2834
2935jarJar. enable()
3036
@@ -42,16 +48,6 @@ tasks.matching { it.name == "reobfJar" }.configureEach {
4248 enabled = false
4349}
4450
45- ext. configFile = file(" build.txt" )
46- configFile. withReader {
47- def prop = new Properties ()
48- prop. load(it)
49- project. ext. config = new ConfigSlurper (). parse(prop)
50- project. ext. hasConfig = { key ->
51- return config. isSet(key);
52- }
53- }
54-
5551version = config. mod_version
5652group = config. maven_group
5753base {
@@ -223,21 +219,36 @@ repositories {
223219 url ' https://jitpack.io'
224220 content {
225221 includeGroup " com.github.rtyley"
222+ includeGroup " com.github.llamalad7.mixinextras"
226223 }
227224 }
228225 maven {
229226 name = " Mihono's maven"
230227 url = " https://maven.mihono.cn/repository/pickaid1201/"
231228 }
229+ templateRepositories. custom. each { repoName , repoUrl ->
230+ maven {
231+ name = " project-${ repoName} "
232+ url = repoUrl
233+ }
234+ }
232235 flatDir { dirs " libraries/${ config.mc_version} /all" }
233236 flatDir { dirs " libraries/${ config.mc_version} /classpathOnly" }
234237 flatDir { dirs " libraries/${ config.mc_version} /runtimeOnly" }
235238 flatDir { dirs " libraries/embedded" }
236239}
237240
241+ def createConfiguredDependency = { String notation , boolean transitive ->
242+ project. dependencies. create(notation) {
243+ it. transitive = transitive
244+ }
245+ }
246+
238247dependencies {
239248 minecraft " net.minecraftforge:forge:${ config.mc_version} -${ config.forge_version} "
240- compileOnly(annotationProcessor(" com.github.llamalad7.mixinextras:mixinextras-common:${ config.mixin_extras_version} " ))
249+ if (enabledFeatures. mixin_extras) {
250+ compileOnly(annotationProcessor(" com.github.llamalad7.mixinextras:mixinextras-common:${ config.mixin_extras_version} " ))
251+ }
241252 testAnnotationProcessor sourceSets. main. output
242253 testImplementation platform(" org.junit:junit-bom:5.10.2" )
243254 testImplementation " org.junit.jupiter:junit-jupiter"
@@ -247,24 +258,24 @@ dependencies {
247258 compileOnly fg. deobf(" com.tterrag.registrate:Registrate:${ config.registrate_version} " )
248259 jarJar(group : ' com.tterrag.registrate' , name : ' Registrate' , version : " [MC1.20,MC1.21)" )
249260
250- if (hasConfig( " jei_version " ) && ! config . jei_version . isEmpty() ) {
261+ if (enabledFeatures . jei ) {
251262 compileOnly fg. deobf(" mezz.jei:jei-${ config.mc_version} -common-api:${ config.jei_version} " )
252263 compileOnly fg. deobf(" mezz.jei:jei-${ config.mc_version} -forge-api:${ config.jei_version} " )
253264 runtimeOnly fg. deobf(" mezz.jei:jei-${ config.mc_version} -forge:${ config.jei_version} " )
254265 }
255266
256- if (hasConfig( " geckolib_version " ) && ! config . geckolib_version . isEmpty() ) {
267+ if (enabledFeatures . geckolib ) {
257268 implementation fg. deobf(" software.bernie.geckolib:geckolib-neoforge-${ config.mc_version} :${ config.geckolib_version} " )
258269 implementation(" com.eliotlash.mclib:mclib:20" )
259270 jarJar(group : ' software.bernie.geckolib' , name : " geckolib-neoforge-${ config.mc_version} " , version : " [${ config.geckolib_version} ,)" )
260271 }
261272
262- if (hasConfig( " curios_version " ) && ! config . curios_version . isEmpty() ) {
273+ if (enabledFeatures . curios ) {
263274 compileOnly fg. deobf(" top.theillusivec4.curios:curios-forge:${ config.curios_version} " )
264275// runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${config.curios_version}")
265276 }
266277
267- if (hasConfig( " playeranimator_version " ) && ! config . playeranimator_version . isEmpty() ) {
278+ if (enabledFeatures . player_animator ) {
268279 implementation fg. deobf(" dev.kosmx.player-anim:player-animation-lib-forge:${ config.playeranimator_version} " )
269280 runtimeOnly fg. deobf(" io.github.kosmx.bendy-lib:bendy-lib-forge:${ config.bendylib_version} " )
270281 }
@@ -274,7 +285,7 @@ dependencies {
274285 }
275286
276287 // Mixin extra
277- if (hasConfig( " mixin_extras_version " ) && ! config . mixin_extras_version . isEmpty() ) {
288+ if (enabledFeatures . mixin_extras ) {
278289 implementation fg. deobf(" com.github.llamalad7.mixinextras:mixinextras-forge:${ config.mixin_extras_version} " )
279290 jarJar(group : ' com.github.llamalad7.mixinextras' , name : ' mixinextras-forge' , version : " [${ config.mixin_extras_version} ,)" )
280291 }
@@ -320,10 +331,15 @@ dependencies {
320331 compileOnly fg. deobf(" curse.maven:advanced-hook-launchers-244849:5829843" )
321332 }
322333
323- // KubeJS Integrations.
324- compileOnly fg. deobf(" dev.latvian.mods:kubejs-forge:${ config.kubejs_version} " )
325- compileOnly fg. deobf(" dev.latvian.mods:rhino-forge:${ config.rhino_version} " )
326- implementation fg. deobf(" dev.architectury:architectury-forge:${ config.architectury_version} " )
334+ templateDependencies. each { dependencySpec ->
335+ def baseDependency = createConfiguredDependency(dependencySpec. notation, dependencySpec. transitive)
336+ def resolvedDependency = dependencySpec. deobf ? fg. deobf(baseDependency) : baseDependency
337+ add(dependencySpec. configuration, resolvedDependency)
338+
339+ if (dependencySpec. range) {
340+ jarJar(group : dependencySpec. group, name : dependencySpec. artifact, version : dependencySpec. range)
341+ }
342+ }
327343
328344 def libraries = new File (file(" libraries" ), " ${ config.mc_version} " )
329345 if (! libraries. isDirectory()) libraries. mkdirs()
@@ -397,6 +413,9 @@ def replaceProperties = [
397413 forge_version : " ${ config.mc_version} -${ config.forge_version} " , forge_version_range : config. forge_range,
398414 mod_id : config. mod_id, mod_name : config. mod_name, mod_license : config. mod_license, mod_version : config. mod_version,
399415 mod_authors : config. mod_authors, mod_description : config. mod_description,
416+ jei_version : config. jei_version, curios_version : config. curios_version,
417+ geckolib_version : config. geckolib_version, playeranimator_version : config. playeranimator_version,
418+ citadel_version : hasConfig(" citadel_version" ) ? config. citadel_version : " " ,
400419 modrinth_project : config. modrinth_project,
401420 issue_tracker_url : config. issue_tracker_url, mod_credits : config. mod_credits
402421]
@@ -486,7 +505,7 @@ artifacts {
486505}
487506
488507modrinth {
489- token = System . env. MODRINTH_TOKEN != null ? System . env . MODRINTH_TOKEN : " NONE"
508+ token = System . env. MODRINTH_TOKEN ?: config . modrinth_token ? : " NONE"
490509 projectId = config. modrinth_project
491510 versionNumber = config. mod_version
492511 versionType = config. release_type
@@ -549,7 +568,7 @@ modrinth {
549568}
550569
551570curseforge {
552- apiKey = System . env. CURSEFORGE_TOKEN != null ? System . env . CURSEFORGE_TOKEN : " NONE"
571+ apiKey = System . env. CURSEFORGE_TOKEN ?: config . curseforge_token ? : " NONE"
553572 project {
554573 id = config. cf_project
555574 changelogType = ' html'
@@ -686,8 +705,8 @@ import java.nio.file.Files
686705
687706def incrementBuild = {
688707 if (hasConfig(" formal_version" ) && Boolean . parseBoolean(config. formal_version)) {
689- def buildTxt = configFile. toPath()
690- List<String > lines = Files . readAllLines buildTxt
708+ def configPath = configFile. toPath()
709+ List<String > lines = Files . readAllLines configPath
691710 lines. replaceAll { String ln ->
692711 if (ln. startsWith(" mod_version" )) {
693712 def version = ln. split(" =" )[1 ]
@@ -696,9 +715,17 @@ def incrementBuild = {
696715 def lastOne = Integer . parseInt(version. substring(dot)) + 1
697716 return " mod_version=" + newVersion + lastOne
698717 }
718+ def matcher = (ln =~ / ^(\s *version\s *=\s *")([^"]+)(".*)$/ )
719+ if (matcher. matches()) {
720+ def version = matcher[0 ][2 ]
721+ def dot = version. lastIndexOf(' .' ) + 1
722+ def newVersion = version. substring(0 , dot)
723+ def lastOne = Integer . parseInt(version. substring(dot)) + 1
724+ return matcher[0 ][1 ] + newVersion + lastOne + matcher[0 ][3 ]
725+ }
699726 return ln
700727 }
701- Files . write buildTxt , lines, java.nio.file.StandardOpenOption . CREATE
728+ Files . write configPath , lines, java.nio.file.StandardOpenOption . CREATE
702729 }
703730}
704731
0 commit comments