Skip to content

Commit

Permalink
chore: make sandboxing testing easy
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshg committed Oct 27, 2024
1 parent 6355917 commit b461add
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 709 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ $ sdk u java 21.0.4-zulu
$ ./gradlew build
```

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

```bash
$ ./gradlew publishToMavenLocal
# Set the test.version in sandbox/gradle.properties
$ ./gradlew -p sandbox :build
$ ./gradlew -p sandbox :dependencyUpdates
```
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
java = "24"
kotlin = "2.1.0-Beta2"
kotlin-ksp = "2.1.0-Beta2-1.0.25"
kotlin-ksp = "2.1.0-Beta2-1.0.26"
kotlin-jvmtarget = "21"
kotlin-dsl-jvmtarget = "21"
kotlin-api-version = "2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import org.tomlj.Toml

val versionCatalog by lazy {
// A hack to read version catalog from settings
Toml.parse(file("$rootDir/gradle/libs.versions.toml").readText()).getTable("versions")
?: error("Unable to parse the version catalog!")
runCatching {
Toml.parse(file("$rootDir/gradle/libs.versions.toml").readText()).getTable("versions")
}
.getOrNull()
}

pluginManagement {
Expand Down Expand Up @@ -123,7 +125,7 @@ fun RepositoryHandler.googleAndroid() {
fun RepositoryHandler.nodeJS() {
exclusiveContent {
forRepository {
ivy(versionCatalog.getString("repo-nodejs").orEmpty()) {
ivy(versionCatalog?.getString("repo-nodejs").orEmpty()) {
name = "Node Distributions at $url"
patternLayout { artifact("v[revision]/[artifact](-v[revision]-[classifier]).[ext]") }
metadataSources { artifact() }
Expand All @@ -135,7 +137,7 @@ fun RepositoryHandler.nodeJS() {
}

fun RepositoryHandler.kobWeb() {
maven(url = versionCatalog.getString("repo-kobweb").orEmpty()) {
maven(url = versionCatalog?.getString("repo-kobweb").orEmpty()) {
name = "KobWeb Repo"
content { includeGroupAndSubgroups("com.varabyte") }
}
Expand All @@ -145,7 +147,7 @@ fun RepositoryHandler.mavenSnapshot() {
val mvnSnapshot = providers.gradleProperty("enableMavenSnapshot").orNull.toBoolean()
if (mvnSnapshot) {
logger.lifecycle("❖ Maven Snapshot is enabled!")
maven(url = versionCatalog.getString("repo-mvn-snapshot").orEmpty()) {
maven(url = versionCatalog?.getString("repo-mvn-snapshot").orEmpty()) {
mavenContent { snapshotsOnly() }
}
}
Expand Down
4 changes: 3 additions & 1 deletion sandbox/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import tasks.*

plugins {
dev.suresh.plugin.root
dev.suresh.plugin.kotlin.jvm
dev.suresh.plugin.kotlin.mpp
com.gradleup.shadow
}

kotlin { jvmTarget(project) }

description = "Sandbox App"

application { mainClass = "MainKt" }
2 changes: 1 addition & 1 deletion sandbox/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ enableMavenSnapshot=false
debug=false

# Sandbox Testing
test.version=0.13.0
# test.version=x.y.z
671 changes: 0 additions & 671 deletions sandbox/gradle/libs.versions.toml

This file was deleted.

48 changes: 26 additions & 22 deletions sandbox/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,49 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
mavenCentral()
}

val testVersion = extra["test.version"].toString()
plugins {
listOf("repos", "root", "kotlin.jvm", "kotlin.mpp").forEach {
// Use individual plugin marker artifact
// id("dev.suresh.plugin.$it") version testVersion
}
}

resolutionStrategy {
eachPlugin {
if (requested.id.id.startsWith("dev.suresh.plugin")) {
// Or directly use the plugin artifact
useModule("dev.suresh.build:plugins:$testVersion")
}
}
}
// val testVersion = extra["test.version"].toString()
//
// 1. Use individual plugin marker artifact
//
// plugins {
// listOf("repos", "root", "kotlin.jvm", "kotlin.mpp").forEach {
// id("dev.suresh.plugin.$it") version testVersion
// }
// }

// 2. Or directly use the main plugin artifact
//
// resolutionStrategy {
// eachPlugin {
// if (requested.id.id.startsWith("dev.suresh.plugin")) {
// useModule("dev.suresh.build:plugins:$testVersion")
// }
// }
// }
}

dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS

repositoriesMode = RepositoriesMode.PREFER_SETTINGS

versionCatalogs {
create("mylibs") {
from("dev.suresh.build:catalog:${extra["test.version"]}")
create("libs") {
from("dev.suresh.build:catalog:+")
version("java", "21")
}
}
}

plugins { id("dev.suresh.plugin.repos") }
plugins { id("dev.suresh.plugin.repos") version "+" }

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

Expand Down
4 changes: 4 additions & 0 deletions sandbox/src/jvmMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fun main() {
println("Hello, sandbox project! 🏖")
println("Java: ${System.getProperty("java.runtime.version")}, Kotlin: ${KotlinVersion.CURRENT}")
}
4 changes: 0 additions & 4 deletions sandbox/src/main/kotlin/Main.kt

This file was deleted.

0 comments on commit b461add

Please sign in to comment.