Skip to content

Commit dd498ba

Browse files
authored
Merge pull request #29 from GradleUp/rearchitecture
Split the plugin in 2
2 parents 4c408b7 + 066ead4 commit dd498ba

27 files changed

Lines changed: 487 additions & 645 deletions

.github/workflows/pull_request.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ jobs:
1616
- uses: actions/checkout@v3
1717
- run: |
1818
./gradlew build
19-
./gradlew -p tests/kmp build
19+
./gradlew -p tests/jvm zipAggregation --configuration-cache
2020
./gradlew -p tests/jvm build
21+
./gradlew -p tests/kmp publishAggregationToCentralPortal --configuration-cache
22+
./gradlew -p tests/kmp build

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Split the plugin in 2 separate plugins:
2+
3+
- `com.gradleup.nmcp` creates a `zip${publicationName.capitalized()}Publication` and `publish${publicationName.capitalized()}PublicationToCentralPortal` task for each publication
4+
- `publish${publicationName.capitalized()}PublicationToCentralPortal` can be used to publish an individual publication to the central portal. If using this, you need to configure the `centralPortal {}` block.
5+
- The output of `zip${publicationName.capitalized()}Publication` is registered as an outgoing artifact so that the aggregation plugin can collect the files from all projects.
6+
- `com.gradleup.nmcp.aggregation` can aggregate all zips from several projects and upload them in a single deployment to the central portal.
7+
8+
## Other changes:
9+
10+
- The default `publicationType` is now `"AUTOMATIC"`, make sure to set it to `"USER_MANAGED"` if you want to manually confirm releases.
11+
- `NmcpSpec.endpoint` is replaced by `NmcpSpec.baseUrl`.
12+
- `NmcpSpec.publicationType` is renamed `NmcpSpec.publishingType`.

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,35 @@ Configure `nmcp` in your root project using the quick way:
2020
```kotlin
2121
// root/build.gradle[.kts]
2222
plugins {
23-
id("com.gradleup.nmcp").version("0.0.8")
23+
id("com.gradleup.nmcp.aggregation").version("0.0.8")
2424
}
2525

2626
nmcp {
27-
publishAllProjectsProbablyBreakingProjectIsolation {
27+
centralPortal {
2828
username = TODO()
2929
password = TODO()
3030
// publish manually from the portal
3131
publicationType = "USER_MANAGED"
3232
// or if you want to publish automatically
3333
publicationType = "AUTOMATIC"
3434
}
35+
36+
// Publish all projects that apply the 'maven-publish' plugin
37+
publishAllProjectsProbablyBreakingProjectIsolation()
3538
}
3639
```
3740

38-
Then call `publishAllPublicationsToCentralPortal` to publish all your publications:
41+
Call `publishAggregationCentralPortal` to publish the aggregation:
3942

4043
```
41-
./gradlew publishAllPublicationsToCentralPortal
44+
./gradlew publishAggregationCentralPortal
4245
# yay everything is uploaded 🎉
4346
# go to https://central.sonatype.com/ to release if you used USER_MANAGED
4447
```
4548

4649
# Project isolation compatible version:
4750

48-
`publishAllProjectsProbablyBreakingProjectIsolation` uses the `allprojects {}` block and might be incompatible with [Project-isolation](https://gradle.github.io/configuration-cache/).
51+
`publishAllProjectsProbablyBreakingProjectIsolation` uses the `allprojects {}` block and is incompatible with [Project-isolation](https://gradle.github.io/configuration-cache/).
4952

5053
You can be 100% compatible by adding the plugin to each module you want to publish:
5154

@@ -54,22 +57,18 @@ You can be 100% compatible by adding the plugin to each module you want to publi
5457
plugins {
5558
id("com.gradleup.nmcp").version("0.0.8")
5659
}
57-
58-
nmcp {
59-
publishAllPublications {}
60-
}
6160
```
6261

6362
And then list all modules in your root project:
6463

6564
```kotlin
6665
//root/build.gradle.kts
6766
plugins {
68-
id("com.gradleup.nmcp").version("0.0.8")
67+
id("com.gradleup.nmcp.aggregation").version("0.0.8")
6968
}
7069

7170
nmcp {
72-
publishAggregation {
71+
centralPortal {
7372
project(":module1")
7473
project(":module2")
7574
project(":module3")
@@ -81,10 +80,10 @@ nmcp {
8180
}
8281
```
8382

84-
Then call `publishAggregatedPublicationToCentralPortal` to publish the aggregated publication:
83+
Then call `publishAggregationToCentralPortal` to publish the aggregation:
8584

8685
```
87-
./gradlew publishAggregatedPublicationToCentralPortal
86+
./gradlew publishAggregationToCentralPortal
8887
# yay everything is uploaded 🎉
8988
# go to https://central.sonatype.com/ to release if you used USER_MANAGED
9089
```
@@ -93,14 +92,14 @@ Then call `publishAggregatedPublicationToCentralPortal` to publish the aggregate
9392

9493
```kotlin
9594
plugins {
95+
id("maven-publish")
9696
id("com.gradleup.nmcp").version("0.0.8")
9797
}
9898

9999
// Create your publications
100100

101101
nmcp {
102-
// nameOfYourPublication must point to an existing publication
103-
publish(nameOfYourPublication) {
102+
centralPortal {
104103
username = TODO("Create a token at https://central.sonatype.com/account")
105104
password = TODO("Create a token at https://central.sonatype.com/account")
106105
// publish manually from the portal
@@ -110,3 +109,13 @@ nmcp {
110109
}
111110
}
112111
```
112+
113+
`nmcp` creates a `"publish${publicationName.capitalize()}PublicationToCentralPortal"` task for each Maven publication.
114+
115+
There is also a lifecycle task to deploy all the publication to the central portal:
116+
117+
```
118+
./gradlew publishAllPublicationsToCentralPortal
119+
# yay everything is uploaded 🎉
120+
# go to https://central.sonatype.com/ to release if you used USER_MANAGED
121+
```

build.gradle.kts

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,12 @@ import java.net.URI
22

33
plugins {
44
alias(libs.plugins.kgp)
5-
id("java-gradle-plugin")
5+
alias(libs.plugins.ksp)
6+
alias(libs.plugins.ggp)
67
id("maven-publish")
78
id("signing")
89
}
910

10-
val pluginDescription = "Plugin that helps you publish to the Central Portal (https://central.sonatype.org/)"
11-
12-
gradlePlugin {
13-
plugins {
14-
create("nmcp") {
15-
id = "com.gradleup.nmcp"
16-
implementationClass = "nmcp.NmcpPlugin"
17-
this.description = pluginDescription
18-
this.displayName = "nmcp"
19-
}
20-
}
21-
}
22-
2311
group = "com.gradleup.nmcp"
2412
version = "0.0.8"
2513

@@ -36,26 +24,21 @@ publishing {
3624
}
3725
}
3826
}
27+
publications.create("default", MavenPublication::class.java) {
28+
from(components.getByName("java"))
29+
artifact(tasks.register("emptySources", Jar::class.java) {
30+
archiveClassifier = "sources"
31+
})
32+
artifact(tasks.register("emptyDocs", Jar::class.java) {
33+
archiveClassifier = "javadoc"
34+
})
35+
}
36+
3937
publications.configureEach {
4038
this as MavenPublication
41-
if (name == "pluginMaven") {
42-
val emptySources by tasks.registering(Jar::class) {
43-
archiveClassifier = "sources"
44-
}
45-
val emptyDocs by tasks.registering(Jar::class) {
46-
archiveClassifier = "javadoc"
47-
}
48-
artifact(emptySources)
49-
artifact(emptyDocs)
50-
51-
groupId = project.rootProject.group.toString()
52-
version = project.rootProject.version.toString()
53-
artifactId = project.name
54-
}
55-
5639
pom {
5740
name.set(project.name)
58-
description.set(pluginDescription)
41+
description.set("NMCP")
5942
url.set("https://github.com/gradleup/nmcp")
6043

6144
scm {
@@ -87,12 +70,17 @@ signing {
8770
useInMemoryPgpKeys(System.getenv("GPG_KEY"), System.getenv("GPG_KEY_PASSWORD"))
8871
}
8972

73+
gratatouille {
74+
codeGeneration()
75+
pluginMarker("com.gradleup.nmcp")
76+
}
9077

9178
dependencies {
9279
implementation(libs.json)
9380
implementation(libs.okio)
9481
implementation(libs.okhttp)
9582
implementation(libs.okhttp.logging.interceptor)
83+
compileOnly(libs.gradle.min)
9684
}
9785

9886
tasks.withType<AbstractPublishToMaven>().configureEach {

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
[versions]
22
kgp = "2.1.20"
3+
ksp = "2.1.20-2.0.0"
34

45
[libraries]
56
json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1"
67
okio = "com.squareup.okio:okio:3.8.0"
78
okhttp = "com.squareup.okhttp3:okhttp:4.12.0"
89
okhttp-logging-interceptor = "com.squareup.okhttp3:logging-interceptor:4.12.0"
910
mockwebserver = "com.squareup.okhttp3:mockwebserver:4.12.0"
11+
gradle-min = "dev.gradleplugins:gradle-api:8.0"
12+
1013
[plugins]
1114
kgp = { id = "org.jetbrains.kotlin.jvm", version.ref = "kgp" }
15+
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
16+
ggp = { id = "com.gradleup.gratatouille", version = "0.0.6-SNAPSHOT-b6a9df610d12e3bbd5066d4bb8f6d640efcc0ca5" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pluginManagement {
55
).forEach {
66
it.apply {
77
mavenCentral()
8+
maven("https://storage.googleapis.com/gradleup/m2")
89
}
910
}
1011
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package nmcp
2+
3+
import java.time.Duration
4+
import org.gradle.api.provider.Property
5+
6+
abstract class CentralPortalOptions {
7+
/**
8+
* The central portal username
9+
*/
10+
abstract val username: Property<String>
11+
12+
/**
13+
* The central portal password
14+
*/
15+
abstract val password: Property<String>
16+
17+
/**
18+
* The publication type (optional).
19+
* One of:
20+
* - "AUTOMATIC": the deployment is automatically published.
21+
* - "USER_MANAGED": the deployment is validated but not published. It must be published manually from the Central Portal UI.
22+
*
23+
* Default: AUTOMATIC
24+
*/
25+
abstract val publishingType: Property<String>
26+
27+
/**
28+
* A name for the publication (optional).
29+
*
30+
* Default: "${project.name}-${project.version}.zip"
31+
*/
32+
abstract val publicationName: Property<String>
33+
34+
/**
35+
* After a deployment has been uploaded, the central portal verifies that it matches the
36+
* maven central requirements, which may take some time.
37+
*
38+
* After waiting, the deployment is either:
39+
* - VALIDATED: it needs to be manually published in the Central Portal UI.
40+
* - PUBLISHED: it is published and available on Maven Central.
41+
* - FAILED: the deployment has failed. You
42+
*
43+
* [verificationTimeout] specifies what duration to wait for the verification to complete.
44+
* You may pass the special value '0' to disable waiting for verification altogether.
45+
*
46+
* Default: 10 minutes.
47+
*/
48+
abstract val verificationTimeout: Property<Duration>
49+
50+
/**
51+
* The API endpoint to use (optional).
52+
*
53+
* Default: "https://central.sonatype.com/".
54+
*/
55+
abstract val baseUrl: Property<String>
56+
}

src/main/kotlin/nmcp/NmcpAggregation.kt

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)