Skip to content

Instantly share code, notes, and snippets.

@CDAGaming
Created July 7, 2021 20:19
Show Gist options
  • Save CDAGaming/d2e2eaa269c9469646ee768a0b6eb720 to your computer and use it in GitHub Desktop.
Save CDAGaming/d2e2eaa269c9469646ee768a0b6eb720 to your computer and use it in GitHub Desktop.
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url = "https://files.minecraftforge.net/maven" }
maven { url = "https://gitlab.com/EMC-Framework/maven/raw/master/" }
maven { url = "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:5.+"
classpath "com.github.CDAGaming:CurseGradle:master-SNAPSHOT"
classpath "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1"
}
}
apply plugin: "net.minecraftforge.gradle"
apply plugin: "com.matthewprenger.cursegradle"
apply plugin: "org.cadixdev.licenser"
import net.minecraftforge.gradle.common.tasks.SignJar
import org.apache.tools.ant.filters.ReplaceTokens
version = "${versionId}"
group = "com.gitlab.cdagaming"
archivesBaseName = "${archive_name}-${mc_version}-${versionType}"
JavaVersion targetVersion = JavaVersion.VERSION_1_8
allprojects {
sourceCompatibility = targetVersion
targetCompatibility = targetVersion
}
license {
// Exclude JUnixSocket Files
exclude "**/newsclub/**"
exclude "**/maven/com.kohlschutter.junixsocket/**"
exclude "**/jni/**"
// Exclude Non-Parsable Files
exclude "**/*.lang"
exclude "**/*.info"
exclude "**/*.mcmeta"
exclude "**/*.properties"
// Exclude other External Sources
exclude "**/WinRegistry.java"
exclude "**/impl/guava/**"
}
curseforge {
project {
apiKey = System.getenv("CF_APIKEY")
id = "297038"
changelog = file("Changes.md")
changelogType = "markdown"
releaseType = "${versionType}".toLowerCase()
addGameVersion "${mc_version}"
addGameVersion "Forge"
mainArtifact(jar) {
displayName = "${archive_name} v${version} ${versionLabel} (${mc_version})"
}
}
}
minecraft {
mappings channel: 'snapshot', version: "${mc_mappings}"
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 {
craftpresence {
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 {
craftpresence {
source sourceSets.main
}
}
}
}
}
repositories {
maven { url = 'https://sizableshrimp.me/maven' }
}
dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
implementation "com.google.code.findbugs:jsr305:3.0.2"
}
jar {
from sourceSets.main.output
}
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.
if (targetVersion.isJava9Compatible()) {
it.options.release = Integer.parseInt(targetVersion.getMajorVersion())
}
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", "${mc_version}"
// replace stuff in mcmod.info, nothing else
filesMatching("mcmod.info") {
// replace version and mcversion
expand 'version': project.version, 'mcversion': "${mc_version}"
}
}
task signJar(type: SignJar, dependsOn: jar) {
onlyIf {
System.getenv("key_MAINPASS") != null
}
keyStore = "keystore.jks"
alias = System.getenv("key_Alias")
storePass = System.getenv("key_MAINPASS")
keyPass = System.getenv("keyPass")
inputFile = jar.archiveFile
outputFile = jar.archiveFile
}
def copyDir = "$compileJava.temporaryDir/replaced"
task processSource(type: Sync) {
// This will ensure that this task is redone when the properties change.
inputs.property "modName", "${mod_name}"
inputs.property "versionId", "${versionId}"
inputs.property "fingerprint", "${certFingerprint}"
inputs.property "versionType", "${versionType}"
inputs.property "versionLabel", "${versionLabel}"
from sourceSets.main.java
filter(ReplaceTokens, tokens: [
MOD_NAME : mod_name,
VERSION_ID : versionId,
FINGERPRINT : certFingerprint,
VERSION_TYPE : versionType,
VERSION_LABEL: versionLabel
])
into copyDir
}
compileJava {
source = processSource.outputs
}
tasks.build.dependsOn signJar
tasks.curseforge.dependsOn build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment