Skip to content

Commit b257d47

Browse files
authored
Refactor build logic (#301)
- Move specific logic, such as applying a convention plugin, out of the example buildscript - Move some publishing, dokka and binary compatibility validator setup to a new "published library" conventions plugin. This simplifies the `:library` buildscript and removes unused configuration from `:examples:example-project` - Use new Kotlin DSL property set syntax Tested with a `check` build: https://scans.gradle.com/s/q34f6ap23bgf2
1 parent f30181b commit b257d47

File tree

7 files changed

+119
-120
lines changed

7 files changed

+119
-120
lines changed

build-logic/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ plugins {
66

77
java {
88
toolchain {
9-
languageVersion.set(JavaLanguageVersion.of(11))
10-
vendor.set(JvmVendorSpec.AZUL)
9+
languageVersion = JavaLanguageVersion.of(11)
10+
vendor = JvmVendorSpec.AZUL
1111
}
1212
}
1313

build-logic/src/main/kotlin/com/gabrielfeo/develocity-api-code-generation.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ val downloadApiSpec by tasks.registering {
3434
}
3535

3636
openApiGenerate {
37-
generatorName.set("kotlin")
37+
generatorName = "kotlin"
3838
val spec = when {
3939
localSpecPath.isPresent() -> localSpecPath.map { rootProject.file(it).absolutePath }
4040
else -> downloadApiSpec.map { it.outputs.files.first().absolutePath }
4141
}
42-
inputSpec.set(spec)
42+
inputSpec = spec
4343
val generateDir = project.layout.buildDirectory.dir("generated-api")
4444
.map { it.asFile.absolutePath }
45-
outputDir.set(generateDir)
45+
outputDir = generateDir
4646
val ignoreFile = project.layout.projectDirectory.file(".openapi-generator-ignore")
47-
ignoreFileOverride.set(ignoreFile.asFile.absolutePath)
48-
apiPackage.set("com.gabrielfeo.develocity.api")
49-
modelPackage.set("com.gabrielfeo.develocity.api.model")
50-
packageName.set("com.gabrielfeo.develocity.api.internal")
51-
invokerPackage.set("com.gabrielfeo.develocity.api.internal")
47+
ignoreFileOverride = ignoreFile.asFile.absolutePath
48+
apiPackage = "com.gabrielfeo.develocity.api"
49+
modelPackage = "com.gabrielfeo.develocity.api.model"
50+
packageName = "com.gabrielfeo.develocity.api.internal"
51+
invokerPackage = "com.gabrielfeo.develocity.api.internal"
5252
additionalProperties.put("library", "jvm-retrofit2")
5353
additionalProperties.put("useCoroutines", true)
5454
additionalProperties.put("enumPropertyNaming", "camelCase")
55-
cleanupOutput.set(true)
55+
cleanupOutput = true
5656
}
5757

5858
val postProcessGeneratedApi by tasks.registering(PostProcessGeneratedApi::class) {
Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,16 @@
11
package com.gabrielfeo
22

3-
import org.jetbrains.dokka.DokkaConfiguration.Visibility.PUBLIC
4-
import org.jetbrains.dokka.gradle.DokkaTask
5-
import java.net.URL
6-
73
plugins {
84
id("org.jetbrains.kotlin.jvm")
9-
id("org.jetbrains.dokka")
10-
id("org.jetbrains.kotlinx.binary-compatibility-validator")
115
`java-library`
126
}
137

14-
val repoUrl: Provider<String> = providers.gradleProperty("repo.url")
15-
168
java {
17-
withSourcesJar()
18-
withJavadocJar()
199
toolchain {
20-
languageVersion.set(JavaLanguageVersion.of(11))
21-
vendor.set(JvmVendorSpec.AZUL)
10+
languageVersion = JavaLanguageVersion.of(11)
11+
vendor = JvmVendorSpec.AZUL
2212
}
23-
}
24-
25-
val kotlinSourceRoot = file("src/main/kotlin")
26-
tasks.withType<DokkaTask>().configureEach {
27-
dokkaSourceSets.all {
28-
sourceRoot(kotlinSourceRoot)
29-
sourceLink {
30-
localDirectory.set(kotlinSourceRoot)
31-
remoteUrl.set(repoUrl.map { URL("$it/blob/$version/${kotlinSourceRoot.relativeTo(rootDir)}") })
32-
remoteLineSuffix.set("#L")
33-
}
34-
jdkVersion.set(11)
35-
suppressGeneratedFiles.set(false)
36-
documentedVisibilities.set(setOf(PUBLIC))
37-
perPackageOption {
38-
matchingRegex.set(""".*\.internal.*""")
39-
suppress.set(true)
40-
}
41-
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
42-
externalDocumentationLink("https://square.github.io/okhttp/4.x/okhttp/")
43-
externalDocumentationLink("https://square.github.io/retrofit/2.x/retrofit/")
44-
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi/")
45-
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi-kotlin/")
13+
consistentResolution {
14+
useRuntimeClasspathVersions()
4615
}
4716
}
48-
49-
tasks.named<Jar>("javadocJar") {
50-
from(tasks.dokkaHtml)
51-
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.gabrielfeo
2+
3+
import org.jetbrains.dokka.DokkaConfiguration.Visibility.PUBLIC
4+
import org.jetbrains.dokka.gradle.DokkaTask
5+
import java.net.URL
6+
7+
plugins {
8+
id("com.gabrielfeo.kotlin-jvm-library")
9+
`java-library`
10+
`maven-publish`
11+
signing
12+
id("org.jetbrains.kotlinx.binary-compatibility-validator")
13+
id("org.jetbrains.dokka")
14+
}
15+
16+
java {
17+
withSourcesJar()
18+
withJavadocJar()
19+
}
20+
21+
val kotlinSourceRoot = file("src/main/kotlin")
22+
tasks.withType<DokkaTask>().configureEach {
23+
dokkaSourceSets.all {
24+
sourceRoot(kotlinSourceRoot)
25+
sourceLink {
26+
localDirectory = kotlinSourceRoot
27+
remoteUrl = providers.gradleProperty("repo.url")
28+
.map { URL("$it/blob/$version/${kotlinSourceRoot.relativeTo(rootDir)}") }
29+
remoteLineSuffix = "#L"
30+
}
31+
jdkVersion = java.toolchain.languageVersion.map { it.asInt() }
32+
suppressGeneratedFiles = false
33+
documentedVisibilities = setOf(PUBLIC)
34+
perPackageOption {
35+
matchingRegex = """.*\.internal.*"""
36+
suppress = true
37+
}
38+
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
39+
externalDocumentationLink("https://square.github.io/okhttp/5.x/okhttp/")
40+
externalDocumentationLink("https://square.github.io/retrofit/2.x/retrofit/")
41+
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi/")
42+
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi-kotlin/")
43+
}
44+
}
45+
46+
tasks.named<Jar>("javadocJar") {
47+
from(tasks.dokkaHtml)
48+
}
49+
50+
publishing {
51+
repositories {
52+
maven {
53+
name = "mavenCentral"
54+
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
55+
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
56+
val isSnapshot = version.toString().endsWith("SNAPSHOT")
57+
url = if (isSnapshot) snapshotsRepoUrl else releasesRepoUrl
58+
authentication {
59+
register<BasicAuthentication>("basic")
60+
}
61+
credentials {
62+
username = project.properties["maven.central.username"] as String?
63+
password = project.properties["maven.central.password"] as String?
64+
}
65+
}
66+
}
67+
}
68+
69+
fun isCI() = System.getenv("CI").toBoolean()
70+
71+
signing {
72+
val signedPublications = publishing.publications.matching {
73+
!it.name.contains("unsigned", ignoreCase = true)
74+
}
75+
sign(signedPublications)
76+
if (isCI()) {
77+
useInMemoryPgpKeys(
78+
project.properties["signing.secretKey"] as String?,
79+
project.properties["signing.password"] as String?,
80+
)
81+
}
82+
}

examples/build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ plugins {
55
}
66

77
// Cross-configure so we don't pollute the example buildscript
8-
project("example-project").configurations.configureEach {
9-
resolutionStrategy.dependencySubstitution {
10-
substitute(module("com.gabrielfeo:develocity-api-kotlin"))
11-
.using(project(":library"))
8+
project("example-project") {
9+
apply(plugin = "com.gabrielfeo.kotlin-jvm-library")
10+
configurations.configureEach {
11+
resolutionStrategy.dependencySubstitution {
12+
substitute(module("com.gabrielfeo:develocity-api-kotlin"))
13+
.using(project(":library"))
14+
}
1215
}
1316
}
1417

examples/example-project/build.gradle.kts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
plugins {
2-
// in your project, replace for id("org.jetbrains.kotlin.jvm")
3-
id("com.gabrielfeo.kotlin-jvm-library")
2+
id("org.jetbrains.kotlin.jvm")
43
application
54
}
65

76
application {
8-
mainClass.set("com.gabrielfeo.develocity.api.example.MainKt")
9-
}
10-
11-
java {
12-
toolchain {
13-
languageVersion.set(JavaLanguageVersion.of(11))
14-
}
7+
mainClass = "com.gabrielfeo.develocity.api.example.MainKt"
158
}
169

1710
dependencies {

library/build.gradle.kts

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
@file:Suppress("UnstableApiUsage")
2-
3-
import java.net.URL
4-
51
plugins {
6-
id("com.gabrielfeo.kotlin-jvm-library")
2+
id("com.gabrielfeo.published-kotlin-jvm-library")
73
id("com.gabrielfeo.develocity-api-code-generation")
84
id("com.gabrielfeo.test-suites")
9-
`java-library`
10-
`maven-publish`
11-
signing
125
alias(libs.plugins.kotlin.jupyter)
136
}
147

@@ -22,12 +15,6 @@ tasks.named<Test>("integrationTest") {
2215
environment("DEVELOCITY_API_LOG_LEVEL", "DEBUG")
2316
}
2417

25-
java {
26-
consistentResolution {
27-
useRuntimeClasspathVersions()
28-
}
29-
}
30-
3118
dependencies {
3219
constraints {
3320
implementation(libs.okio)
@@ -52,29 +39,29 @@ dependencies {
5239
}
5340

5441
val libraryPom = Action<MavenPom> {
55-
name.set("Develocity API Kotlin")
56-
description.set("A library to use the Develocity API in Kotlin")
42+
name = "Develocity API Kotlin"
43+
description = "A library to use the Develocity API in Kotlin"
5744
val repoUrl = providers.gradleProperty("repo.url")
58-
url.set(repoUrl)
45+
url = repoUrl
5946
licenses {
6047
license {
61-
name.set("MIT")
62-
url.set("https://spdx.org/licenses/MIT.html")
63-
distribution.set("repo")
48+
name = "MIT"
49+
url = "https://spdx.org/licenses/MIT.html"
50+
distribution = "repo"
6451
}
6552
}
6653
developers {
6754
developer {
68-
id.set("gabrielfeo")
69-
name.set("Gabriel Feo")
70-
email.set("gabriel@gabrielfeo.com")
55+
id = "gabrielfeo"
56+
name = "Gabriel Feo"
57+
email = "gabriel@gabrielfeo.com"
7158
}
7259
}
7360
scm {
7461
val basicUrl = repoUrl.map { it.substringAfter("://") }
75-
connection.set(basicUrl.map { "scm:git:git://$it.git" })
76-
developerConnection.set(basicUrl.map { "scm:git:ssh://$it.git" })
77-
url.set(basicUrl.map { "https://$it/" })
62+
connection = basicUrl.map { "scm:git:git://$it.git" }
63+
developerConnection = basicUrl.map { "scm:git:ssh://$it.git" }
64+
url = basicUrl.map { "https://$it/" }
7865
}
7966
}
8067

@@ -105,35 +92,4 @@ publishing {
10592
}
10693
}
10794
}
108-
repositories {
109-
maven {
110-
name = "mavenCentral"
111-
val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
112-
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
113-
val isSnapshot = version.toString().endsWith("SNAPSHOT")
114-
url = if (isSnapshot) snapshotsRepoUrl else releasesRepoUrl
115-
authentication {
116-
register<BasicAuthentication>("basic")
117-
}
118-
credentials {
119-
username = project.properties["maven.central.username"] as String?
120-
password = project.properties["maven.central.password"] as String?
121-
}
122-
}
123-
}
124-
}
125-
126-
fun isCI() = System.getenv("CI").toBoolean()
127-
128-
signing {
129-
val signedPublications = publishing.publications.matching {
130-
!it.name.contains("unsigned", ignoreCase = true)
131-
}
132-
sign(signedPublications)
133-
if (isCI()) {
134-
useInMemoryPgpKeys(
135-
project.properties["signing.secretKey"] as String?,
136-
project.properties["signing.password"] as String?,
137-
)
138-
}
13995
}

0 commit comments

Comments
 (0)