Skip to content

Commit

Permalink
rework buildscript (part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Apr 3, 2022
1 parent f3c9385 commit 01c75db
Show file tree
Hide file tree
Showing 16 changed files with 426 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ baritone_Client.launch
!/.idea/copyright/profiles_settings.xml

.vscode/launch.json
.architectury-transformer
190 changes: 37 additions & 153 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,175 +16,59 @@
*/

plugins {
id 'java'
id 'dev.architectury.loom' version '0.10.0-SNAPSHOT'
id 'maven-publish'
id "architectury-plugin" version "3.4-SNAPSHOT"
id 'dev.architectury.loom' version '0.11.0-SNAPSHOT' apply false
}


archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

import baritone.gradle.task.CreateDistTask
import baritone.gradle.task.ProguardTask

def compileType = project.hasProperty("baritone.fabric_build") ? "FABRIC" : project.hasProperty("baritone.forge_build") ? "FORGE" : "OFFICIAL"

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_16

compileJava {
options.encoding = "UTF-8" // allow emoji in comments :^)
}

sourceSets {
api {
compileClasspath += main.compileClasspath
}
main {
compileClasspath += api.output
}
test {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
launch {
compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output
runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output
}
schematica_api {
compileClasspath += main.compileClasspath
}
main {
compileClasspath += schematica_api.output
}
architectury {
minecraft = rootProject.minecraft_version
}

loom {
if (compileType.equals("FORGE")) {
forge {
mixinConfig 'mixins.baritone.json'
}
}
mixin.defaultRefmapName = "mixins.baritone.refmap.json"
subprojects {
apply plugin: 'java'
apply plugin: "maven-publish"
apply plugin: "dev.architectury.loom"

runs {
client {
source = sourceSets.launch
}
}
}
archivesBaseName = rootProject.archives_base_name
version = rootProject.mod_version
group = rootProject.maven_group

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_16

repositories {
maven {
name = 'impactdevelopment-repo'
url = 'https://impactdevelopment.github.io/maven/'
loom {
silentMojangMappingsLicense()
}
maven {
name = "ldtteam"
url = "https://maven.parchmentmc.net/"
}
mavenCentral()
}

dependencies {
if (compileType.equals("FORGE")) {
forge "net.minecraftforge:forge:${project.forge_version}"
}
mappings loom.layered() {
officialMojangMappings()
//technically optional, but really helpful in dev:
parchment("org.parchmentmc.data:parchment-1.17.1:2021.10.24@zip" as String)
dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well
mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
// mappings "net.fabricmc:yarn:1.17.1+build.32:v2"
}
minecraft "com.mojang:minecraft:${project.minecraft_version}"
if (!compileType.equals("FORGE")) {
modImplementation "net.fabricmc:fabric-loader:${project.fabric_version}"
}
// this makes it compile with the forge tweak stuff
implementation 'com.github.ImpactDevelopment:SimpleTweaker:1.2'
implementation('net.minecraft:launchwrapper:1.12') {
exclude module: 'lwjgl'
exclude module: 'asm-debug-all'
}

implementation 'com.google.code.findbugs:jsr305:3.0.2'

testImplementation 'junit:junit:4.12'
}

javadoc {
options.addStringOption('Xwerror', '-quiet') // makes the build fail on travis when there is a javadoc error
options.linkSource true
options.encoding "UTF-8" // allow emoji in comments :^)
source = sourceSets.api.allJava
classpath += sourceSets.api.compileClasspath
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"

// skidded from fabric-example-mod (comments and all)
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"

// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used.
// We'll use that if it's available, but otherwise we'll use the older option.
def targetVersion = 16
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
def targetVersion = 16
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
}
}
}

allprojects {
apply plugin: "architectury-plugin"

jar {
from sourceSets.launch.output, sourceSets.api.output

if (!getProject().hasProperty("baritone.forge_build")) {
exclude "**/BaritoneForgeModXD.class"
exclude "**/mods.toml"
}

preserveFileTimestamps = false
reproducibleFileOrder = true

if (getProject().hasProperty("baritone.fabric_build")) {
filesMatching("fabric.mod.json") {
expand "version": version
repositories {
maven {
name = 'impactdevelopment-repo'
url = 'https://impactdevelopment.github.io/maven/'
}
} else {
exclude("fabric.mod.json")
}


manifest {
attributes(
'MixinConfigs': 'mixins.baritone.json',
"MixinConnector": "baritone.launch.BaritoneMixinConnector",

'Implementation-Title': 'Baritone',
'Implementation-Version': version,
)
}
}

if (compileType.equals("OFFICIAL")) {
remapJar {
toM.set "official"
maven {
name = "ldtteam"
url = "https://maven.parchmentmc.net/"
}
mavenCentral()
}
}



task proguard(type: ProguardTask) {
url 'https://downloads.sourceforge.net/project/proguard/v7.1.0-beta5/proguard-7.1.0-beta5.zip'
extract 'proguard-7.1.0-beta5/lib/proguard.jar'
compType compileType
}

task createDist(type: CreateDistTask, dependsOn: proguard)


build.finalizedBy(createDist)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package baritone.gradle.task;

import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.Input;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -59,7 +60,7 @@ class BaritoneGradleTask extends DefaultTask {
proguardOut;

public BaritoneGradleTask() {
this.artifactName = getProject().getName();
this.artifactName = getProject().getProperties().get("archivesBaseName").toString();
this.artifactVersion = getProject().getVersion().toString();

this.artifactPath = this.getBuildFile(formatVersion(ARTIFACT_STANDARD));
Expand Down Expand Up @@ -102,6 +103,10 @@ protected Path getRelativeFile(String file) {
return Paths.get(new File(new File(getProject().getBuildDir(), "../"), file).getAbsolutePath());
}

protected Path getRootRelativeFile(String file) {
return Paths.get(new File(new File(getProject().getRootProject().getBuildDir(), "../"), file).getAbsolutePath());
}

protected Path getTemporaryFile(String file) {
return Paths.get(new File(getTemporaryDir(), file).getAbsolutePath());
}
Expand Down
28 changes: 14 additions & 14 deletions buildSrc/src/main/java/baritone/gradle/task/CreateDistTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ protected void exec() throws Exception {
super.verifyArtifacts();

// Define the distribution file paths
Path api = getRelativeFile("dist/" + getFileName(artifactApiPath));
Path standalone = getRelativeFile("dist/" + getFileName(artifactStandalonePath));
Path unoptimized = getRelativeFile("dist/" + getFileName(artifactUnoptimizedPath));
Path api = getRootRelativeFile("dist/" + getFileName(artifactApiPath));
Path standalone = getRootRelativeFile("dist/" + getFileName(artifactStandalonePath));
Path unoptimized = getRootRelativeFile("dist/" + getFileName(artifactUnoptimizedPath));

// NIO will not automatically create directories
Path dir = getRelativeFile("dist/");
Path dir = getRootRelativeFile("dist/");
if (!Files.exists(dir)) {
Files.createDirectory(dir);
}
Expand All @@ -67,7 +67,7 @@ protected void exec() throws Exception {
shasum.forEach(System.out::println);

// Write the checksums to a file
Files.write(getRelativeFile("dist/checksums.txt"), shasum);
Files.write(getRootRelativeFile("dist/checksums.txt"), shasum);
}

private static String getFileName(Path p) {
Expand All @@ -76,15 +76,15 @@ private static String getFileName(Path p) {

private List<Path> getAllDistJars() {
return Arrays.asList(
getRelativeFile("dist/" + formatVersion(ARTIFACT_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_UNOPTIMIZED)),
getRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED))
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_API)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_API)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_API)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_STANDALONE)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_STANDALONE)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_STANDALONE)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_UNOPTIMIZED)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FABRIC_UNOPTIMIZED)),
getRootRelativeFile("dist/" + formatVersion(ARTIFACT_FORGE_UNOPTIMIZED))
);
}

Expand Down
16 changes: 6 additions & 10 deletions buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ protected void exec() throws Exception {
}

private boolean isMcJar(File f) {
return f.getName().startsWith(compType.equals("FORGE") ? "forge-" : "minecraft-") && f.getName().contains("minecraft-mapped");
return f.getName().startsWith(compType.equals("FORGE") ? "forge-" : "minecraft-") && f.getName().contains("minecraft-merged-named");
}

private void copyMcJar() throws IOException {
File mcClientJar = this.getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
File mcClientJar = this.getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("main").getRuntimeClasspath().getFiles()
.stream()
.filter(this::isMcJar)
.map(f -> {
switch (compType) {
case "OFFICIAL":
return new File(f.getParentFile().getParentFile(), "minecraft-merged.jar");
case "FABRIC":
return new File(f.getParentFile(), "minecraft-intermediary.jar");
return new File(f.getParentFile().getParentFile(), "minecraft-merged-intermediary.jar");
case "FORGE":
return new File(f.getParentFile(), "minecraft-srg.jar");
return new File(f.getParentFile().getParentFile(), f.getName().replace("-named.jar", "-srg.jar"));
}
return null;
})
Expand Down Expand Up @@ -233,7 +233,7 @@ private boolean validateJavaVersion(String java) {
}

private void generateConfigs() throws Exception {
Files.copy(getRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING);
Files.copy(getRootRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING);

// Setup the template that will be used to derive the API and Standalone configs
List<String> template = Files.readAllLines(getTemporaryFile(PROGUARD_CONFIG_DEST));
Expand Down Expand Up @@ -268,12 +268,8 @@ private void generateConfigs() throws Exception {
Files.write(getTemporaryFile(PROGUARD_STANDALONE_CONFIG), standalone);
}

private File getSrgMcJar() {
return getProject().getTasks().findByName("copyMcJar").getOutputs().getFiles().getSingleFile();
}

private Stream<File> acquireDependencies() {
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("launch").getRuntimeClasspath().getFiles()
return getProject().getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().findByName("main").getRuntimeClasspath().getFiles()
.stream()
.filter(File::isFile);
}
Expand Down
Loading

0 comments on commit 01c75db

Please sign in to comment.