BetterEnd/build.gradle
2023-06-19 19:31:27 +02:00

388 lines
No EOL
12 KiB
Groovy

buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.114'
}
}
plugins {
id 'fabric-loom' version "${loom_version}"
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id "com.matthewprenger.cursegradle" version "1.4.0"
}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group
def local_bclib = findProject(':BCLib') != null
def local_wunderlib = findProject(':WunderLib') != null
repositories {
maven { url "https://maven.dblsaiko.net/" }
maven { url "https://maven.fabricmc.net/" }
maven { url 'https://maven.blamejared.com' }
maven { url "https://maven.shedaniel.me/" }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.terraformersmc.com/releases' }
maven { url = "https://maven.terraformersmc.com/" }
maven { url "https://ladysnake.jfrog.io/artifactory/mods" }
maven { url = "https://dvs1.progwml6.com/files/maven/" }
maven { url = "https://modmaven.dev" }
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
flatDir {
dirs 'libs'
}
}
loom {
accessWidenerPath = file("src/main/resources/betterend.accesswidener")
interfaceInjection {
// When enabled injected interfaces from dependecies will be applied.
enableDependencyInterfaceInjection = true
}
runs {
// This adds a new gradle task that runs the datagen API: "gradlew runDatagenClient"
datagenClient {
inherit client
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
vmArg "-Dfabric-api.datagen.strict-validation"
vmArg "-Dfabric-api.datagen.modid=betterend"
runDir "build/datagen"
}
}
}
sourceSets {
main {
// Add the datagenned files into the jar.
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
//1.19.3 modApi "vazkii.patchouli:Patchouli:${project.patchouli_version}"
println "Using local BCLib: ${local_bclib}"
if (local_bclib) {
implementation(project(path: ":BCLib", configuration: 'dev'))
} else {
modImplementation "com.github.quiqueck:BCLib:${project.bclib_version}"
}
modCompileOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
//needed for trinkets, otherwise BetterEnd would require users to install trinkets
modApi "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}"
modCompileOnly "dev.emi:trinkets:${project.trinkets_version}"
modCompileOnly "dev.emi:emi-fabric:${emi_version}:api"
modLocalRuntime "dev.emi:emi-fabric:${emi_version}"
if (local_wunderlib) {
println "Using local WunderLib"
implementation project(path: ":WunderLib", configuration: 'dev')
}
}
processResources {
println "Version: ${project.version}"
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
// 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
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
it.options.release = 17
}
javadoc {
options.tags = ["reason"]
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {
from "LICENSE"
from "LICENSE.ASSETS"
}
artifacts {
archives sourcesJar
archives javadocJar
}
def env = System.getenv()
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task release(dependsOn: [remapJar, sourcesJar, javadocJar]) {
onlyIf {
env.GITHUB_TOKEN
}
doLast {
def github = GitHub.connectUsingOAuth(env.GITHUB_TOKEN as String)
def repository = github.getRepository("quiqueck/BetterEnd")
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("${archivesBaseName}-${version}")
releaseBuilder.body("A changelog can be found at https://github.com/quiqueck/BetterEnd/commits")
releaseBuilder.commitish("master")
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-sources.jar"), "application/java-archive");
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}-javadoc.jar"), "application/java-archive");
}
}
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
//from https://lowcarbrob.medium.com/android-pro-tip-generating-your-apps-changelog-from-git-inside-build-gradle-19a07533eec4
String generateChangelog() {
println "Assembeling Changelog ..."
def lastTag = "git describe --tags --abbrev=0".execute().text.trim()
//def gitLogCmd = "git log $lastTag..HEAD --oneline --no-merges --pretty=format:\"%s\"".execute().text.trim()
def gitLogCmd = "git log $lastTag..HEAD --oneline --pretty=format:\"%s\"".execute().text.trim()
def features = ""
def fixes = ""
def changes = ""
gitLogCmd.eachLine { gitLine ->
def line = gitLine.substring(1, gitLine.length() - 1)
if (line.trim().startsWith("[")) {
def sline = line.split("]", 2)
if (sline.length == 2) {
def type = sline[0].trim().toLowerCase().substring(1)
def comment = sline[1].trim()
//filter issue links
if (comment.contains("(")) {
def cline = comment.split("\\(", 2)
if (cline.length == 2 && cline[1].contains("#")) {
comment = cline[0].trim()
}
}
if (type == "fix" || type == "fixes" || type == "fixed") {
fixes += "- $comment \n"
} else if (type == "feature" || type == "features") {
features += "- $comment \n"
} else if (type == "change" || type == "changes" || type == "changed") {
changes += "- $comment \n"
} else {
println "Unknown Type: $type ($line)"
}
}
}
}
def changelog = ""
if (!features.isEmpty()) {
changelog += "#### Features\n"
changelog += features.trim()
changelog += "\n\n"
}
if (!changes.isEmpty()) {
changelog += "#### Changes\n"
changelog += changes.trim()
changelog += "\n\n"
}
if (!fixes.isEmpty()) {
changelog += "#### Fixes\n"
changelog += fixes.trim()
changelog += "\n\n"
}
println "Changelog since $lastTag:\n$changelog"
return changelog
}
task changelog() {
doLast {
new File(projectDir, "CHANGES.md").text = generateChangelog()
}
}
modrinth {
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
def modrinth_token = new File(projectDir, "../MODRINTH_TOKEN")
if (modrinth_token.exists()) {
modrinth_token = modrinth_token.text
} else {
modrinth_token = ""
}
def slurper = new groovy.json.JsonSlurper()
token = modrinth_token
projectId = project.modrinth_id
versionNumber = project.mod_version
versionType = project.release_channel
uploadFile = remapJar
gameVersions = slurper.parseText(project.modrinth_versions)
loaders = ["fabric"]
changelog = changes
dependencies {
required.project "fabric-api"
required.project "bclib"
optional.project "emi"
optional.project "rei"
optional.project "trinkets"
optional.project "patchouli"
}
debugMode = false
}
curseforge {
def slurper = new groovy.json.JsonSlurper()
apiKey = new File(projectDir, "../CURSEFORGE_TOKEN")
if (apiKey.exists()) {
apiKey = apiKey.text
} else {
apiKey = ""
}
def changes = new File(projectDir, "CHANGES.md")
if (changes.exists()) {
changes = changes.getText('UTF-8')
} else {
changes = ""
}
project {
id = '413596'
changelogType = 'markdown'
changelog = changes
releaseType = project.release_channel
def versions = slurper.parseText(project.modrinth_versions);
def latestVersion = ''
for (v in versions) {
addGameVersion v
latestVersion = "[$v]"
}
addGameVersion 'Fabric'
addGameVersion 'Java 17'
relations {
requiredDependency 'fabric-api'
requiredDependency 'bclib'
optionalDependency 'emi'
optionalDependency 'roughly-enough-items'
optionalDependency 'patchouli'
optionalDependency 'trinkets'
}
mainArtifact(remapJar) {
displayName = "$project.modrinth_id-$project.version $latestVersion"
}
afterEvaluate {
mainArtifact(remapJar.outputs)
}
}
options {
debug = false
forgeGradleIntegration = false
}
}
task nextVersion() {
doLast {
def inputFile = new File('modrinth.json')
def gameVersions = java.net.URLEncoder.encode(project.modrinth_versions, "UTF-8")
new URL("https://api.modrinth.com/v2/project/${project.modrinth_id}/version?&game_versions=${gameVersions}").withInputStream { i -> inputFile.withOutputStream { it << i } }
def json = new groovy.json.JsonSlurper().parseText(inputFile.text)
def version = json[0].version_number
//increment patch version
def indexedVersionList = version.split(/\./).toList().withIndex()
indexedVersionList = indexedVersionList.collect { num, idx -> num.toInteger() }
indexedVersionList[2] = indexedVersionList[2].value + 1
def updatedVersion = indexedVersionList.join(".")
println "\n\n"
println "------------- CURRENT VERSION -------------"
println "Last Published Version: " + version
println " Game Versions: " + json[0].game_versions
println " Status: " + json[0].status
println " Featured: " + json[0].featured
println " Downloaded: " + json[0].downloads
println "\n"
println "-------------- NEXT VERSION ---------------"
println "Next Version: " + updatedVersion
println "\n\n"
def propertiesFile = new File("gradle.properties")
def newContents = propertiesFile.text.replaceFirst("mod_version=\\d+.\\d+.\\d+", "mod_version=${updatedVersion}")
propertiesFile.text = newContents
}
}