Advanced-Portals/build.gradle

161 lines
5.0 KiB
Groovy
Raw Permalink Normal View History

import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.nio.file.StandardOpenOption
2022-05-04 02:17:54 +02:00
buildscript {
repositories {
maven {url "https://plugins.gradle.org/m2/"}
mavenCentral()
}
dependencies {
classpath "org.apache.httpcomponents:httpmime:4.5.13"
classpath "com.google.code.gson:gson:2.8.6"
classpath "org.apache.httpcomponents:httpclient:4.5.13"
}
}
plugins {
id 'dev.s7a.gradle.minecraft.server' version '1.1.0'
}
allprojects {
apply plugin: 'java'
tasks.withType(JavaCompile).configureEach {
2021-05-25 02:32:22 +02:00
options.encoding = 'UTF-8'
}
2023-11-22 01:25:22 +01:00
if (project.name != "Advanced-Portals") {
task buildSubmodules doLast {
task -> println "Building $task.project.name"
}
2022-04-24 04:31:39 +02:00
buildSubmodules.finalizedBy build
}
tasks.processResources {
def files = ["plugin.yml", "bungee.yml"]
filesMatching(files) {
expand(["pluginVersion": project.version])
}
}
2023-05-14 22:12:18 +02:00
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}
2018-06-03 09:13:21 +02:00
apply from: 'env-variables.gradle'
archivesBaseName = "Advanced-Portals"
2018-06-03 09:13:21 +02:00
group = 'com.sekwah.advancedportals'
def versionString = (file('./version.txt').text + (isRelease ? "" : "-${snapshotName}${shaRef}")).replaceAll('\n', '').replaceAll('\r', '')
setVersion(versionString)
println "Version: ${getVersion()}"
2018-06-03 09:13:21 +02:00
description = ""
2018-06-04 12:54:52 +02:00
configurations {
// configuration that holds jars to copy into lib
2022-04-24 04:34:45 +02:00
implementation.extendsFrom(includeLibs)
2018-06-04 12:54:52 +02:00
}
2018-06-07 00:10:52 +02:00
repositories {
2020-06-28 23:44:20 +02:00
maven { url "https://repo.maven.apache.org/maven2" }
2018-06-07 00:10:52 +02:00
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
2020-06-28 23:44:20 +02:00
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://nexus.velocitypowered.com/repository/maven-public/" }
}
2018-06-04 12:54:52 +02:00
// includeLibs just says to include the library in the final jar
2018-06-03 09:13:21 +02:00
dependencies {
2021-05-25 02:32:22 +02:00
includeLibs project(':lang')
includeLibs project(':core')
2021-05-25 02:32:22 +02:00
includeLibs project(':bungee')
includeLibs project(':spigot')
includeLibs project(':velocity')
}
apply from: 'env-variables.gradle'
println "Branch ${ext.branch}${ext.shaRef} isRelease: '${ext.isRelease}'"
jar {
// Filters the files out that are in the build folders. Look to see if there is a better way to do this?
from configurations.includeLibs.filter {
it.path.contains("${File.separator}build${File.separator}libs")
} .collect {
println("Will Include: ${it.name}")
it.isDirectory() ? it : zipTree(it)
}
2022-05-04 02:17:54 +02:00
}
2023-12-03 15:19:57 +01:00
// This is used to download my plugin for helping reload the server in tandem with the copyPlugin task
tasks.register('downloadSekCDevToolsPlugin') {
doLast {
// Define the URL and destination path
def url = 'https://github.com/sekwah41/SekCDevToolsPlugin/releases/download/v1.0.0/SekCDevToolsPlugin-1.0-SNAPSHOT.jar'
def destinationDir = new File("$buildDir/MinecraftServer/plugins")
def destinationFile = new File(destinationDir, 'SekCDevToolsPlugin-1.0-SNAPSHOT.jar')
// Create the directory if it doesn't exist
if (!destinationDir.exists()) {
destinationDir.mkdirs()
}
// Download the file if it doesn't exist
if (!destinationFile.exists()) {
println "Downloading SekCDevToolsPlugin..."
new URL(url).withInputStream { i ->
destinationFile.withOutputStream {
it << i
}
}
} else {
println "SekCDevToolsPlugin already downloaded"
}
}
}
tasks.launchMinecraftServer.dependsOn(downloadSekCDevToolsPlugin)
2022-05-04 02:17:54 +02:00
minecraftServerConfig {
jarUrl.set('https://download.getbukkit.org/spigot/spigot-1.20.2.jar')
2022-05-04 02:17:54 +02:00
jvmArgument = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", "-DIReallyKnowWhatIAmDoingISwear=true"]
}
tasks.withType(Jar).configureEach {
2023-04-06 19:41:18 +02:00
duplicatesStrategy = DuplicatesStrategy.WARN
}
2022-05-04 02:17:54 +02:00
2023-12-03 15:19:57 +01:00
/**
* Will build then copy it to the minecraft server folder for use with the launch task and dev tools plugin
*/
tasks.register('copyPlugin') {
2023-12-03 15:19:57 +01:00
dependsOn(build)
2022-05-04 02:17:54 +02:00
doLast {
copy {
def sourceFilePath = Paths.get("$buildDir/libs/Advanced-Portals-${getVersion()}.jar")
def destinationFilePath = Paths.get("$buildDir/MinecraftServer/plugins/Advanced-Portals.jar")
println "Handling file: $destinationFilePath"
byte[] newContent = Files.readAllBytes(sourceFilePath)
if (Files.exists(destinationFilePath)) {
println "File exists. Overwriting with new binary content."
Files.write(destinationFilePath, newContent, StandardOpenOption.TRUNCATE_EXISTING)
} else {
println "File does not exist. Copying from source."
Files.copy(sourceFilePath, destinationFilePath, StandardCopyOption.REPLACE_EXISTING)
2022-05-04 02:17:54 +02:00
}
}
}
}