Skip to content

Commit b461add

Browse files
committed
chore: make sandboxing testing easy
1 parent 6355917 commit b461add

File tree

9 files changed

+44
-709
lines changed

9 files changed

+44
-709
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ $ sdk u java 21.0.4-zulu
2424
$ ./gradlew build
2525
```
2626

27-
For testing, a separate [sandbox project](/sandbox) is available with the plugin applied in `settings.gradle.kts`.
28-
First publish the plugin to the local maven repository and then run the sandbox project by setting the `test.version` in
29-
sandbox [gradle.properties](/sandbox/gradle.properties).
27+
For testing, a separate [sandbox project](/sandbox) is available with the plugin and version catalog applied in
28+
`settings.gradle.kts`. First publish the plugin to the local maven repository and then run the sandbox project.
3029

3130
```bash
3231
$ ./gradlew publishToMavenLocal
33-
# Set the test.version in sandbox/gradle.properties
3432
$ ./gradlew -p sandbox :build
3533
$ ./gradlew -p sandbox :dependencyUpdates
3634
```

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
java = "24"
33
kotlin = "2.1.0-Beta2"
4-
kotlin-ksp = "2.1.0-Beta2-1.0.25"
4+
kotlin-ksp = "2.1.0-Beta2-1.0.26"
55
kotlin-jvmtarget = "21"
66
kotlin-dsl-jvmtarget = "21"
77
kotlin-api-version = "2.1"

plugins/src/main/kotlin/dev.suresh.plugin.repos.settings.gradle.kts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import org.tomlj.Toml
1111

1212
val versionCatalog by lazy {
1313
// A hack to read version catalog from settings
14-
Toml.parse(file("$rootDir/gradle/libs.versions.toml").readText()).getTable("versions")
15-
?: error("Unable to parse the version catalog!")
14+
runCatching {
15+
Toml.parse(file("$rootDir/gradle/libs.versions.toml").readText()).getTable("versions")
16+
}
17+
.getOrNull()
1618
}
1719

1820
pluginManagement {
@@ -123,7 +125,7 @@ fun RepositoryHandler.googleAndroid() {
123125
fun RepositoryHandler.nodeJS() {
124126
exclusiveContent {
125127
forRepository {
126-
ivy(versionCatalog.getString("repo-nodejs").orEmpty()) {
128+
ivy(versionCatalog?.getString("repo-nodejs").orEmpty()) {
127129
name = "Node Distributions at $url"
128130
patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
129131
metadataSources { artifact() }
@@ -135,7 +137,7 @@ fun RepositoryHandler.nodeJS() {
135137
}
136138

137139
fun RepositoryHandler.kobWeb() {
138-
maven(url = versionCatalog.getString("repo-kobweb").orEmpty()) {
140+
maven(url = versionCatalog?.getString("repo-kobweb").orEmpty()) {
139141
name = "KobWeb Repo"
140142
content { includeGroupAndSubgroups("com.varabyte") }
141143
}
@@ -145,7 +147,7 @@ fun RepositoryHandler.mavenSnapshot() {
145147
val mvnSnapshot = providers.gradleProperty("enableMavenSnapshot").orNull.toBoolean()
146148
if (mvnSnapshot) {
147149
logger.lifecycle("❖ Maven Snapshot is enabled!")
148-
maven(url = versionCatalog.getString("repo-mvn-snapshot").orEmpty()) {
150+
maven(url = versionCatalog?.getString("repo-mvn-snapshot").orEmpty()) {
149151
mavenContent { snapshotsOnly() }
150152
}
151153
}

sandbox/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import tasks.*
44

55
plugins {
66
dev.suresh.plugin.root
7-
dev.suresh.plugin.kotlin.jvm
7+
dev.suresh.plugin.kotlin.mpp
88
com.gradleup.shadow
99
}
1010

11+
kotlin { jvmTarget(project) }
12+
1113
description = "Sandbox App"
1214

1315
application { mainClass = "MainKt" }

sandbox/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ enableMavenSnapshot=false
5656
debug=false
5757

5858
# Sandbox Testing
59-
test.version=0.13.0
59+
# test.version=x.y.z

sandbox/gradle/libs.versions.toml

Lines changed: 0 additions & 671 deletions
This file was deleted.

sandbox/settings.gradle.kts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,49 @@
33
pluginManagement {
44
repositories {
55
gradlePluginPortal()
6-
mavenCentral()
76
mavenLocal()
7+
mavenCentral()
88
}
99

10-
val testVersion = extra["test.version"].toString()
11-
plugins {
12-
listOf("repos", "root", "kotlin.jvm", "kotlin.mpp").forEach {
13-
// Use individual plugin marker artifact
14-
// id("dev.suresh.plugin.$it") version testVersion
15-
}
16-
}
17-
18-
resolutionStrategy {
19-
eachPlugin {
20-
if (requested.id.id.startsWith("dev.suresh.plugin")) {
21-
// Or directly use the plugin artifact
22-
useModule("dev.suresh.build:plugins:$testVersion")
23-
}
24-
}
25-
}
10+
// val testVersion = extra["test.version"].toString()
11+
//
12+
// 1. Use individual plugin marker artifact
13+
//
14+
// plugins {
15+
// listOf("repos", "root", "kotlin.jvm", "kotlin.mpp").forEach {
16+
// id("dev.suresh.plugin.$it") version testVersion
17+
// }
18+
// }
19+
20+
// 2. Or directly use the main plugin artifact
21+
//
22+
// resolutionStrategy {
23+
// eachPlugin {
24+
// if (requested.id.id.startsWith("dev.suresh.plugin")) {
25+
// useModule("dev.suresh.build:plugins:$testVersion")
26+
// }
27+
// }
28+
// }
2629
}
2730

2831
dependencyResolutionManagement {
2932
repositories {
33+
mavenLocal()
3034
mavenCentral()
3135
gradlePluginPortal()
32-
mavenLocal()
3336
}
34-
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
37+
38+
repositoriesMode = RepositoriesMode.PREFER_SETTINGS
3539

3640
versionCatalogs {
37-
create("mylibs") {
38-
from("dev.suresh.build:catalog:${extra["test.version"]}")
41+
create("libs") {
42+
from("dev.suresh.build:catalog:+")
3943
version("java", "21")
4044
}
4145
}
4246
}
4347

44-
plugins { id("dev.suresh.plugin.repos") }
48+
plugins { id("dev.suresh.plugin.repos") version "+" }
4549

4650
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
4751

sandbox/src/jvmMain/kotlin/Main.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fun main() {
2+
println("Hello, sandbox project! 🏖")
3+
println("Java: ${System.getProperty("java.runtime.version")}, Kotlin: ${KotlinVersion.CURRENT}")
4+
}

sandbox/src/main/kotlin/Main.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)