Skip to content

Commit

Permalink
Upgraded to Gradle 8 (#129)
Browse files Browse the repository at this point in the history
* Upgraded to Gradle 8, now using CrucibleGradle
  • Loading branch information
juanmuscaria authored May 22, 2023
1 parent ff00464 commit f84563f
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/DevBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: ./gradlew --version

- name: Create distribution
run: ./gradlew jar
run: ./gradlew buildPackages
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
260 changes: 85 additions & 175 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
buildscript {
repositories {
mavenCentral()
//mavenLocal() // for testing plugin pre release
maven {
name = "juanmuscaria"
url = "https://github.com/juanmuscaria/maven/raw/master"
Expand All @@ -10,24 +12,24 @@ buildscript {
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-1.5.6-SNAPSHOT'
//classpath files('ForgeGradle-1.2-1.5.5-SNAPSHOT.jar')
classpath 'com.anatawa12.forge:ForgeGradle:1.2-1.1.0'
classpath 'io.github.cruciblemc:CrucibleGradle:1.0-SNAPSHOT'
}
}

apply plugin: 'maven'
apply plugin: 'cauldron'
apply plugin: 'maven-publish'
apply plugin: 'signing'
// Base lifecycle tasks are provided by this plugin
apply plugin: 'base'

// Crucible tasks and subproject management is provided by this plugin
apply plugin: 'crucible'

repositories {
maven {
name = "juanmuscaria"
url = "https://github.com/juanmuscaria/maven/raw/master"
}
maven {
name 'prok'
name 'thermos'
url 'https://github.com/juanmuscaria/maven/raw/master/ThermosLibs'
}
maven {
Expand All @@ -46,61 +48,37 @@ minecraft {
mainClass = 'cpw.mods.fml.relauncher.ServerLaunchWrapper'
tweakClass = 'cpw.mods.fml.common.launcher.FMLTweaker'
installerVersion = "1.4"
srgExtra "PK: org/bukkit/craftbukkit org/bukkit/craftbukkit/v1_7_R4"
srgExtra "PK: org/bukkit/craftbukkit org/bukkit/craftbukkit/v1_7_R4" // TODO: Perhaps rename the packages itself

// Repos used on the generated subprojects
repos = [
'https://github.com/juanmuscaria/maven/raw/master/ThermosLibs',
'https://github.com/juanmuscaria/maven/raw/master',
'https://maven.minecraftforge.net/',
'https://oss.sonatype.org/content/repositories/snapshots/',
'https://libraries.minecraft.net/'
]
}

group = 'cruciblemc'

ext.buildInfoCached = null;

ext.gitInfoCached = null;

def gitInfo(String key) {
if (!gitInfoCached) {
if (file('.git').exists()) {
gitInfoCached = [
hash : ['git', 'log', "--format=%h", '-n', '1'].execute().text.trim(),
fullHash: ['git', 'log', "--format=%H", '-n', '1'].execute().text.trim(),
branch : System.getenv("CI_BUILD_REF_NAME") ?: ['git', 'symbolic-ref', '--short', 'HEAD'].execute().text.trim(),
message : ['git', 'log', "--format=%B", '-n', '1'].execute().text.trim()
]
} else {
gitInfoCached = [
hash : 'NOT_A_GIT',
fullHash: 'NOT_A_GIT',
branch : 'NOT_A_GIT',
message : 'NOT_A_GIT'
]
}
}
return key ? gitInfoCached[key] : gitInfoCached;
}
group = 'io.github.cruciblemc'

ext.buildInfoCached = null
ext.gitInfoCached = null
ext.mcVersion = "1.7.10"
ext.forgeVersion = "1614"
ext.revision = "1.0.7"
ext.crucibleVersion = "5.4"
var crucibleVersion = "5.4" // TODO: Not hardcode the version.
if (gitInfo('branch') != "master") {
version = "${mcVersion}-${gitInfo('branch')}-${gitInfo('hash')}"
ext.crucibleVersion = "${gitInfo('branch')}-${gitInfo('hash')}"
} else {
version = "${mcVersion}-${crucibleVersion}"
}
System.setProperty("file.encoding", "UTF-8")

launch4j {
jreMinVersion = '1.8.0'
}

configurations {
compile.extendsFrom exported
libraries
bootstrap
}

dependencies {
bootstrap 'pw.prok:KBootstrap:0.2.+'
libraries 'pw.prok:KBootstrap:0.3.2@jar'
libraries 'pw.prok:Damask:0.1.2@jar'
libraries 'commons-cli:commons-cli:1.3@jar'
libraries 'org.slf4j:slf4j-simple:1.6.2@jar'
Expand Down Expand Up @@ -143,25 +121,76 @@ dependencies {
libraries 'it.unimi.dsi:fastutil:8.2.2'
}

packageUniversal {
from {
configurations.exported.collect {
it.isDirectory() ? it : zipTree(it)
packageServer {
manifest {
attributes([
'Thermos-Git-Branch' : gitInfo('branch'),
'Thermos-Git-Hash' : gitInfo('fullHash'),
'Thermos-Group' : project.group,
'Thermos-Channel' : project.name,
'Thermos-Version' : project.version,
'Thermos-Legacy' : true,
'Implementation-Vendor' : 'CrucibleMC Team',
'Implementation-Title' : project.name,
'Implementation-Version': project.version,
'Specification-Vendor' : 'Bukkit Team',
'Specification-Title' : 'Bukkit',
'Specification-Version' : '1.7.10-R0.1-SNAPSHOT',
'Forge-Version' : '10.13.4.1614',
'TweakClass' : 'cpw.mods.fml.common.launcher.FMLTweaker',
'Main-Class' : 'cpw.mods.fml.relauncher.ServerLaunchWrapper',
'Class-Path' : generateClasspath(),
'Crucible-Libs' : generateMavenLibs()
])
}
dependsOn("packageLibraries")
}

// TODO: Move this into the gradle plugin, generate md5 as well
tasks.register('packageLibraries', Zip) {
archiveFileName = 'libraries.zip'
destinationDirectory = file("$buildDir/distributions")
outputs.upToDateWhen {
false // TODO: Not 100% sure how to make this task re-run when libraries are changed...
}

configurations.libraries.resolvedConfiguration.resolvedArtifacts.collect {
def moduleVersion = it.moduleVersion
from (it.file) {
into ("${moduleVersion.id.group.replace('.', '/')}/${moduleVersion.id.name}/${moduleVersion.id.version}/")
}
}

group('crucible')
description("Package all necessary libraries to run Crucible, in case the server is unable to download them at runtime")
}

def String repeat(String string, int times) {
StringBuilder builder = new StringBuilder(string.length() * times)
times.times { builder.append(string) }
builder as String
def gitInfo(String key) {
if (!gitInfoCached) {
if (file('.git').exists()) {
gitInfoCached = [
hash : ['git', 'log', "--format=%h", '-n', '1'].execute().text.trim(),
fullHash: ['git', 'log', "--format=%H", '-n', '1'].execute().text.trim(),
branch : ['git', 'symbolic-ref', '--short', 'HEAD'].execute().text.trim(),
message : ['git', 'log', "--format=%B", '-n', '1'].execute().text.trim()
]
} else {
gitInfoCached = [
hash : 'NOT_A_GIT',
fullHash: 'NOT_A_GIT',
branch : 'NOT_A_GIT',
message : 'NOT_A_GIT'
]
}
}
return key ? gitInfoCached[key] : gitInfoCached
}

def generateClasspath(boolean legacy = false) {
def generateClasspath() {
def classpath = ''
configurations.libraries.resolvedConfiguration.resolvedArtifacts.collect { it.moduleVersion.id }.each {
def jar = "${it.group.replace('.', '/')}/${it.name}/${it.version}/${it.name}-${it.version}.jar"
classpath += " ${legacy ? 'libraries/' : repeat('../', (group as String).split('\\.').length + 2)}${jar}"
classpath += " ${'libraries/'}${jar}"
}
return classpath.trim()
}
Expand All @@ -172,123 +201,4 @@ def generateMavenLibs() {
libs += " ${it.group}:${it.name}:${it.version}"
}
return libs.trim()
}

def generateManifest(boolean legacy = false) {
[
'Thermos-Git-Branch' : gitInfo('branch'),
'Thermos-Git-Hash' : gitInfo('fullHash'),
'Thermos-Group' : project.group,
'Thermos-Channel' : project.name,
'Thermos-Version' : project.version,
'Thermos-Legacy' : legacy,
'Implementation-Vendor' : 'CrucibleMC Team',
'Implementation-Title' : project.name,
'Implementation-Version': project.version,
'Specification-Vendor' : 'Bukkit Team',
'Specification-Title' : 'Bukkit',
'Specification-Version' : '1.7.10-R0.1-SNAPSHOT',
'Forge-Version' : '10.13.4.1614',
'TweakClass' : 'cpw.mods.fml.common.launcher.FMLTweaker',
'Main-Class' : 'cpw.mods.fml.relauncher.ServerLaunchWrapper',
'Class-Path' : generateClasspath(legacy),
'Crucible-Libs' : generateMavenLibs()
]
}

tasks.packageUniversal {
classifier = 'server'
setManifest {}
manifest.attributes(generateManifest(true))
}

task copyLibraries(type: Copy) {
outputs.upToDateWhen { false }
into(buildDir)
configurations.libraries.resolvedConfiguration.resolvedArtifacts.collect {
def moduleVersion = it.moduleVersion
from (it.file) {
into ("libraries/${moduleVersion.id.group.replace('.', '/')}/${moduleVersion.id.name}/${moduleVersion.id.version}/")
}
}
}

task packageLibraries(type: Zip, dependsOn: copyLibraries) {
outputs.upToDateWhen { false }
setArchiveName("libraries.zip")
setDestinationDir(file("$buildDir/distributions"))
from("$buildDir/libraries")
}

task jar(type: Jar, dependsOn: [packageUniversal, packageLibraries]) {
destinationDir file("${buildDir}/distributions")
from zipTree(tasks.packageUniversal.archivePath)
manifest.attributes(generateManifest())
}

tasks.packageInstaller.onlyIf { false }

tasks.getByName("generateProjectCauldron") {
doLast {
def file = new File('eclipse/cauldron/build.gradle')
writeToBuildFile(file)
}
}
tasks.getByName("generateProjectClean") {
doLast {
def file = new File('eclipse/Clean/build.gradle')
writeToBuildFile(file)
}
}

def writeToBuildFile(file) {
file.append('''
repositories {
clear()
maven {
name = "juanmuscaria"
url = "https://github.com/juanmuscaria/maven/raw/master"
}
maven {
name "prok"
url "https://github.com/juanmuscaria/maven/raw/master/ThermosLibs"
}
maven {
name 'forge'
url 'https://maven.minecraftforge.net/'
}
maven {
name 'minecraft'
url 'https://libraries.minecraft.net/'
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
''')
configurations.libraries.resolvedConfiguration.resolvedArtifacts.collect { it.moduleVersion.id }.each { module ->
if (['net.minecraft:server:', 'org.ow2.asm:asm-all'].findAll { (module as String).startsWith it }.size() > 0) {
return
}
file.append(" compile '${module}'\n")
}
file.append('}')
}

task resolveAllDependencies {
doLast {
configurations.each { it.resolve() }
}
}

task copyLibs( type: Copy ) {
into "$buildDir/libs/lib"
from configurations.libraries
}

subprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.daemon=false
org.gradle.daemon=false
file.encoding=UTF-8
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit f84563f

Please sign in to comment.