Skip to content

Commit ab4c451

Browse files
authored
Merge pull request #59 from EraTiem-Network/next
Gradle 8.8 + maven repos via yaml
2 parents e73e936 + 7a84a46 commit ab4c451

File tree

6 files changed

+75
-27
lines changed

6 files changed

+75
-27
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ build/
66
!**/src/main/**/run/
77
!**/src/test/**/run/
88
gradle.properties
9+
maven-repos.yml
10+
.kotlin
911

1012
### Files with secrets and private paths ###
1113
.idea/runConfigurations

build.gradle.kts

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import com.charleskorn.kaml.Yaml
2+
import com.charleskorn.kaml.decodeFromStream
13
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2-
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
34
import java.lang.System.getProperty
5+
import java.lang.System.getenv
46
import java.net.URI
57

68
group = "net.eratiem"
@@ -40,33 +42,37 @@ subprojects {
4042
}
4143
}
4244

45+
// ###############
46+
// # Maven Repos #
47+
// ###############
48+
buildscript {
49+
dependencies {
50+
classpath(libs.kotlinx.serialization.core)
51+
classpath(libs.kaml)
52+
}
53+
repositories.mavenCentral()
54+
}
55+
56+
val repoList = File("maven-repos.yml").takeIf(File::exists)?.inputStream()?.use { stream ->
57+
Yaml.default.decodeFromStream<List<Map<String, String?>>>(stream).map {
58+
MavenRepo(
59+
it["name"]!!,
60+
URI(it["url"]!!),
61+
it["username"],
62+
it["password"],
63+
it["publish"]?.toBooleanStrictOrNull() ?: false
64+
)
65+
}
66+
}
67+
4368

4469
// ##############
4570
// # Publishing #
4671
// ##############
4772

4873
publishing {
4974
repositories {
50-
val repoNames = System.getProperties().filterKeys { (it as String).startsWith("project.publish", true) }
51-
.map { (it.key as String).removePrefix("project.publish.").substringBefore(".") }.toSet()
52-
53-
repoNames.forEach {
54-
maven {
55-
name = it.uppercaseFirstChar()
56-
url = uri(getProperty("project.publish.$it.url"))
57-
58-
getProperty("project.publish.$it.auth-type")?.let { authType ->
59-
when (authType) {
60-
else -> {
61-
credentials {
62-
username = "${properties["project.publish.$it.username"]}"
63-
password = "${properties["project.publish.$it.access-token"]}"
64-
}
65-
}
66-
}
67-
}
68-
}
69-
}
75+
repoList?.filter { it.publish }?.forEach { createRepository(it) }
7076
}
7177
}
7278

@@ -81,10 +87,7 @@ allprojects {
8187
}
8288

8389
repositories {
84-
maven {
85-
name = "Bit-Build | Artifactory"
86-
url = URI("https://artifactory.bit-build.de/artifactory/public")
87-
}
90+
repoList?.forEach { createRepository(it) }
8891
}
8992

9093
tasks {
@@ -136,4 +139,30 @@ fun <T> T.applyIf(condition: Boolean, block: T.() -> Unit) =
136139
apply { block() }
137140
} else {
138141
this
139-
}
142+
}
143+
144+
fun RepositoryHandler.createRepository(repo: MavenRepo) {
145+
maven {
146+
name = repo.name.replace(Regex("[^A-Za-z0-9_\\-. ]"), "").replace(Regex("\\s+"), "_")
147+
url = repo.url
148+
149+
val envName = name.replace(Regex("\\."), "").uppercase()
150+
val user = repo.username ?: getenv("${envName}_USERNAME")
151+
val pass = repo.password ?: getenv("${envName}_PASSWORD")
152+
153+
if (!user.isNullOrBlank() || !pass.isNullOrBlank()) {
154+
credentials {
155+
if (!user.isNullOrBlank()) username = user
156+
if (!pass.isNullOrBlank()) password = pass
157+
}
158+
}
159+
}
160+
}
161+
162+
data class MavenRepo(
163+
val name: String,
164+
val url: URI,
165+
val username: String? = null,
166+
val password: String? = null,
167+
val publish: Boolean = false
168+
)

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[versions]
22
kotlin = "2.0.0"
3+
kotlinx-serialization = "1.6.3"
34
shadow = "8.1.1"
45
run = "2.3.0"
56
paperweight = "1.7.1"
@@ -16,6 +17,8 @@ plugin-folia = "1.20"
1617
[libraries]
1718
kotlin-gradleplugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
1819
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
20+
kotlinx-serialization-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
21+
kaml = { group = "com.charleskorn.kaml", name = "kaml", version = "0.59.0" }
1922

2023
# Minecraft Software Dependencies
2124
minecraft-server-folia = { group = "dev.folia", name = "folia-api", version.ref = "folia" }

gradle/wrapper/gradle-wrapper.jar

-9 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

maven-repos.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- name: EmpireRP | Public
2+
url: https://nexus.empirerp.de/repository/public/
3+
username: motzkiste
4+
password: 5,W5dVDeD-4nN!}_?ibRtNMr;^7=pZ]Y,;UV<sHQ*:\;"#N{MU`m-533yz<~?L<i
5+
- name: EmpireRP | Snapshots
6+
url: https://nexus.empirerp.de/repository/empirerp-snapshots/
7+
username: motzkiste
8+
password: 5,W5dVDeD-4nN!}_?ibRtNMr;^7=pZ]Y,;UV<sHQ*:\;"#N{MU`m-533yz<~?L<i
9+
publish: true
10+
- name: EmpireRP | Releases
11+
url: https://nexus.empirerp.de/repository/empirerp-releases/
12+
username: motzkiste
13+
password: 5,W5dVDeD-4nN!}_?ibRtNMr;^7=pZ]Y,;UV<sHQ*:\;"#N{MU`m-533yz<~?L<i
14+
publish: true

0 commit comments

Comments
 (0)