Skip to content

Commit

Permalink
Updated buildsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Nov 22, 2023
1 parent 1fc9292 commit a42620f
Show file tree
Hide file tree
Showing 62 changed files with 190 additions and 177 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish
on:
workflow_dispatch:
push:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'oracle'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Publish
run: ./gradlew publish
env:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
BUILD_NUMBER: ${{ github.run_number }}
- name: CurseForge Publish
run: ./gradlew curseforge -PcurseApiKey=${CURSE_API_KEY}
env:
CURSE_API_KEY: ${{ secrets.CURSE_API_KEY }}
BUILD_NUMBER: ${{ github.run_number }}
continue-on-error: true
- name: Modrinth Publish
run: ./gradlew modrinth -PmodrinthToken=${MODRINTH_TOKEN}
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
BUILD_NUMBER: ${{ github.run_number }}
continue-on-error: true
156 changes: 91 additions & 65 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.+', changing: true
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}

plugins {
id "net.minecraftforge.gradle" version "6.0.+"
id "org.spongepowered.mixin" version "0.7-SNAPSHOT"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "2.+"
id 'net.minecraftforge.gradleutils' version '2.2.0'
}

apply plugin: 'maven-publish'
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'maven-publish'

ext {
mod_version = gradleutils.getTagOffsetVersion()
changelog_file = project.file("build/changelog.txt")
}

changelog {
fromTag '9.2.0'
}

repositories { mavenLocal() }
def trimChangelog(String text) {
def m = text =~ /(?s) - (?:[0-9.]+) (.+?)(?=( - )|$)/
return '```\n' + m[0][1].replaceAll(/(?m)^ */, '')
}

group = "com.github.glitchfiend"
archivesBaseName = "${mod_name}"
version = "${minecraft_version}-${mod_version}.${System.getenv().BUILD_NUMBER}"
base.archivesName = mod_name
version = "${minecraft_version}-${mod_version}"

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

tasks.withType(JavaCompile).configureEach {
it.options.encoding = 'UTF-8'
it.options.release.set(17)
}

// Disables Gradle's custom module metadata from being published to maven. The
// metadata includes mapped dependencies which are not reasonably consumable by
// other mod developers.
tasks.withType(GenerateModuleMetadata) {
enabled = false
}

minecraft {
mappings channel: 'official', version: minecraft_version
Expand All @@ -34,39 +50,55 @@ minecraft {
runs {
client = {
workingDirectory = project.file("run")
source sourceSets.main
args "-mixin.config=${mod_id}.mixins.json"
ideaModule "${project.name}.main"
taskName 'Client'
mods {
modClientRun {
source sourceSets.main
}
}
}
server = {
workingDirectory = project.file("run")
source sourceSets.main
server {
workingDirectory project.file('run')
args "-mixin.config=${mod_id}.mixins.json"
ideaModule "${project.name}.main"
taskName 'Server'
mods {
modServerRun {
source sourceSets.main
}
}
}
data {
workingDirectory = project.file("run")
source sourceSets.main
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/'), '--existing', file('src/generated/resources/')
workingDirectory project.file('run')
ideaModule "${project.name}.main"
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/'), "-mixin.config=${mod_id}.mixins.json"
taskName 'Data'
mods {
modDataRun {
source sourceSets.main
}
}
}
}
}

// Configure the source folders
sourceSets {
main {
api {
java {
srcDir "src/main/java"
srcDir "public/src/main/java"
compileClasspath += main.compileClasspath
srcDirs main.java.srcDirs
include "${mod_id}/api/**"
}
}
main {
resources {
srcDir 'src/main/resources'
srcDir 'src/generated/resources'
srcDir 'public/src/main/resources'
}
}
}

processResources {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

dependencies {
minecraft 'net.minecraftforge:forge:' + minecraft_version + '-' + forge_version
implementation fg.deobf("com.github.glitchfiend:SereneSeasons:${serene_seasons_version}")
Expand All @@ -78,30 +110,21 @@ mixin {
config "${mod_id}.mixins.json"
}

task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
}

task apiJar(type: Jar) {
from(sourceSets.main.allJava) {
include "${mod_id}/api/**"
}
from (sourceSets.main.output) {
include 'LICENSE.txt'
include "${mod_id}/api/**"
}
from sourceSets.api.allJava, sourceSets.api.output
archiveClassifier = 'api'
}

duplicatesStrategy = DuplicatesStrategy.INCLUDE
classifier = 'api'
task deobfJar(type: Jar) {
from sourceSets.main.output
archiveClassifier = 'deobf'
}

def changelog_file = rootProject.file("build/${mod_name}-${version}-changelog.txt")
build.dependsOn apiJar
build.dependsOn deobfJar

curseforge {
if (project.hasProperty('curseApiKey')) {
apiKey = project.getProperty('curseApiKey')
}
apiKey = project.findProperty('curseApiKey') ?: 'unset'
project {
id = mod_curseforge_id

Expand All @@ -121,22 +144,28 @@ curseforge {
}
}

artifacts {
modrinth {
token = project.findProperty('modrinthToken')
projectId = mod_modrinth_id
versionNumber = mod_version
versionName = version + " for Forge " + minecraft_version
versionType = 'beta' // can be release, beta, or alpha
uploadFile = jar
gameVersions = [minecraft_version]
loaders = ['forge']

if (changelog_file.exists()) {
archives changelog_file
changelog = trimChangelog(changelog_file.text)
}
archives jar
archives deobfJar
archives apiJar
}

publishing {
publications {
mavenJava(MavenPublication) {
// We must use artifact jar to ensure the Forge dependency is excluded from the pom, breaking fg.deobf()
artifact jar
artifact deobfJar
artifact apiJar
artifact deobfJar
groupId project.group
artifactId project.archivesBaseName
version project.version
Expand Down Expand Up @@ -174,13 +203,10 @@ publishing {
}
repositories {
maven {
url "https://maven.minecraftforge.net/releases/"
authentication {
basic(BasicAuthentication)
}
url = "https://maven.minecraftforge.net/releases/"
credentials {
username = System.env.MAVEN_USER ?:'fake'
password = System.env.MAVEN_PASSWORD ?:'news'
username = System.getenv("MAVEN_USER")
password = System.getenv("MAVEN_PASSWORD")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

# Project
mod_version=9.1.0
mod_id=toughasnails
mod_name=ToughAsNails
mod_display_name=Tough As Nails
Expand All @@ -14,6 +13,7 @@ mod_issues_url=https://github.com/Glitchfiend/ToughAsNails/issues
mod_git_url=https://github.com/Glitchfiend/ToughAsNails
mod_scm_url=scm:git:[email protected]:Glitchfiend/ToughAsNails.git
mod_curseforge_id=246391
mod_modrinth_id=tough-as-nails

# Dependencies
minecraft_version=1.20.2
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 23 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand All @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
Loading

0 comments on commit a42620f

Please sign in to comment.