-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle.kts
221 lines (197 loc) · 5.91 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
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
import BuildInfo.*
import co.riiid.gradle.ReleaseTask
import org.gradle.api.tasks.wrapper.Wrapper
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import us.kirchmeier.capsule.manifest.CapsuleManifest
import us.kirchmeier.capsule.spec.ReallyExecutableSpec
import us.kirchmeier.capsule.task.*
import org.gradle.jvm.tasks.Jar
import org.jetbrains.dokka.gradle.*
import term.*
buildscript {
var javaVersion: JavaVersion by extra { JavaVersion.VERSION_1_8 }
var kotlinVersion: String by extra { "kotlin.version".sysProp }
var kotlinEAPRepo: String by extra { "kotlin.eap.repo".sysProp }
var wrapperVersion: String by extra { "wrapper.version".sysProp }
repositories {
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
}
dependencies {
val dokkaVersion = "dokka.version".sysProp
classpath("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion")
}
}
val appVersion by project
val appAuthor by project
val javaVersion: JavaVersion by extra
val kotlinVersion: String by extra
val kotlinEAPRepo: String by extra
val wrapperVersion: String by extra
printHeader(appVersion)
plugins {
java
application
idea
val ktPlugin = "kotlin.version".sysProp
val gradleVersion = "gradle-versions.version".sysProp
kotlin("jvm", ktPlugin)
id("com.github.ben-manes.versions") version gradleVersion
id("us.kirchmeier.capsule") version "1.0.2"
id("co.riiid.gradle") version "0.4.2"
}
apply {
plugin<DokkaPlugin>()
}
base {
group = "io.sureshg"
version = appVersion
description = "Install Certs!"
}
/**
* Configure java compiler options.
*/
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
kotlin {
this.experimental.coroutines
}
/**
* Configure application plugin
*/
application {
applicationName = rootProject.name
mainClassName = "${project.group}.MainKt"
}
/**
* Configure kotlin compiler options.
*/
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = javaVersion.toString()
}
}
repositories {
jcenter()
maven { setUrl(kotlinEAPRepo) }
}
dependencies {
compile(kotlin("stdlib-jre8", kotlinVersion))
compile("io.airlift:airline:0.7")
}
/**
* Add jar manifests.
*/
tasks.withType<Jar> {
manifest {
attributes(mapOf(
Author.attr to appAuthor,
Date.attr to buildDateTime,
JDK.attr to "java.version".sysProp,
BuildTarget.attr to javaVersion,
OS.attr to "${"os.name".sysProp} ${"os.version".sysProp}",
KotlinVersion.attr to kotlinVersion,
CreatedBy.attr to "Gradle ${gradle.gradleVersion}",
AppVersion.attr to appVersion,
Title.attr to application.applicationName,
Vendor.attr to project.group,
MainClass.attr to application.mainClassName))
}
}
/**
* Make executable
*/
task<FatCapsule>("makeExecutable") {
val minJavaVer = javaVersion.toString()
val appName = application.applicationName
val appMainClass = application.mainClassName
archiveName = appName
reallyExecutable(closureOf<ReallyExecutableSpec> { regular() })
capsuleManifest(closureOf<CapsuleManifest> {
premainClass = "Capsule"
mainClass = "Capsule"
applicationName = appName
applicationClass = appMainClass
applicationVersion = version
jvmArgs = listOf("-client", "-Djava.security.egd=file:/dev/./urandom")
minJavaVersion = minJavaVer
})
description = "Create $archiveName executable."
dependsOn("clean")
doLast {
archivePath.setExecutable(true)
val size = archivePath.length().toBinaryPrefixString()
println("Executable File: ${archivePath.absolutePath.bold} (${size.bold})".done)
}
}
tasks.withType<DokkaTask> {
val src = "src/main"
val out = "$projectDir/docs"
val format = DokkaFormat.Html
doFirst {
println("Cleaning doc directory ${out.bold}...".cyan)
project.delete(fileTree(out) {
exclude("logos/**", "templates/**")
})
}
moduleName = ""
sourceDirs = files(src)
outputFormat = format.type
outputDirectory = out
skipEmptyPackages = true
jdkVersion = javaVersion.majorVersion.toInt()
includes = listOf("README.md", "CHANGELOG.md")
val mapping = LinkMapping().apply {
dir = src
url = "${githubRepo.url}/blob/master/$src"
suffix = "#L"
}
linkMappings = arrayListOf(mapping)
description = "Generate ${project.name} v$appVersion docs in ${format.desc} format."
doLast {
println("Generated ${format.desc} format docs to ${outputDirectory.bold}".done)
}
}
/**
* Set Github token and publish.
*/
github {
val tag = version.toString()
baseUrl = "https://api.github.com"
owner = githubRepo.user
repo = githubRepo.repo
tagName = tag
targetCommitish = "master"
name = "${application.applicationName} v$version"
val changelog = githubRepo.changelogUrl(branch = targetCommitish, tag = tag)
body = "$name release. Check [CHANGELOG.md]($changelog) for details."
setAssets(File(buildDir, "libs/${application.applicationName}").path)
}
tasks.withType<ReleaseTask> {
doFirst {
github.token = getEnv("GITHUB_TOKEN")
}
doLast {
println("Published github release ${github.name}.".done)
println("Release URL: ${githubRepo.releaseUrl().bold}")
}
description = "Publish Github release ${github.name}"
dependsOn("makeExecutable")
}
/**
* Generate Gradle Script Kotlin wrapper.
*/
task<Wrapper>("wrapper") {
description = "Generate Gradle Script Kotlin wrapper $wrapperVersion"
distributionType = ALL
distributionUrl = gradleKotlinDslUrl(wrapperVersion)
doFirst {
println(description)
}
}
/**
* Set default task
*/
defaultTasks("makeExecutable")