11# Gradle Enterprise API Kotlin
22
3- [ ![ Maven Central] ( https://img.shields.io/badge/Maven%20Central-0.16.2 -blue )] [ 14 ]
4- [ ![ Javadoc] ( https://img.shields.io/badge/Javadoc-0.16.2 -orange )] [ 7 ]
3+ [ ![ Maven Central] ( https://img.shields.io/badge/Maven%20Central-0.17.0 -blue )] [ 14 ]
4+ [ ![ Javadoc] ( https://img.shields.io/badge/Javadoc-0.17.0 -orange )] [ 7 ]
55
66A Kotlin library to access the [ Gradle Enterprise API] [ 1 ] , easy to use from:
77
88- [ Jupyter notebooks with the Kotlin kernel] [ 29 ]
99- [ Kotlin scripts (` kts ` )] [ 27 ]
1010- [ Kotlin projects] [ 28 ]
1111
12- Using the API is as easy as this:
13-
1412``` kotlin
15- GradleEnterpriseApi .buildsApi.getBuilds(since = yesterdayMilli).forEach {
13+ val api = GradleEnterpriseApi .newInstance()
14+ api.buildsApi.getBuilds(since = yesterdayMilli).forEach {
1615 println (it)
1716}
1817```
@@ -53,7 +52,7 @@ recommended over JitPack.
5352
5453```
5554%useLatestDescriptors
56- %use gradle-enterprise-api-kotlin(version=0.16.2 )
55+ %use gradle-enterprise-api-kotlin(version=0.17.0 )
5756```
5857
5958</details >
@@ -62,7 +61,7 @@ recommended over JitPack.
6261 <summary >Add to a Kotlin script</summary >
6362
6463``` kotlin
65- @file:DependsOn(" com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2 " )
64+ @file:DependsOn(" com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0 " )
6665```
6766
6867</details >
@@ -72,7 +71,7 @@ recommended over JitPack.
7271
7372``` kotlin
7473dependencies {
75- implementation(" com.gabrielfeo:gradle-enterprise-api-kotlin:0.16.2 " )
74+ implementation(" com.gabrielfeo:gradle-enterprise-api-kotlin:0.17.0 " )
7675}
7776```
7877
@@ -101,11 +100,13 @@ For example, [`BuildsApi`][20] contains all endpoints under `/api/builds/`:
101100
102101### Calling the APIs
103102
104- For simple use cases, you may use the companion instance ( [ DefaultInstance ] [ 23 ] ) directly, as if
105- calling static methods :
103+ API methods are generated as suspend functions.
104+ For most cases like scripts and notebooks, simply use [ runBlocking ] [ 30 ] :
106105
107106``` kotlin
108- GradleEnterpriseApi .buildsApi.getBuilds(since = yesterdayMilli)
107+ runBlocking {
108+ val builds: List <Build > = api.buildsApi.getBuilds(since = yesterdayMilli)
109+ }
109110```
110111
111112It's recommended to call [ ` GradleEnterpriseApi.shutdown() ` ] [ 11 ] at the end of scripts to release
@@ -130,7 +131,7 @@ also takes care of paging under-the-hood, returning a [`Flow`][26] of all builds
130131date, so you don't have to worry about the REST API's limit of 1000 builds per request:
131132
132133``` kotlin
133- val builds = GradleEnterpriseApi .buildsApi.getGradleAttributesFlow(since = lastYear)
134+ val builds: Flow < GradleAttributes > = api .buildsApi.getGradleAttributesFlow(since = lastYear)
134135builds.collect {
135136 // ...
136137}
@@ -189,7 +190,7 @@ import com.gabrielfeo.gradle.enterprise.api.model.extension.*
189190[ 11 ] : https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-gradle-enterprise-api/shutdown.html
190191[ 12 ] : https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/-cache-config/cache-enabled.html
191192[ 13 ] : https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/-cache-config/index.html
192- [ 14 ] : https://central.sonatype.com/artifact/com.gabrielfeo/gradle-enterprise-api-kotlin/0.16.2
193+ [ 14 ] : https://central.sonatype.com/artifact/com.gabrielfeo/gradle-enterprise-api-kotlin/0.17.0
193194[ 16 ] : https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/api-url.html
194195[ 17 ] : https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-config/api-token.html
195196[ 18 ] : https://gabrielfeo.github.io/gradle-enterprise-api-kotlin/library/com.gabrielfeo.gradle.enterprise.api/-builds-api/index.html
@@ -204,3 +205,4 @@ import com.gabrielfeo.gradle.enterprise.api.model.extension.*
204205[ 27 ] : ./examples/example-script.main.kts
205206[ 28 ] : ./examples/example-project
206207[ 29 ] : https://nbviewer.org/github/gabrielfeo/gradle-enterprise-api-kotlin/blob/main/examples/example-notebooks/MostFrequentBuilds.ipynb
208+ [ 30 ] : https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/run-blocking.html
0 commit comments