-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
257 lines (224 loc) · 8.86 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
plugins {
id 'java-library'
id 'maven-publish'
}
import org.apache.tools.ant.taskdefs.condition.Os
ext {
if(Os.isFamily(Os.FAMILY_MAC)) {
// Compilation succeeds for both targets on either Mac platform, but in both cases the output is for the platform we're on
// Therefore, we only include our own platform as target here.
if (Os.isArch("aarch64")) {
natives = ["macosx_aarch64_clang"]
} else {
natives = ["macosx_amd64_clang"]
}
} else if (Os.isFamily(Os.FAMILY_UNIX)) {
// Cross-compilation with MinGW-w64 allows us to also build the Windows target on Linux
natives = ["linux_amd64_gcc","linux_windows_amd64_mingw32"]
} else {
throw new GradleException("This script only works on Linux or Mac")
}
allNatives = [
"linux_amd64_gcc",
"linux_windows_amd64_mingw32",
"macosx_aarch64_clang",
"macosx_amd64_clang"
]
generatedSrcDir = 'src/generated/java'
}
java {
sourceCompatibility(JavaVersion.VERSION_1_8)
targetCompatibility(JavaVersion.VERSION_1_8)
}
// We use both Maven Central and our own Artifactory instance, which contains module builds, extra libs, and so on
repositories {
mavenCentral()
// Terasology Artifactory instance for libs not readily available elsewhere plus our own libs
maven {
def repoViaEnv = System.getenv()["RESOLUTION_REPO"]
if (rootProject.hasProperty("alternativeResolutionRepo")) {
// If the user supplies an alternative repo via gradle.properties then use that
name "from alternativeResolutionRepo property"
url alternativeResolutionRepo
} else if (repoViaEnv != null && repoViaEnv != "") {
name "from \$RESOLUTION_REPO"
url = repoViaEnv
} else {
// Our default is the main virtual repo containing everything except repos for testing Artifactory itself
name "Terasology Artifactory"
url "https://artifactory.terasology.io/artifactory/virtual-repo-live"
}
}
}
group = 'org.terasology.jnbullet'
dependencies {
api group: 'org.joml', name: 'joml', version: '1.9.25'
api group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
}
sourceSets {
main {
java {
srcDir generatedSrcDir
}
}
}
task generateSources{
dependsOn ":swig-src:Swig"
}
compileJava.dependsOn generateSources
clean {
// the clean task should delete the folder, because it is the
// output folder of generateSources, but it doesn't do it.
delete generatedSrcDir
}
task sourceJar(type: Jar) {
description = "Create a JAR with all sources"
from sourceSets.main.allSource
from sourceSets.test.allSource
archiveClassifier = 'sources'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
description = "Create a JAR with the JavaDoc for the java sources"
from javadoc.destinationDir
archiveClassifier = 'javadoc'
}
natives.each { module ->
tasks.create(name: "native_${module}", type: Exec) {
description = "cmake ${module} "
executable "cmake"
workingDir "$rootDir/build/natives/${module}"
args "$rootDir", "-DCMAKE_TOOLCHAIN_FILE=$rootDir/toolchains/${module}.cmake", "-DCMAKE_BUILD_TYPE=Release"
doFirst {
mkdir "$rootDir/build/natives/${module}"
}
doLast {
exec {
workingDir "$rootDir/build/natives/${module}"
commandLine 'make', "-j${Runtime.runtime.availableProcessors()}"
}
}
}
}
task buildNatives{
description = "Builds Natives"
natives.each { module ->
dependsOn "native_${module}"
}
}
task listNatives{
description = "List all supported platforms."
doLast {
println "All known natives (*supported):"
allNatives.each { module ->
// check whether module is contained in natives
if (natives.contains(module)) {
println " *native_${module}"
} else {
println " native_${module}"
}
}
}
}
// TODO: outputs are not defined well enough yet for Gradle to skip this if already done (maybe more the natives task?)
task zipNatives(type: Zip){
description 'Creates a zip archive that contains all TeraBullet native files'
allNatives.each { module ->
from ("$rootDir/build/natives/${module}") {
include '*linux*'
into 'linux'
}
from ("$rootDir/build/natives/${module}") {
include '*windows*'
into 'windows'
}
from ("$rootDir/build/natives/${module}") {
include '*darwin*'
into 'macosx'
}
}
destinationDirectory = file(buildDir)
archiveBaseName = 'JNBullet'
}
buildNatives.dependsOn generateSources
// Building natives is a prerequisite for zipping them, but we don't want to re-compute them every time.
// Also, we build natives on different platforms and combine them to a single zip, so we can't just depend on the native tasks anyway.
//zipNatives.dependsOn buildNatives
javadoc {
failOnError = false
}
publish {
dependsOn sourceJar, javadocJar, zipNatives
}
// Define the artifacts we want to publish (the .pom will also be included since the Maven plugin is active)
publishing {
publications {
mavenJava(MavenPublication) {
artifactId='JNBullet'
groupId = group
from components.java
artifact sourceJar
artifact javadocJar
artifact zipNatives
pom.withXml {
asNode().with {
appendNode('name', "JNBullet")
appendNode('description', "A Java Native Bullet Wrapper")
appendNode('url', "http://www.example.com/project")
appendNode('licenses').with {
appendNode('license').with {
appendNode('name', "The Apache License, Version 2.0")
appendNode('url', "http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
appendNode('developers').with {
appendNode('developer').with {
appendNode('id', "michaelpollind")
appendNode('name', "Michael Pollind")
appendNode('email', "[email protected]")
}
}
appendNode('scm').with {
appendNode('connection', "https://github.com/MovingBlocks/JNBullet")
appendNode('developerConnection', "[email protected]:MovingBlocks/JNBullet.git")
appendNode('url', "https://github.com/MovingBlocks/JNBullet")
}
}
}
repositories {
maven {
name = 'TerasologyOrg'
if (rootProject.hasProperty("publishRepo")) {
// This first option is good for local testing, you can set a full explicit target repo in gradle.properties
url = "https://artifactory.terasology.io/artifactory/$publishRepo"
logger.info("Changing PUBLISH repoKey set via Gradle property to {}", publishRepo)
} else {
// Support override from the environment to use a different target publish org
String deducedPublishRepo = System.getenv()["PUBLISH_ORG"]
if (deducedPublishRepo == null || deducedPublishRepo == "") {
// If not then default
deducedPublishRepo = "libs"
}
// Base final publish repo on whether we're building a snapshot or a release
if (project.version.endsWith('SNAPSHOT')) {
deducedPublishRepo += "-snapshot-local"
} else {
deducedPublishRepo += "-release-local"
}
logger.info("The final deduced publish repo is {}", deducedPublishRepo)
url = "https://artifactory.terasology.io/artifactory/$deducedPublishRepo"
}
if (rootProject.hasProperty("mavenUser") && rootProject.hasProperty("mavenPass")) {
credentials {
username = "$mavenUser"
password = "$mavenPass"
}
authentication {
basic(BasicAuthentication)
}
}
}
}
}
}
}