Skip to content

Commit 469c281

Browse files
committed
set init block in spotifyAppApi builder with credentials to optional
1 parent 052c50d commit 469c281

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

build.gradle.kts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import org.jetbrains.dokka.gradle.DokkaTask
22
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile
3+
import java.net.URI
34

45
plugins {
56
`maven-publish`
@@ -123,6 +124,10 @@ nexusStaging {
123124
}
124125

125126

127+
tasks.withType<GenerateModuleMetadata> {
128+
enabled = false
129+
}
130+
126131
publishing {
127132
publications {
128133
val jvm by getting(MavenPublication::class) {
@@ -165,17 +170,30 @@ publishing {
165170
}
166171
}
167172
repositories {
168-
maven {
169-
name = "nexus"
170-
val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
171-
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
172-
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
173-
174-
credentials {
175-
val nexusUsername: String? by project.extra
176-
val nexusPassword: String? by project.extra
177-
username = nexusUsername
178-
password = nexusPassword
173+
if (project.hasProperty("publishToCentral")) {
174+
maven {
175+
name = "nexus"
176+
val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
177+
val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
178+
url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
179+
180+
credentials {
181+
val nexusUsername: String? by project.extra
182+
val nexusPassword: String? by project.extra
183+
username = nexusUsername
184+
password = nexusPassword
185+
}
186+
}
187+
} else {
188+
if (project.extra.has("spaceUser") && project.extra.has("spacePassword")) {
189+
maven {
190+
credentials {
191+
username = project.extra["spaceUser"]?.toString()
192+
password = project.extra["spacePassword"]?.toString()
193+
}
194+
195+
url = URI.create("https://maven.jetbrains.space/adam/ratzman")
196+
}
179197
}
180198
}
181199
}

samples/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repositories {
1111
}
1212

1313
dependencies {
14-
implementation "com.adamratzman:spotify-api-kotlin:3.0.0"
14+
compile "com.adamratzman:spotify-api-kotlin:3.0.0"
1515
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
1616
}
1717

samples/src/main/kotlin/public/BrowseApiSample.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package public
33
import com.adamratzman.spotify.spotifyAppApi
44

55
fun main() {
6-
val api = spotifyAppApi {
7-
credentials {
8-
}
9-
}
6+
val api = spotifyAppApi(
7+
System.getenv("SPOTIFY_CLIENT_ID"),
8+
System.getenv("SPOTIFY_CLIENT_SECRET")
9+
)
1010
}

src/commonMain/kotlin/com.adamratzman.spotify/Builder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlinx.serialization.json.Json
1515

1616
// Kotlin DSL builders
1717

18-
fun spotifyAppApi(clientId: String, clientSecret: String, block: SpotifyAppApiBuilder.() -> Unit) =
18+
fun spotifyAppApi(clientId: String, clientSecret: String, block: SpotifyAppApiBuilder.() -> Unit = {}) =
1919
SpotifyAppApiBuilder().apply(block).apply {
2020
credentials {
2121
this.clientId = clientId

0 commit comments

Comments
 (0)