Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

Commit 5423d96

Browse files
authored
update build script (#4)
1 parent cfd00f3 commit 5423d96

File tree

3 files changed

+138
-28
lines changed

3 files changed

+138
-28
lines changed

build.gradle

Lines changed: 130 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//version: 1642464427
1+
//version: 1643020202
22
/*
33
DO NOT CHANGE THIS FILE!
44
@@ -32,16 +32,18 @@ buildscript {
3232
}
3333
}
3434
dependencies {
35-
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.5'
35+
classpath 'com.github.GTNewHorizons:ForgeGradle:1.2.7'
3636
}
3737
}
3838

3939
plugins {
4040
id 'idea'
41+
id 'eclipse'
4142
id 'scala'
4243
id("org.ajoberstar.grgit") version("3.1.1")
4344
id("com.github.johnrengelman.shadow") version("4.0.4")
4445
id("com.palantir.git-version") version("0.12.3")
46+
id('de.undercouch.download') version('4.1.2')
4547
id("maven-publish")
4648
}
4749

@@ -88,6 +90,7 @@ checkPropertyExists("containsMixinsAndOrCoreModOnly")
8890
checkPropertyExists("usesShadowedDependencies")
8991
checkPropertyExists("developmentEnvironmentUserName")
9092

93+
boolean noPublishedSources = project.findProperty("noPublishedSources") ? project.noPublishedSources.toBoolean() : false
9194

9295
String javaSourceDir = "src/main/java/"
9396
String scalaSourceDir = "src/main/scala/"
@@ -171,6 +174,19 @@ else {
171174
archivesBaseName = modId
172175
}
173176

177+
178+
def arguments = []
179+
def jvmArguments = []
180+
181+
if(usesMixins.toBoolean()) {
182+
arguments += [
183+
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
184+
]
185+
jvmArguments += [
186+
"-Dmixin.debug.countInjections=true", "-Dmixin.debug.verbose=true", "-Dmixin.debug.export=true"
187+
]
188+
}
189+
174190
minecraft {
175191
version = minecraftVersion + "-" + forgeVersion + "-" + minecraftVersion
176192
runDir = "run"
@@ -190,6 +206,20 @@ minecraft {
190206
replace gradleTokenGroupName, modGroup
191207
}
192208
}
209+
210+
clientIntellijRun {
211+
args(arguments)
212+
jvmArgs(jvmArguments)
213+
214+
if(developmentEnvironmentUserName) {
215+
args("--username", developmentEnvironmentUserName)
216+
}
217+
}
218+
219+
serverIntellijRun {
220+
args(arguments)
221+
jvmArgs(jvmArguments)
222+
}
193223
}
194224

195225
if(file("addon.gradle").exists()) {
@@ -321,15 +351,6 @@ afterEvaluate {
321351
}
322352

323353
runClient {
324-
def arguments = []
325-
326-
if(usesMixins.toBoolean()) {
327-
arguments += [
328-
"--mods=../build/libs/$modId-${version}.jar",
329-
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
330-
]
331-
}
332-
333354
if(developmentEnvironmentUserName) {
334355
arguments += [
335356
"--username",
@@ -338,19 +359,12 @@ runClient {
338359
}
339360

340361
args(arguments)
362+
jvmArgs(jvmArguments)
341363
}
342364

343365
runServer {
344-
def arguments = []
345-
346-
if (usesMixins.toBoolean()) {
347-
arguments += [
348-
"--mods=../build/libs/$modId-${version}.jar",
349-
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
350-
]
351-
}
352-
353366
args(arguments)
367+
jvmArgs(jvmArguments)
354368
}
355369

356370
tasks.withType(JavaExec).configureEach {
@@ -484,20 +498,34 @@ task apiJar(type: Jar) {
484498
}
485499

486500
artifacts {
487-
archives sourcesJar
501+
if(!noPublishedSources) {
502+
archives sourcesJar
503+
}
488504
archives devJar
489505
if(apiPackage) {
490506
archives apiJar
491507
}
492508
}
493509

510+
// The gradle metadata includes all of the additional deps that we disabled from POM generation (including forgeBin with no groupID),
511+
// and isn't strictly needed with the POM so just disable it.
512+
tasks.withType(GenerateModuleMetadata) {
513+
enabled = false
514+
}
515+
516+
494517
// publishing
495518
publishing {
496519
publications {
497520
maven(MavenPublication) {
498-
artifact source: jar
499-
artifact source: sourcesJar, classifier: "src"
500-
artifact source: devJar, classifier: "dev"
521+
from components.java
522+
if(usesShadowedDependencies.toBoolean()) {
523+
artifact source: shadowJar, classifier: ""
524+
}
525+
if(!noPublishedSources) {
526+
artifact source: sourcesJar, classifier: "src"
527+
}
528+
artifact source: usesShadowedDependencies.toBoolean() ? shadowDevJar : devJar, classifier: "dev"
501529
if (apiPackage) {
502530
artifact source: apiJar, classifier: "api"
503531
}
@@ -506,6 +534,18 @@ publishing {
506534
artifactId = System.getenv("ARTIFACT_ID") ?: project.name
507535
// Using the identified version, not project.version as it has the prepended 1.7.10
508536
version = System.getenv("RELEASE_VERSION") ?: identifiedVersion
537+
538+
// Remove all non GTNH deps here.
539+
// Original intention was to remove an invalid forgeBin being generated without a groupId (mandatory), but
540+
// it also removes all of the MC deps
541+
pom.withXml {
542+
Node pomNode = asNode()
543+
pomNode.dependencies.'*'.findAll() {
544+
it.groupId.text() != 'com.github.GTNewHorizons'
545+
}.each() {
546+
it.parent().remove(it)
547+
}
548+
}
509549
}
510550
}
511551

@@ -576,6 +616,72 @@ configure(updateBuildScript) {
576616
description = 'Updates the build script to the latest version'
577617
}
578618

619+
// Deobfuscation
620+
621+
def deobf(String sourceURL) {
622+
try {
623+
URL url = new URL(sourceURL)
624+
String fileName = url.getFile()
625+
626+
//get rid of directories:
627+
int lastSlash = fileName.lastIndexOf("/")
628+
if(lastSlash > 0) {
629+
fileName = fileName.substring(lastSlash + 1)
630+
}
631+
//get rid of extension:
632+
if(fileName.endsWith(".jar")) {
633+
fileName = fileName.substring(0, fileName.lastIndexOf("."))
634+
}
635+
636+
String hostName = url.getHost()
637+
if(hostName.startsWith("www.")) {
638+
hostName = hostName.substring(4)
639+
}
640+
List parts = Arrays.asList(hostName.split("\\."))
641+
Collections.reverse(parts)
642+
hostName = String.join(".", parts)
643+
644+
return deobf(sourceURL, hostName + "/" + fileName)
645+
} catch(Exception e) {
646+
return deobf(sourceURL, "deobf/" + String.valueOf(sourceURL.hashCode()))
647+
}
648+
}
649+
650+
// The method above is to be prefered. Use this method if the filename is not at the end of the URL.
651+
def deobf(String sourceURL, String fileName) {
652+
String cacheDir = System.getProperty("user.home") + "/.gradle/caches/"
653+
String bon2Dir = cacheDir + "forge_gradle/deobf"
654+
String bon2File = bon2Dir + "/BON2-2.5.0.jar"
655+
String obfFile = cacheDir + "modules-2/files-2.1/" + fileName + ".jar"
656+
String deobfFile = cacheDir + "modules-2/files-2.1/" + fileName + "-deobf.jar"
657+
658+
if(file(deobfFile).exists()) {
659+
return files(deobfFile)
660+
}
661+
662+
download {
663+
src 'https://github.com/GTNewHorizons/BON2/releases/download/2.5.0/BON2-2.5.0.CUSTOM-all.jar'
664+
dest bon2File
665+
quiet true
666+
overwrite false
667+
}
668+
669+
download {
670+
src sourceURL
671+
dest obfFile
672+
quiet true
673+
overwrite false
674+
}
675+
676+
exec {
677+
commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', '1.7.10', '--mappingsVer', 'stable_12', '--notch'
678+
workingDir bon2Dir
679+
standardOutput = new ByteArrayOutputStream()
680+
}
681+
682+
return files(deobfFile)
683+
}
684+
579685
// Helper methods
580686

581687
def checkPropertyExists(String propertyName) {

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ autoUpdateBuildScript = false
1515
minecraftVersion = 1.7.10
1616
forgeVersion = 10.13.4.1614
1717

18-
# Select a username for testing your mod with breakpoints. You may leave this empty for a random user name each time you
18+
# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
1919
# restart Minecraft in development. Choose this dependent on your mod:
2020
# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
2121
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
2222
developmentEnvironmentUserName = Developer
2323

2424
# Define a source file of your project with:
2525
# public static final String VERSION = "GRADLETOKEN_VERSION";
26-
# The string's content will be replaced with your mods version when compiled. You should use this to specify your mod's
26+
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
2727
# version in @Mod([...], version = VERSION, [...])
2828
# Leave these properties empty to skip individual token replacements
2929
replaceGradleTokenInFile =
@@ -37,7 +37,7 @@ gradleTokenGroupName =
3737
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
3838
apiPackage =
3939

40-
# Specify the configuration file for Forge's access transformers here. I must be placed into /src/main/resources/META-INF/
40+
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
4141
# Example value: mymodid_at.cfg
4242
accessTransformersFile =
4343

@@ -48,7 +48,7 @@ mixinPlugin =
4848
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
4949
mixinsPackage =
5050
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
51-
# This parameter is for legacy compatability only
51+
# This parameter is for legacy compatibility only
5252
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
5353
coreModClass =
5454
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class

repositories.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Add any additional repositiroes for your dependencies here
22

33
repositories {
4+
maven {
5+
name = "GTNH Maven"
6+
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
7+
}
48

59
}

0 commit comments

Comments
 (0)