-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
193 lines (166 loc) · 6.27 KB
/
build.gradle.kts
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
import com.jfrog.bintray.gradle.BintrayExtension
import de.undercouch.gradle.tasks.download.Download
import groovy.lang.GroovyObject
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import kotlin.concurrent.thread
plugins {
`java-library`
`maven-publish`
kotlin("jvm")
id("de.undercouch.download")
id("com.jfrog.bintray")
id("com.jfrog.artifactory")
}
val branch = prop("branch") ?: System.getenv("TRAVIS_BRANCH") ?: System.getenv("GIT_BRANCH")
?: Runtime.getRuntime().exec("git rev-parse --abbrev-ref HEAD", null, buildDir).inputStream.reader().readLines().last()
logger.info("On branch $branch")
group = "be.bluexin"
version = "$branch-".takeUnless { branch == "master" }.orEmpty() + prop("version_number") + "." + prop("build_number")
description = "Bringing Discord-RPC to Kotlin"
repositories {
jcenter()
}
val shade by configurations.creating
val shadeInPlace by configurations.creating
configurations.compileOnly.extendsFrom(shade, shadeInPlace)
configurations.testCompileOnly.extendsFrom(shade, shadeInPlace)
dependencies {
api(kotlin("stdlib-jdk8"))
api("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
api("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8", prop("coroutinesVersion"))
implementation("org.slf4j", "slf4j-api")
implementation("io.github.microutils", "kotlin-logging", prop("kotlinLoggingVersion"))
testRuntime("org.slf4j", "slf4j-simple", prop("slf4jVersion"))
shade("net.java.dev.jna", "jna", prop("jnaVersion"))
shadeInPlace(files("libs"))
shadeInPlace(files("libsExt") {
builtBy("expandDiscordRPC")
})
}
tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
getByName("jar", Jar::class).apply {
for (dep in shade) {
from(zipTree(dep)) {
exclude("META-INF", "META-INF/**")
}
}
for (dep in shadeInPlace) {
from(dep)
}
}
// DISCORDRPC
val discordVersion = prop("discord_rpc_version")
val discordDownloadFolder = "$buildDir/download/discord/$discordVersion"
val dlDiscordRPC by creating {
logger.info("Downloading discord-rpc version $discordVersion...")
arrayOf("win", "linux", "osx").forEach {
val dlCurrent by tasks.register<Download>("download-$it") {
src("https://github.com/discordapp/discord-rpc/releases/download/v$discordVersion/discord-rpc-$it.zip")
dest("$discordDownloadFolder/discord-rpc-$it.zip")
overwrite(false)
}
outputs.files(dlCurrent.outputFiles)
dependsOn(dlCurrent)
}
}
val expandDiscordRPC by creating(Copy::class) {
inputs.files(dlDiscordRPC.outputs.files)
logger.info("Expanding discord-rpc...")
val outputDir = file("libsExt")
outputDir.delete()
val extensions = arrayOf("dll", "so", "dylib")
val map = mapOf(
"win64-dynamic" to "win32-x86-64",
"win32-dynamic" to "win32-x86",
"linux-dynamic" to "linux-x86-64",
"osx-dynamic" to "darwin"
)
from(inputs.files.map { logger.info("Zip: $it"); zipTree(it) })
eachFile {
var accepted = false
val split = name.split('.')
if (split.any() && split.last() in extensions) for (entry in map) {
logger.info("3 $relativePath")
if (relativePath.pathString.contains(entry.key)) {
logger.info("4 $relativePath")
relativePath = RelativePath(true, entry.value, name)
logger.info("5 $relativePath")
accepted = true
break
}
}
if (!accepted) exclude()
}
into(outputDir)
includeEmptyDirs = false
}
}
// PUBLISHING
val sourcesJar by tasks.creating(Jar::class) {
from(sourceSets["main"].allSource)
from(sourceSets["test"].allSource)
classifier = "sources"
}
publishing {
publications.register("publication", MavenPublication::class) {
from(components["java"])
artifact(sourcesJar)
}
repositories {
val mavenPassword = if (hasProp("local")) null else prop("mavenPassword")
maven {
val remoteURL = "https://maven.bluexin.be/repository/" + (if ((version as String).contains("SNAPSHOT")) "snapshots" else "releases")
val localURL = "file://$buildDir/repo"
url = uri(if (mavenPassword != null) remoteURL else localURL)
if (mavenPassword != null) {
credentials(PasswordCredentials::class.java) {
username = prop("mavenUser")
password = mavenPassword
}
}
}
}
}
val publication by publishing.publications
bintray {
user = prop("bintrayUser")
key = prop("bintrayApiKey")
publish = true
override = true
setPublications(publication.name)
pkg(delegateClosureOf<BintrayExtension.PackageConfig> {
repo = "bluexin"
name = project.name
userOrg = "bluexin"
websiteUrl = "https://github.com/Bluexin/drpc4k"
githubRepo = "Bluexin/drpc4k"
vcsUrl = "https://github.com/Bluexin/drpc4k"
issueTrackerUrl = "https://github.com/Bluexin/drpc4k/issues"
desc = project.description
setLabels("kotlin", "discord")
setLicenses("GPL-3.0")
})
}
artifactory {
setContextUrl("https://oss.jfrog.org")
publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<GroovyObject> {
val targetRepoKey = if (project.version.toString().endsWith("-SNAPSHOT")) "oss-snapshot-local" else "oss-release-local"
setProperty("repoKey", targetRepoKey)
setProperty("username", prop("bintrayUser"))
setProperty("password", prop("bintrayApiKey"))
setProperty("maven", true)
})
defaults(delegateClosureOf<GroovyObject> {
invokeMethod("publications", publication.name)
})
})
}
// UTILS
fun hasProp(name: String): Boolean = extra.has(name)
fun prop(name: String): String? = extra.properties[name] as? String