| plugins { |
| id 'java' |
| id 'com.github.johnrengelman.shadow' version '7.0.0' |
| id 'io.github.shevchik.ManualGradleDependencySupplier' version '3.0' |
| id 'maven-publish' |
| } |
| |
| |
| gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.ShowStacktrace.ALWAYS |
| |
| |
| defaultTasks 'build' |
| |
| |
| group 'protocolsupport' |
| version '1.17.1-2' |
| |
| |
| import java.nio.file.Path |
| import java.nio.file.Paths |
| import java.nio.file.Files |
| import java.nio.file.StandardCopyOption; |
| |
| import io.github.shevchik.manualgradledependencysupplier.ManualGradleDependencySupplier |
| import io.github.shevchik.manualgradledependencysupplier.DependencySupplier |
| import io.github.shevchik.manualgradledependencysupplier.BuildDependencySupplier |
| import io.github.shevchik.manualgradledependencysupplier.FilterZipFileDependencySupplier |
| |
| |
| Path projectDirectoryPath = projectDir.toPath().toAbsolutePath() |
| Path projectBuildDirectoryPath = getBuildDir().toPath() |
| |
| |
| Path generatedResourcesDirectoryPath = projectBuildDirectoryPath.resolve('gen') |
| Path generatedResourcesResourcesDirectoryPath = generatedResourcesDirectoryPath.resolve('resources') |
| |
| task setupFolders(type: DefaultTask) {doLast{ |
| Files.createDirectories(generatedResourcesDirectoryPath) |
| Files.createDirectories(generatedResourcesResourcesDirectoryPath) |
| }} |
| |
| |
| sourceCompatibility = JavaVersion.VERSION_16 |
| |
| sourceSets { |
| main { |
| java { |
| srcDirs = ['src'] |
| } |
| resources { |
| srcDirs = ['resources'] |
| } |
| } |
| test { |
| java { |
| srcDirs = ['tests'] |
| } |
| } |
| } |
| |
| repositories { |
| mavenCentral() |
| maven { |
| url 'https://oss.sonatype.org/content/repositories/snapshots/' |
| } |
| maven { |
| url 'https://papermc.io/repo/repository/maven-public/' |
| } |
| maven { |
| url 'https://jitpack.io' |
| } |
| } |
| |
| dependencies { |
| Path spigotBuildDirectoryPath = projectBuildDirectoryPath.resolve('spigot') |
| |
| DependencySupplier spigotDependencySupplier = new BuildDependencySupplier( |
| new URL('https://hub.spigotmc.org/jenkins/job/BuildTools/128/artifact/target/BuildTools.jar'), |
| spigotBuildDirectoryPath, |
| 'BuildTools.jar', |
| ['java', '-jar', 'BuildTools.jar', '--rev', '1.17.1'], |
| ['spigot-1.17.1.jar'] |
| ).setBuildEnv([ |
| 'MAVEN_OPTS': '-Dmaven.repo.local=' + spigotBuildDirectoryPath.resolve('m2').toString() + ' -Xmx1024M' |
| ]) |
| |
| compileOnly group: 'com.github.ProtocolSupport', name: 'ProtocolSupportBuildProcessor', version: '907b3e20db' |
| compileOnly group: 'io.netty', name: 'netty-all', version: '4.1.70.Final' |
| compileOnly (group: 'io.papermc.paper', name: 'paper-api', version: '1.17.1-R0.1-SNAPSHOT') { |
| exclude group: 'com.google.code.gson', module: 'gson' |
| } |
| compileOnly group: 'com.google.code.gson', name: 'gson', version: '2.8.0' |
| compileOnly ManualGradleDependencySupplier.supplyDependecies([ |
| new FilterZipFileDependencySupplier( |
| spigotDependencySupplier, |
| ['/net/minecraft', '/com/mojang', '/org/bukkit/craftbukkit', '/org/spigotmc'], true, |
| spigotBuildDirectoryPath, |
| 'spigot-1.17.1-1-filtered-compile.jar' |
| ) |
| ]) |
| |
| |
| implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11' |
| implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.4.2' |
| implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' |
| |
| annotationProcessor group: 'com.github.ProtocolSupport', name: 'ProtocolSupportBuildProcessor', version: '907b3e20db' |
| |
| testImplementation ManualGradleDependencySupplier.supplyDependecies([ |
| spigotDependencySupplier |
| ]) |
| testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0' |
| testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0' |
| } |
| |
| compileJava { |
| options.encoding = 'UTF-8' |
| options.incremental = false |
| options.compilerArgs << ('-Aprotocolsupportbuildprocessor.generatedresourcesdirectory=' + generatedResourcesResourcesDirectoryPath.resolve('preload').toString()) |
| } |
| |
| |
| test { |
| Path workingDirectoryPath = projectDirectoryPath.resolve('testsRun'); |
| |
| doFirst { |
| Files.createDirectories(workingDirectoryPath) |
| } |
| |
| useJUnitPlatform() |
| |
| workingDir = workingDirectoryPath; |
| } |
| |
| |
| processResources { |
| doFirst { |
| Properties properties = new Properties() |
| properties.setProperty('buildtime', new Date().format('yyyy.MM.dd \'at\' HH:mm:ss z')) |
| properties.setProperty('buildhost', System.getProperty('protocolsupport.buildhost', 'unknown')) |
| properties.setProperty('buildnumber', System.getProperty('protocolsupport.buildnumber', 'unknown')) |
| properties.setProperty('buildgit', System.getProperty('protocolsupport.buildgit', 'unknown')) |
| Files.newBufferedWriter(generatedResourcesResourcesDirectoryPath.resolve('buildinfo')).withCloseable({ properties.store(it, 'Build info') }) |
| } |
| |
| from generatedResourcesDirectoryPath |
| |
| filesMatching('plugin.yml') { |
| expand 'version': project.version |
| } |
| } |
| |
| shadowJar { |
| duplicatesStrategy = DuplicatesStrategy.INCLUDE |
| |
| archiveClassifier = '' |
| |
| from sourceSets.main.java.srcDirs |
| from 'LICENSE' |
| |
| exclude 'META-INF/**' |
| exclude 'module-info.class' |
| |
| String relocatePrefix = 'protocolsupport.libs.' |
| |
| relocate 'org.apache', relocatePrefix + 'org.apache' |
| relocate 'it.unimi.dsi.fastutil', relocatePrefix + 'it.unimi.dsi.fastutil' |
| relocate 'javax.annotation', relocatePrefix + 'javax.annotation' |
| |
| minimize() |
| } |
| |
| |
| task copyFinalJarToTarget(type: DefaultTask) {doLast{ |
| Path targetJarDirectory = projectDirectoryPath.resolve('target') |
| Files.createDirectories(targetJarDirectory) |
| Files.copy( |
| shadowJar.archiveFile.get().getAsFile().toPath().toAbsolutePath(), |
| targetJarDirectory.resolve(shadowJar.archiveBaseName.get() + '.jar'), |
| StandardCopyOption.REPLACE_EXISTING |
| ) |
| }} |
| |
| |
| compileJava.dependsOn(setupFolders) |
| compileJava.finalizedBy(test) |
| jar.enabled = false |
| jar.finalizedBy(shadowJar) |
| shadowJar.finalizedBy(copyFinalJarToTarget) |
| |
| |
| tasks.withType(GenerateModuleMetadata) { |
| enabled = false |
| } |
| |
| publishing { |
| publications { |
| release(MavenPublication) { |
| from components.java |
| |
| artifacts = [shadowJar] |
| } |
| } |
| } |