-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
181 lines (149 loc) · 4.74 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
id 'java'
id 'maven-publish'
id 'application'
id "org.panteleyev.jpackageplugin" version "1.3.1"
}
repositories {
mavenLocal()
maven { url 'https://repo.maven.apache.org/maven2' }
}
project.ext {
lwjglVersion = '3.2.3'
log4jVersion = '2.17.1'
gsonVersion = '2.10.1'
majorVersion = '0'
minorVersion = '5'
}
version = "${majorVersion}.${minorVersion}.${getBuildId()}" + ""
group = "Bob-Rust-Java"
description = "Bob-Rust-Java"
java.sourceCompatibility = JavaVersion.VERSION_16
// Make sure our project knows it's own version
writeVersion()
application {
mainClass = 'com.bobrust.main.Main'
}
import org.gradle.internal.os.OperatingSystem
switch (OperatingSystem.current()) {
case OperatingSystem.LINUX:
def osArch = System.getProperty("os.arch")
project.ext.lwjglNatives = osArch.startsWith("arm") || osArch.startsWith("aarch64")
? "natives-linux-${osArch.contains("64") || osArch.startsWith("armv8") ? "arm64" : "arm32"}"
: "natives-linux"
break
case OperatingSystem.MAC_OS:
project.ext.lwjglNatives = natives-macos
break
case OperatingSystem.WINDOWS:
def osArch = System.getProperty("os.arch")
project.ext.lwjglNatives = osArch.contains("64")
? "natives-windows${osArch.startsWith("aarch64") ? "-arm64" : ""}"
: "natives-windows-x86"
break
}
configurations {
packImpl {
canBeResolved = true
transitive = false
}
implementation.extendsFrom(packImpl)
}
dependencies {
packImpl "org.lwjgl:lwjgl:$lwjglVersion"
packImpl "org.lwjgl:lwjgl-tinyfd:$lwjglVersion"
packImpl "org.lwjgl:lwjgl:$lwjglVersion:$lwjglNatives"
packImpl "org.lwjgl:lwjgl-tinyfd:$lwjglVersion:$lwjglNatives"
packImpl "org.apache.logging.log4j:log4j-api:$log4jVersion"
packImpl "org.apache.logging.log4j:log4j-core:$log4jVersion"
packImpl "com.google.code.gson:gson:$gsonVersion"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
test {
useJUnitPlatform()
}
def incrementBuildId() {
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
def code = versionProps['build_id'].toInteger() + 1
versionProps['build_id'] = code.toString()
versionProps.store(versionPropsFile.newWriter(), null)
}
}
def writeVersion() {
def versionFile = file('src/main/resources/version')
FileOutputStream stream = new FileOutputStream(versionFile)
stream.write("$version".getBytes())
stream.close()
}
def getBuildId() {
def versionPropsFile = file('version.properties')
if (versionPropsFile.canRead()) {
def Properties versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
return versionProps['build_id'].toInteger()
}
return 0
}
task clearDist {
doLast {
println "Cleaning dist"
project.delete(files("${buildDir}/distributions"))
def jpackageTemp = file("${buildDir}/jpackagetemp");
project.delete(jpackageTemp)
jpackageTemp.mkdirs()
}
}
task assembleRelease {
doFirst {
println "AutoIncrement"
incrementBuildId()
}
}
task copyRuntimeLibs(type: Copy) {
into "${buildDir}/$libsDirName"
from configurations.packImpl
}
task assembleProject {
doFirst {
// Clean the libs folder such that the release doesn't contain old files
println "Cleaning libs"
project.delete(files("${buildDir}/libs"))
}
dependsOn("assembleRelease")
dependsOn("jpackage")
}
/**
* https://github.com/petr-panteleyev/jpackage-gradle-plugin
* https://docs.oracle.com/en/java/javase/16/jpackage/override-jpackage-resources.html#GUID-1B718F8B-B68D-4D46-B1DB-003D7729AAB6
*/
tasks.jpackage {
dependsOn("copyRuntimeLibs")
dependsOn("clearDist")
dependsOn("build")
// autoincrement version
dependsOn("assembleRelease")
appName = "Bob Rust"
temp = "${buildDir}/jpackagetemp"
type = "MSI"
input = "$buildDir/$libsDirName"
destination = "$buildDir/$distsDirName"
mainClass = "com.bobrust.main.Main"
verbose = true
mainJar = jar.archiveFileName.get()
windows {
resourceDir = "$projectDir/jpackage"
winMenu = true
winDirChooser = true
winPerUserInstall = true // Use AppData
winShortcut = true
winUpgradeUuid = "2a3ea308-884a-4d37-81ce-9899b022d9ef"
icon = "$projectDir/jpackage/assets/icon.ico"
}
}