Skip to content

Commit 52348f1

Browse files
committed
Setup Maven central publishing
1 parent c42dbd5 commit 52348f1

File tree

7 files changed

+84
-17
lines changed

7 files changed

+84
-17
lines changed

.github/workflows/actions.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ jobs:
3030
- name: Publish package
3131
run: ./gradlew publish
3232
env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
34+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
35+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_IN_MEMORY_KEY }}
36+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_IN_MEMORY_KEY_PASSWORD }}

.idea/artifacts/kotlin_parallel_operations_js_1_6_0.xml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/artifacts/kotlin_parallel_operations_jvm_1_6_0.xml

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Parallel Operations for Kotlin
2+
Parallel *map*, *reduce*, and various indexed and in-place operations on collections for Kotlin using coroutines.
3+
4+
The parallel *map* implementation is called *.mapParallel()*. It is implemented like this.
5+
```kotlin
6+
suspend fun <T, R> Iterable<T>.mapParallel(transform: (T) -> R): List<R> = coroutineScope {
7+
map { async { transform(it) } }.map { it.await() }
8+
}
9+
```
10+
11+
Example of using the parallel *map* operation.
12+
```kotlin
13+
fun showCase() {
14+
val list = listOf(1,2,3)
15+
runBlocking(Dispatchers.Default) {
16+
var mappedList = list.mapParallel { it * 2 } // Results in [2,4,6]
17+
}
18+
}
19+
```
20+
21+
There is also the parallel *reduce* operation with chunked variations, which can be used to perform **associative** operations on a collection, like *sum*.
22+
23+
**Note:** If you want to achieve multithreading, make sure to run the coroutine with the Default dispatcher.
24+
25+
## Chunked operations
26+
Chunked operations improve performance since they split the collection into just a couple of segments,
27+
which are processed each by a single thread. That benefits from data locality and lesser thread management.
28+
It is particularly useful (pretty much needed for operations like sum) in the reduce operation when using multithreading,
29+
since each thread takes one chunk that it reduces on its own. After all coroutines finish, their results are then reduced again to the final result.
30+
31+
## Gradle
32+
The library is published in the Maven Central repository.
33+
Include this line in your module build.gradle file.
34+
```gradle
35+
dependencies {
36+
implementation("io.github.cvb941:kotlin-parallel-operations:2.0.0")
37+
}
38+
```
39+
40+
## Future
41+
In the future, I would like other transformation functions to be implemented.

build.gradle.kts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import com.vanniktech.maven.publish.SonatypeHost
12
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
23

34
plugins {
45
kotlin("multiplatform") version "1.9.23"
56
id("org.jetbrains.kotlinx.benchmark") version "0.4.10"
67
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.23"
7-
id("maven-publish")
8+
id("com.vanniktech.maven.publish") version "0.28.0"
89
}
910

10-
group = "net.kusik"
11+
group = "io.github.cvb941"
1112
version = "2.0.0"
1213

1314
repositories {
@@ -90,15 +91,34 @@ allOpen {
9091
annotation("org.openjdk.jmh.annotations.State")
9192
}
9293

93-
publishing {
94-
repositories {
95-
maven {
96-
name = "GitHubPackages"
97-
url = uri("https://maven.pkg.github.com/cvb941/kotlin-parallel-operations")
98-
credentials {
99-
username = project.findProperty("gpr.user")?.toString() ?: System.getenv("GITHUB_ACTOR")
100-
password = project.findProperty("gpr.key")?.toString() ?: System.getenv("GITHUB_TOKEN")
94+
mavenPublishing {
95+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)
96+
97+
signAllPublications()
98+
99+
pom {
100+
name.set("Parallel Operations")
101+
description.set("Parallel map, reduce and more using coroutines in Kotlin.")
102+
inceptionYear.set("2019")
103+
url.set("https://github.com/cvb941/kotlin-parallel-operations/")
104+
licenses {
105+
license {
106+
name.set("MIT License")
107+
url.set("https://opensource.org/licenses/MIT")
108+
distribution.set("repo")
101109
}
102110
}
111+
developers {
112+
developer {
113+
id.set("cvb941")
114+
name.set("Lukas Kusik")
115+
url.set("https://github.com/cvb941/")
116+
}
117+
}
118+
scm {
119+
url.set("https://github.com/cvb941/kotlin-parallel-operations/")
120+
connection.set("scm:git:git://github.com/cvb941/kotlin-parallel-operations.git")
121+
developerConnection.set("scm:git:ssh://git@github.com/cvb941/kotlin-parallel-operations.git")
122+
}
103123
}
104124
}

0 commit comments

Comments
 (0)