Skip to content

Commit 82588dc

Browse files
committed
update buildscript
1 parent 76339db commit 82588dc

File tree

2 files changed

+69
-20
lines changed

2 files changed

+69
-20
lines changed

build.gradle

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//version: 1656003793falsepattern67
1+
//version: 1656003793falsepattern70
22
/*
33
DO NOT CHANGE THIS FILE!
44
@@ -132,6 +132,8 @@ propertyDefaultIfUnset("mixinConfigs", "")
132132
propertyDefaultIfUnset("mixinPluginPreInit", "")
133133
propertyDefaultIfUnset("mixinPluginMinimumVersion", "0.8.5")
134134
propertyDefaultIfUnset("remapStubs", false)
135+
propertyDefaultIfUnset("apiPackages", null)
136+
propertyDefaultIfUnset("apiPackagesNoRecurse", null)
135137

136138
propertyDefaultIfUnset("modrinthProjectId", "")
137139
propertyDefaultIfUnset("modrinthDependencies", "")
@@ -147,20 +149,31 @@ String javaSourceDir = "src/main/java/"
147149
String scalaSourceDir = "src/main/scala/"
148150
String kotlinSourceDir = "src/main/kotlin/"
149151

150-
String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/")
151-
String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/")
152-
String targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/")
153-
if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
154-
throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
152+
def verifyPackage(thePackage, propName) {
153+
String javaSourceDir = "src/main/java/"
154+
String scalaSourceDir = "src/main/scala/"
155+
String kotlinSourceDir = "src/main/kotlin/"
156+
String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + thePackage.toString().replaceAll("\\.", "/")
157+
String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + thePackage.toString().replaceAll("\\.", "/")
158+
String targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + thePackage.toString().replaceAll("\\.", "/")
159+
if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
160+
throw new GradleException("Could not resolve \"${propName}\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
161+
}
155162
}
156163

164+
verifyPackage("", "modGroup")
165+
157166
if(apiPackage) {
158-
targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
159-
targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
160-
targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
161-
if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
162-
throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
163-
}
167+
verifyPackage(apiPackage, "apiPackage")
168+
}
169+
170+
171+
if (apiPackages) {
172+
apiPackages.tokenize(';').forEach { it -> verifyPackage(it, "apiPackages")}
173+
}
174+
175+
if (apiPackagesNoRecurse) {
176+
apiPackagesNoRecurse.tokenize(';').forEach { it -> verifyPackage(it, "apiPackagesNoRecurse")}
164177
}
165178

166179
if(accessTransformersFile) {
@@ -175,9 +188,9 @@ if(usesMixins.toBoolean()) {
175188
throw new GradleException("\"usesMixins\" requires \"mixinsPackage\" to be set!")
176189
}
177190

178-
targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
179-
targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
180-
targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
191+
String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
192+
String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
193+
String targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
181194
if(!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
182195
throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
183196
}
@@ -281,6 +294,10 @@ if(file("addon.gradle").exists()) {
281294

282295
apply from: 'repositories.gradle'
283296

297+
if(file('repositories_override.gradle').exists()) {
298+
apply from: 'repositories_override.gradle'
299+
}
300+
284301
configurations {
285302
for (config in [shadowImplementation, shadowCompile, shadeCompile]) {
286303
implementation.extendsFrom(shadeCompile)
@@ -335,6 +352,10 @@ dependencies {
335352

336353
apply from: 'dependencies.gradle'
337354

355+
if(file('dependencies_override.gradle').exists()) {
356+
apply from: 'dependencies_override.gradle'
357+
}
358+
338359
def mixinDir = new File(project.buildDir, 'mixins')
339360
if (!mixinDir.exists()) {
340361
mixinDir.mkdirs()
@@ -602,11 +623,29 @@ task devJar(type: Jar) {
602623

603624
task apiJar(type: Jar) {
604625
from (sourceSets.main.allSource) {
605-
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
626+
if (apiPackage)
627+
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
628+
if (apiPackages)
629+
apiPackages.tokenize(';').forEach { pkg ->
630+
include modGroup.toString().replaceAll("\\.", "/") + "/" + pkg.toString().replaceAll("\\.", "/") + '/**'
631+
}
632+
if (apiPackagesNoRecurse)
633+
apiPackagesNoRecurse.tokenize(';').forEach { pkg ->
634+
include modGroup.toString().replaceAll("\\.", "/") + "/" + pkg.toString().replaceAll("\\.", "/") + '/*'
635+
}
606636
}
607637

608638
from (sourceSets.main.output) {
609-
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
639+
if (apiPackage)
640+
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
641+
if (apiPackages)
642+
apiPackages.tokenize(';').forEach { pkg ->
643+
include modGroup.toString().replaceAll("\\.", "/") + "/" + pkg.toString().replaceAll("\\.", "/") + '/**'
644+
}
645+
if (apiPackagesNoRecurse)
646+
apiPackagesNoRecurse.tokenize(';').forEach { pkg ->
647+
include modGroup.toString().replaceAll("\\.", "/") + "/" + pkg.toString().replaceAll("\\.", "/") + '/*'
648+
}
610649
}
611650

612651
from (sourceSets.main.resources.srcDirs) {
@@ -627,7 +666,7 @@ compileJava.dependsOn(copySrgs)
627666
artifacts {
628667
archives sourcesJar
629668
archives devJar
630-
if(apiPackage) {
669+
if(apiPackage || apiPackages || apiPackagesNoRecurse) {
631670
archives apiJar
632671
}
633672
}
@@ -683,7 +722,7 @@ publishing {
683722
artifact source: sourcesJar, classifier: "sources"
684723
}
685724
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
686-
if (apiPackage) {
725+
if (apiPackage || apiPackages || apiPackagesNoRecurse) {
687726
artifact source: apiJar, classifier: "api"
688727
}
689728

gradle.properties

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,19 @@ modGroup = com.falsepattern.lib
1111

1212
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
1313
# leave this property empty.
14-
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
14+
# Example value: apiPackage = api
15+
# ... api + (modGroup -> com.myname.mymodid) -> com.myname.mymodid.api
1516
apiPackage =
1617

18+
# Same thing, but for multi-poackage APIs, if said API packages cannot be easily split from internals.
19+
# Packages separated by semicolons
20+
# ExampleValue: apiPackages = foo;bar;baz
21+
# ... foo;bar;baz -> com.myname.mymodid.foo;com.myname.mymodid.bar;com.myname.mymodid.baz
22+
apiPackages = asm;compat;config;dependencies;mapping;mixin;text;toasts;util
23+
24+
# Same as apiPackages, but does not pull in inner packages
25+
apiPackagesNoRecurse = .
26+
1727
# WHY is there no version field?
1828
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
1929
# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/

0 commit comments

Comments
 (0)