Skip to content

Commit

Permalink
build.gradle modernizations
Browse files Browse the repository at this point in the history
  • Loading branch information
williewillus committed Jul 4, 2022
1 parent 1352d4e commit f90ed7e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 87 deletions.
87 changes: 11 additions & 76 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
Expand All @@ -12,59 +11,36 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

ext.configFile = file('build.properties')
ext.config = parseConfig(configFile)

version = "${config.version}-${config.build_number}"
group = "vazkii.${config.mod_id}" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = config.mod_name
version = "${project.version}-${project.build_number}"
group = "vazkii.${project.mod_id}"
archivesBaseName = project.mod_name

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

compileJava.options.compilerArgs << "-Xlint:all,-classfile,-processing,-serial" << "-Werror"

minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.

mappings channel: "${config.mapping_channel}", version: "${config.mapping_version}"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.

mappings channel: "official", version: "${project.mc_version}"
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
neat {
source sourceSets.main
}
}
}

server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'

// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'

mods {
examplemod {
neat {
source sourceSets.main
}
}
Expand All @@ -73,68 +49,27 @@ minecraft {
}

dependencies {
minecraft "net.minecraftforge:forge:${config.mc_version}-${config.forge_version}"
minecraft "net.minecraftforge:forge:${project.mc_version}-${project.forge_version}"
}

processResources {
// replace stuff in mcmod.info, nothing else
filesMatching('META-INF/mods.toml') {

// replace version and mcversion
expand 'version': project.version
}
}

task incrementBuildNumber {
doFirst {
config.build_number = (config.build_number.toString().toInteger()) + 1
configFile.withWriter {
config.toProperties().store(it, "")
}
}
}

import java.util.regex.Pattern
task sortArtifacts(type: Copy) {
from jar.destinationDir
into config.dir_output
//Put each jar with a classifier in a subfolder with the classifier as its name
eachFile {
//This matcher is used to get the classifier of the jar
def matcher = Pattern.compile(Pattern.quote("$config.mod_name-$version") + "-(?<classifier>\\w+).jar").matcher(it.name)
//Only change the destination for full matches, i.e jars with classifiers
if (matcher.matches()) {
def classifier = matcher.group('classifier')
/* Set the relative path to change the destination, since
* Gradle doesn't seem to like the absolute path being set*/
it.relativePath = it.relativePath.parent.append(false, classifier, it.name)
}
}
}

def parseConfig(File config) {
config.withReader {
def prop = new Properties()
prop.load(it)
return (new ConfigSlurper().parse(prop))
}
}

jar {
//rename the default output, for some better... sanity with scipts
archiveName = "${baseName} ${version}.${extension}"

manifest {
attributes([
"Specification-Title": "${config.mod_id}",
"Specification-Title": "${project.mod_id}",
"Specification-Vendor": "vazkii",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": "${config.mod_id}",
"Implementation-Version": "${version}",
"Implementation-Title": "${project.mod_id}",
"Implementation-Version": "${project.version}",
"Implementation-Vendor" :"vazkii",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}

defaultTasks 'clean', 'build', 'sortArtifacts', 'incrementBuildNumber'
defaultTasks 'clean', 'build'
11 changes: 0 additions & 11 deletions build.properties

This file was deleted.

15 changes: 15 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Done to increase the memory available to gradle.
# add-exports are needed for spotless to work on new Javas
org.gradle.jvmargs=-Xmx1G \
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

forge_version=39.0.9
mod_id=neat
build_number=31
version=1.8
mod_name=Neat
mc_version=1.18.1

0 comments on commit f90ed7e

Please sign in to comment.