-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
246 lines (202 loc) · 7.74 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
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
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.*
plugins {
`maven-publish`
id("io.github.goooler.shadow") version "8.1.8" // ShadowJar
id("cl.franciscosolis.gradledotenv") version "1.0.1" // .env support
kotlin("jvm") version "2.0.0" // Kotlin
id("org.jetbrains.dokka") version "1.9.20" // Dokka (Kotlin Docs)
id("cl.franciscosolis.sonatype-central-upload") version "1.0.3" // Sonatype Central Upload
id("org.scm-manager.license") version "0.7.1" // License Header
}
/*
* Project Build ID is based on GIT_COMMIT_SHORT_HASH if any,
* otherwise we generate an UUIDv4 that will randomize its
* contents and get the first 8 characters.
*/
val projectBuildId = env["GIT_COMMIT_SHORT_HASH"] ?: UUID.randomUUID().toString().replace("-", "").split("").shuffled().joinToString("").substring(0, 8)
/*
* Project Version will be the environment variable version (or the one specified by us) if it's production,
* otherwise it will be added '$projectBuildId'
* (no snapshot because maven central does not support it)
*/
val projectVersion = "${env["VERSION"] ?: "1.0.1"}${if (env["ENV"] != "prod") "-$projectBuildId" else ""}"
/* Print out the current version */
println("This build version was '$projectVersion'")
val repo = "https://github.com/Im-Fran/SimpleCoreAPI"
/*
* The groupId will be the package name in lowercase
* if the environment is not production, we will add the environment name
* (or 'dev' if it's not specified)
*/
val groupId = "cl.franciscosolis${if(env["ENV"] != "prod") ".${env["ENV"] ?: "dev"}" else ""}".lowercase()
group = groupId
version = projectVersion.replaceFirst("v", "").replace("/", "")
description = "The best way to create a kotlin project."
allprojects {
apply {
plugin("io.github.goooler.shadow")
plugin("cl.franciscosolis.gradledotenv")
plugin("org.jetbrains.kotlin.jvm")
}
group = rootProject.group
version = rootProject.version
description = rootProject.description
repositories {
mavenCentral()
maven("https://s01.oss.sonatype.org/content/groups/public/")
maven("https://oss.sonatype.org/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/releases/")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://repo.codemc.org/repository/maven-public/")
maven("https://jitpack.io/")
mavenLocal()
}
kotlin {
compilerOptions.jvmTarget = JvmTarget.JVM_21
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
withJavadocJar()
}
tasks {
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
copy {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}
}
subprojects {
apply {
plugin("org.scm-manager.license")
plugin("org.jetbrains.dokka")
}
license {
header(rootProject.file("LICENSE-HEADER"))
include("**/src/main/**/*.kt")
newLine(true)
}
tasks {
compileJava {
options.encoding = "UTF-8"
}
named<DokkaTaskPartial>("dokkaHtmlPartial") {
outputDirectory = layout.buildDirectory.dir("dokka")
cacheRoot = file("${System.getProperty("user.home")}/.cache/dokka").apply {
if(!exists()) mkdirs()
}
}
}
}
dependencies {
implementation(project(":build-info", "shadow"))
implementation(project(":simplecoreapi", "shadow"))
}
tasks {
named<ShadowJar>("shadowJar") {
doLast {
copy {
from(archiveFile.get().asFile.absolutePath)
into(rootProject.layout.buildDirectory.dir("libs"))
rename { "simplecoreapi.jar" }
}
}
manifest {
attributes["Main-Class"] = "cl.franciscosolis.simplecoreapi.standalone.StandaloneLoaderKt"
}
mergeServiceFiles()
exclude("**/*.kotlin_metadata")
exclude("**/*.kotlin_builtins")
archiveBaseName = "simplecoreapi"
archiveClassifier = ""
}
register<Jar>("mergeSourcesJar") {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveClassifier = "sources"
from(subprojects.filter { subproject -> subproject.tasks.any { task -> task.name == "sourcesJar" } }
.flatMap { subproject -> subproject.sourceSets.map { sourceSet -> sourceSet.allSource } })
copy {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
archiveBaseName = "simplecoreapi"
}
dokkaHtmlMultiModule {
dependsOn(":dokkaHtml")
outputDirectory = rootProject.layout.buildDirectory.dir("dokka/")
}
register<Jar>("dokkaJavadocJar") {
dependsOn(dokkaHtmlMultiModule)
from(dokkaHtmlMultiModule.flatMap { dokkaTask -> dokkaTask.outputDirectory })
archiveClassifier = "javadoc"
archiveBaseName = "simplecoreapi"
}
sonatypeCentralUpload {
dependsOn(named("publish"))
username = env["SONATYPE_USERNAME"]
password = env["SONATYPE_PASSWORD"]
val publication = publishing.publications.named<MavenPublication>("shadow").orNull ?: error("Publication 'shadow' not found")
archives = files(publication.artifacts?.map { artifact -> artifact.file })
pom = file(layout.buildDirectory.file("publications/shadow/pom-default.xml"))
signingKey = env["SIGNING_KEY"]
signingKeyPassphrase = env["SIGNING_PASSWORD"]
publicKey = env["PUBLIC_KEY"]
}
}
publishing {
repositories {
if (env["ENV"] in listOf("prod", "dev")) {
if (env["GITHUB_ACTOR"] != null && env["GITHUB_TOKEN"] != null) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/Im-Fran/SimpleCoreAPI")
credentials {
username = env["GITHUB_ACTOR"]
password = env["GITHUB_TOKEN"]
}
}
}
}
mavenLocal()
}
publications {
create<MavenPublication>("shadow") {
configure<ShadowExtension> {
artifactId = rootProject.name.lowercase()
component(this@create)
artifact(tasks.named("dokkaJavadocJar"))
artifact(tasks.named("mergeSourcesJar"))
// Add contents from pom template
pom {
name = rootProject.name
description = project.description
url = repo
licenses {
license {
name = "GNU GPL v3"
url = "${repo}/blob/master/LICENSE"
}
}
developers {
developer {
id = "Im-Fran"
name = "Francisco Solís"
email = "[email protected]"
}
}
scm {
url = "$repo${if(repo.endsWith(".git")) "" else ".git"}"
}
}
}
}
}
}