forked from PG85/OpenTerrainGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
112 lines (92 loc) · 3.95 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// This is the main build.gradle, and includes the createReleaseJar that was previously in the Releases module
// Version is set in this document, and then fetched and replaced into mods.toml and plugin.yml by gradle, in forge and spigot's build.gradle files
// Information for all projects
import java.util.zip.*
// The default tasks for all projects
defaultTasks 'clean', 'build', 'createReleaseJar', 'install'
allprojects
{
version = "1.16.5-0.1.11"
group = "com.pg85.otg"
// Version of the shadow plugin
ext.shadowVersion = '1.2.4'
}
description = "Open Terrain Generator: Generate anything!"
// Information for all subprojects
// (common, forge and bukkit, but not this file)
subprojects
{ task ->
task.plugins.withType(JavaBasePlugin)
{
// Generate Eclipse config files when using "gradle eclipse"
task.apply plugin: 'eclipse'
// Generate IntelliJ IDEA config files
task.apply plugin: 'idea'
}
// Generate a pom.xml, upload to local Maven repository
apply plugin: 'maven'
}
// Gets the JAR file for the project with the given name
static def getJarFile(Project project)
{
String fileName = project.archivesBaseName + '-' + project.version + '.jar'
return new File(project.buildDir, 'distributions/' + fileName)
}
// Adds all files from the given zip file (source) to the given destination, which
// must also be a zip file. A set of already added files is maintained to prevent
// duplicates
static def addToZip(File source, ZipOutputStream destination, Set<String> alreadyAddedFiles)
{
byte[] buffer = new byte[4096]
ZipInputStream inputStream = new ZipInputStream(new FileInputStream(source))
ZipEntry nextEntry = inputStream.getNextEntry()
while (nextEntry != null)
{
if (!alreadyAddedFiles.contains(nextEntry.name))
{
// Start new entry
alreadyAddedFiles.add(nextEntry.name)
destination.putNextEntry(new ZipEntry(nextEntry))
// Transfer all bytes
int bytesRead = inputStream.read(buffer)
while (bytesRead > 0)
{
destination.write(buffer, 0, bytesRead)
bytesRead = inputStream.read(buffer)
}
}
// Done reading this entry, on to the next one
nextEntry = inputStream.getNextEntry()
}
inputStream.close()
}
task buildSubProjects {
dependsOn ':common:common-core:build', ':platforms:fabric:build', ':platforms:forge:build', ':platforms:spigot:build'
}
task createReleaseJar {
dependsOn project.buildSubProjects
doLast {
// We're including common only for the external libraries that are packaged with it (using Forge jar-in-jar).
File commonFile = getJarFile(project(":common:common-core"))
File forgeFile = getJarFile(project(":platforms:forge"))
File fabricFile = getJarFile(project(":platforms:fabric"))
File spigotFile = getJarFile(project(":platforms:spigot"))
File ourFile = new File(project.buildDir, 'releases/OpenTerrainGenerator-'+project.version+'.jar')
if (forgeFile.exists() && spigotFile.exists() && fabricFile.exists())
{
ourFile.getParentFile().mkdirs()
ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(ourFile))
Set<String> alreadyAddedFiles = new HashSet<String>()
addToZip(forgeFile, outputStream, alreadyAddedFiles) // Add Forge first so its jar manifest is used
addToZip(fabricFile, outputStream, alreadyAddedFiles)
addToZip(commonFile, outputStream, alreadyAddedFiles)
addToZip(spigotFile, outputStream, alreadyAddedFiles)
outputStream.close()
} else {
println(" Skipping the release jar, as the Spigot, Fabric or Forge file failed")
println(" Forge exists: " + forgeFile.exists())
println(" Fabric exists: " + fabricFile.exists())
println(" Spigot exists: " + spigotFile.exists())
}
}
}