Skip to content

Commit

Permalink
build: new gradle build scripts
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
WakelessSloth56 committed Aug 15, 2022
1 parent 8c46e3b commit a8fcfec
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 104 deletions.
111 changes: 7 additions & 104 deletions build.gradle
Expand Up @@ -13,13 +13,14 @@ buildscript {
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'signing'
apply plugin: 'maven-publish'
apply plugin: 'org.spongepowered.mixin'


group = 'org.auioc.mcmod'
archivesBaseName = "arnicalib"
version = "${minecraft_version}-${arnicalib_version}"
project.ext.modVersion= "${arnicalib_version}"
apply from: 'gradle/version.gradle'

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

Expand Down Expand Up @@ -70,107 +71,9 @@ mixin {
add sourceSets.main, 'arnicalib.mixin-refmap.json'
}

ext {
manifest_attributes = [
"Specification-Title": 'arnicalib',
"Specification-Vendor": 'AUIOC',
"Specification-Version": '1',
"Implementation-Title": project.name,
"Implementation-Version": "${arnicalib_version}",
"Implementation-Vendor" :'AUIOC',
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"TweakClass": 'org.spongepowered.asm.launch.MixinTweaker',
"TweakOrder": 0,
"MixinConfigs": 'arnicalib.mixin.json',
"ArnicaLib-Version": "${archivesBaseName}-${version}-${getVar('CI_VERSION')}"
]
}

jar {
manifest {attributes(manifest_attributes)}
}
jar.finalizedBy('reobfJar')
apply from: 'gradle/tasks.gradle'

task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
manifest {attributes(manifest_attributes)}
}
task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
classifier = 'sources'
manifest {attributes(manifest_attributes)}
}
task forgelibJar(type: Jar) {
from sourceSets.main.output
from sourceSets.main.allJava
classifier = 'forgelib'
manifest {attributes(manifest_attributes)}
}
artifacts {
archives sourcesJar
archives deobfJar
archives forgelibJar
}
apply from: 'gradle/artifacts.gradle'
apply from: 'gradle/publishing.gradle'
apply from: 'gradle/signing.gradle'

tasks.build.dependsOn('sourcesJar', 'deobfJar', 'forgelibJar')

publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
artifact jar
artifact deobfJar {
classifier 'deobf'
}
artifact sourcesJar {
classifier 'sources'
}
artifact forgelibJar {
classifier 'forgelib'
}
}
}
repositories {
maven {
name = 'GitHubPackages'
url = uri('https://maven.pkg.github.com/auioc/arnicalib-mcmod')
credentials {
username = getVar('GITHUB_ACTOR')
password = getVar('GITHUB_TOKEN')
}
}
maven {
name = 'McmodsRepo'
url "file://${project.projectDir}/mcmodsrepo"
}
}
}

signing {
useInMemoryPgpKeys(findProperty('signingKey'), findProperty('signingPassword'))
sign publishing.publications
}


task genUpdateJson() {
doFirst {
def j = [
'homepage': 'https://github.com/auioc/arnicalib-mcmod/releases',
'promos': [
"${minecraft_version}-latest": "${arnicalib_version}",
"${minecraft_version}-recommended": "${arnicalib_version}",
]
]
println(groovy.json.JsonOutput.toJson(j))
File file = file("tmp/${minecraft_version}.json")
file.write(groovy.json.JsonOutput.toJson(j))
}
}


def getVar(String var_name) {
return System.getenv(var_name)
}
1 change: 1 addition & 0 deletions gradle.properties
Expand Up @@ -11,4 +11,5 @@ mappings_version=1.18.2

mixin_version=0.8.5

github_repo=auioc/arnicalib-mcmod
arnicalib_version=5.3.8
43 changes: 43 additions & 0 deletions gradle/artifacts.gradle
@@ -0,0 +1,43 @@
def jarManifest = [
"Specification-Title": 'arnicalib',
"Specification-Vendor": 'AUIOC',
"Specification-Version": '1',
"Implementation-Title": project.name,
"Implementation-Version": "${arnicalib_version}",
"Implementation-Vendor" :'AUIOC',
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"TweakClass": 'org.spongepowered.asm.launch.MixinTweaker',
"TweakOrder": 0,
"MixinConfigs": 'arnicalib.mixin.json',
"ArnicaLib-Version": "${project.archivesBaseName}-${project.fullVersion}"
]

jar {
manifest {attributes(jarManifest)}
}
jar.finalizedBy('reobfJar')

task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
manifest {attributes(jarManifest)}
}
task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
classifier = 'sources'
manifest {attributes(jarManifest)}
}
task forgelibJar(type: Jar) {
from sourceSets.main.output
from sourceSets.main.allJava
classifier = 'forgelib'
manifest {attributes(jarManifest)}
}

artifacts {
archives sourcesJar
archives deobfJar
archives forgelibJar
}

tasks.build.dependsOn('sourcesJar', 'deobfJar', 'forgelibJar')
33 changes: 33 additions & 0 deletions gradle/publishing.gradle
@@ -0,0 +1,33 @@
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
artifact jar
artifact deobfJar {
classifier 'deobf'
}
artifact sourcesJar {
classifier 'sources'
}
artifact forgelibJar {
classifier 'forgelib'
}
}
}
repositories {
maven {
name = 'GitHubPackages'
url = uri("https://maven.pkg.github.com/${github_repo}")
credentials {
username = System.getenv('GITHUB_ACTOR')
password = System.getenv('GITHUB_TOKEN')
}
}
maven {
name = 'McmodsRepo'
url "file://${project.projectDir}/mcmodsrepo"
}
}
}
6 changes: 6 additions & 0 deletions gradle/signing.gradle
@@ -0,0 +1,6 @@
apply plugin: 'signing'

signing {
useInMemoryPgpKeys(findProperty('signingKey'), findProperty('signingPassword'))
sign publishing.publications
}
17 changes: 17 additions & 0 deletions gradle/tasks.gradle
@@ -0,0 +1,17 @@
task genUpdateJson() {
doFirst {
def j = [
'homepage': "https://github.com/${github_repo}/releases",
'promos': [
"${minecraft_version}-latest": "${project.modVersion}",
"${minecraft_version}-recommended": "${project.modVersion}",
]
]
File file = file("tmp/${minecraft_version}.json")
file.write(groovy.json.JsonOutput.toJson(j))
}
}

task outputProjectFullName() {
file("tmp/fullname.txt").write("${project.archivesBaseName}-${project.fullVersion}")
}
17 changes: 17 additions & 0 deletions gradle/utils.gradle
@@ -0,0 +1,17 @@
def getExecOutput(commands) {
def out = new ByteArrayOutputStream()
exec {
commandLine commands
standardOutput out
}
return out.toString().trim();
}

def getEnvAsBoolean(name) {
return System.getenv(name) && System.getenv(name).toBoolean()
}

ext {
getExecOutput = this.&getExecOutput
getEnvAsBoolean = this.&getEnvAsBoolean
}
27 changes: 27 additions & 0 deletions gradle/version.gradle
@@ -0,0 +1,27 @@
apply from: "$rootDir/gradle/utils.gradle"

def getBuildVersion() {
if (getEnvAsBoolean('CI')) {
if (getEnvAsBoolean('GITHUB_ACTIONS')) {
def dev = getEnvAsBoolean('IS_RELEASE') ? '' : 'dev-'
def sha = System.getenv('GITHUB_SHA').substring(0, 7)
def buildNumber = System.getenv('GITHUB_RUN_NUMBER')

return "${dev}rev.${sha}-build.${buildNumber}"
} else {
return System.getenv('CI_VERSION')
}
} else {
def sha = getExecOutput(['git', 'rev-parse', '--verify', '--short', 'HEAD'])
def dirty = getExecOutput(['git', 'status', '--short']).isEmpty() ? '' : '-dirty'
return "dev-rev.${sha}-build.0${dirty}"
}
}


project.ext.baseVersion = "${minecraft_version}-${project.modVersion}"
project.ext.fullVersion = "${baseVersion}-${getBuildVersion()}"
project.version = getEnvAsBoolean('IS_RELEASE') ? baseVersion : fullVersion

logger.lifecycle("Project version: ${project.version}")
logger.lifecycle("Full version: ${fullVersion}")

0 comments on commit a8fcfec

Please sign in to comment.