Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1fa7ecd
wip
martinbonnin Apr 19, 2025
281fa66
Split the plugin in 2
martinbonnin Apr 21, 2025
87d59e6
update CHANGELOG
martinbonnin Apr 21, 2025
7ac3e89
remove leftovers
martinbonnin Apr 21, 2025
ac9d7db
Remove the plugin boilerplate
martinbonnin Apr 21, 2025
05d0ea0
tweak error message, thanks @vlsi!
martinbonnin Apr 21, 2025
7c30fe3
put smaller code first
martinbonnin Apr 21, 2025
79fe2c9
tweak message
martinbonnin Apr 21, 2025
1d43f45
fix wording
martinbonnin Apr 21, 2025
6f0706b
Remove verifyStatus
martinbonnin Apr 22, 2025
4e7a93d
remove useless code
martinbonnin Apr 22, 2025
3b41d9e
Use aggregation consistently
martinbonnin Apr 22, 2025
8234974
remove unused class
martinbonnin Apr 22, 2025
f063a3f
Update src/main/kotlin/nmcp/internal/task/publish.kt
martinbonnin Apr 22, 2025
baf5bb2
Update src/main/kotlin/nmcp/internal/task/publish.kt
martinbonnin Apr 22, 2025
adb9d56
Update src/main/kotlin/nmcp/internal/task/publish.kt
martinbonnin Apr 22, 2025
9a15ce7
Merge branch 'main' into rearchitecture
martinbonnin Apr 22, 2025
6dde059
unbreak tests
martinbonnin Apr 22, 2025
95fe190
NmcpSpec -> CentralPortalOptions
martinbonnin Apr 22, 2025
424ef0b
Update src/main/kotlin/nmcp/NmcpExtension.kt
martinbonnin Apr 22, 2025
de6e2e5
configuration cache
martinbonnin Apr 22, 2025
7f3279b
missing parenthesis
martinbonnin Apr 22, 2025
2504216
unbreak tests
martinbonnin Apr 22, 2025
7cdaf30
format
martinbonnin Apr 24, 2025
066ead4
Merge branch 'main' into rearchitecture
martinbonnin Apr 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Split the plugin in 2 separate plugins:

- `com.gradleup.nmcp` creates a `zip${publicationName.capitalized()}Publication` and `publish${publicationName.capitalized()}PublicationToCentralPortal` task for each publication
- `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.
- 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.
- `com.gradleup.nmcp.aggregation` can aggregate all zips from several projects and upload them in a single deployment to the central portal.

## Other changes:

- The default `publicationType` is now `"AUTOMATIC"`, make sure to set it to `"USER_MANAGED"` if you want to manually confirm releases.
- `NmcpSpec.endpoint` is replaced by `NmcpSpec.baseUrl`.
- `NmcpSpec.publicationType` is renamed `NmcpSpec.publishingType`.
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,35 @@ Configure `nmcp` in your root project using the quick way:
```kotlin
// root/build.gradle[.kts]
plugins {
id("com.gradleup.nmcp").version("0.0.8")
id("com.gradleup.nmcp.aggregation").version("0.0.8")
}

nmcp {
publishAllProjectsProbablyBreakingProjectIsolation {
centralPortal {
username = TODO()
password = TODO()
// publish manually from the portal
publicationType = "USER_MANAGED"
// or if you want to publish automatically
publicationType = "AUTOMATIC"
}

// Publish all projects that apply the 'maven-publish' plugin
publishAllProjectsProbablyBreakingProjectIsolation()
}
```

Then call `publishAllPublicationsToCentralPortal` to publish all your publications:
Call `publishAggregatedPublicationToCentralPortal` to publish the aggregated publication:

```
./gradlew publishAllPublicationsToCentralPortal
./gradlew publishAggregatedPublicationToCentralPortal
# yay everything is uploaded 🎉
# go to https://central.sonatype.com/ to release if you used USER_MANAGED
```

# Project isolation compatible version:

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

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

Expand All @@ -54,22 +57,18 @@ You can be 100% compatible by adding the plugin to each module you want to publi
plugins {
id("com.gradleup.nmcp").version("0.0.8")
}

nmcp {
publishAllPublications {}
}
```

And then list all modules in your root project:

```kotlin
//root/build.gradle.kts
plugins {
id("com.gradleup.nmcp").version("0.0.8")
id("com.gradleup.nmcp.aggregation").version("0.0.8")
}

nmcp {
publishAggregation {
centralPortal {
project(":module1")
project(":module2")
project(":module3")
Expand All @@ -93,14 +92,14 @@ Then call `publishAggregatedPublicationToCentralPortal` to publish the aggregate

```kotlin
plugins {
id("maven-publish")
id("com.gradleup.nmcp").version("0.0.8")
}

// Create your publications

nmcp {
// nameOfYourPublication must point to an existing publication
publish(nameOfYourPublication) {
centralPortal {
username = TODO("Create a token at https://central.sonatype.com/account")
password = TODO("Create a token at https://central.sonatype.com/account")
// publish manually from the portal
Expand All @@ -110,3 +109,13 @@ nmcp {
}
}
```

`nmcp` creates a `"publish${publicationName.capitalize()}PublicationToCentralPortal"` task for each Maven publication.

There is also a lifecycle task to deploy all the publication to the central portal:

```
./gradlew publishAllPublicationsToCentralPortal
# yay everything is uploaded 🎉
# go to https://central.sonatype.com/ to release if you used USER_MANAGED
```
49 changes: 22 additions & 27 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,12 @@ import java.net.URI

plugins {
alias(libs.plugins.kgp)
id("java-gradle-plugin")
alias(libs.plugins.ksp)
alias(libs.plugins.ggp)
id("maven-publish")
id("signing")
}

val pluginDescription = "Plugin that helps you publish to the Central Portal (https://central.sonatype.org/)"

gradlePlugin {
plugins {
create("nmcp") {
id = "com.gradleup.nmcp"
implementationClass = "nmcp.NmcpPlugin"
this.description = pluginDescription
this.displayName = "nmcp"
}
}
}

group = "com.gradleup.nmcp"
version = "0.0.8"

Expand All @@ -36,24 +24,26 @@ publishing {
}
}
}
publications.create("default", MavenPublication::class.java) {
from(components.getByName("java"))
artifact(tasks.register("emptySources", Jar::class.java) {
archiveClassifier = "sources"
})
artifact(tasks.register("emptyDocs", Jar::class.java) {
archiveClassifier = "javadoc"
})

groupId = project.rootProject.group.toString()
version = project.rootProject.version.toString()
artifactId = project.name
}

publications.configureEach {
this as MavenPublication
if (name == "pluginMaven") {
artifact(tasks.register("emptySources", Jar::class.java) {
archiveClassifier = "sources"
})
artifact(tasks.register("emptyDocs", Jar::class.java) {
archiveClassifier = "javadoc"
})

groupId = project.rootProject.group.toString()
version = project.rootProject.version.toString()
artifactId = project.name
}

pom {
name.set(project.name)
description.set(pluginDescription)
description.set("NMCP")
url.set("https://github.com/gradleup/nmcp")

scm {
Expand Down Expand Up @@ -85,12 +75,17 @@ signing {
useInMemoryPgpKeys(System.getenv("GPG_KEY"), System.getenv("GPG_KEY_PASSWORD"))
}

gratatouille {
codeGeneration()
pluginMarker("com.gradleup.nmcp")
}

dependencies {
implementation(libs.json)
implementation(libs.okio)
implementation(libs.okhttp)
implementation(libs.okhttp.logging.interceptor)
compileOnly(libs.gradle.min)
}

tasks.withType<AbstractPublishToMaven>().configureEach {
Expand Down
7 changes: 6 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[versions]
kgp = "2.1.20"
ksp = "2.1.20-2.0.0"

[libraries]
json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1"
okio = "com.squareup.okio:okio:3.8.0"
okhttp = "com.squareup.okhttp3:okhttp:4.12.0"
okhttp-logging-interceptor = "com.squareup.okhttp3:logging-interceptor:4.12.0"
mockwebserver = "com.squareup.okhttp3:mockwebserver:4.12.0"
gradle-min = "dev.gradleplugins:gradle-api:8.0"

[plugins]
kgp = { id = "org.jetbrains.kotlin.jvm", version.ref = "kgp" }
kgp = { id = "org.jetbrains.kotlin.jvm", version.ref = "kgp" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ggp = { id = "com.gradleup.gratatouille", version = "0.0.6-SNAPSHOT-b6a9df610d12e3bbd5066d4bb8f6d640efcc0ca5" }
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
mavenCentral()
maven("https://storage.googleapis.com/gradleup/m2")
}
}
}
}
62 changes: 0 additions & 62 deletions src/main/kotlin/nmcp/NmcpAggregation.kt

This file was deleted.

71 changes: 71 additions & 0 deletions src/main/kotlin/nmcp/NmcpAggregationExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package nmcp

import gratatouille.GExtension
import nmcp.internal.configureAttributes
import nmcp.internal.nmcpConsumerConfigurationName
import nmcp.internal.task.registerPublishTask
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Zip

@GExtension(pluginId = "com.gradleup.nmcp.aggregation")
open class NmcpAggregationExtension(private val project: Project) {
internal val spec = project.objects.newInstance(NmcpSpec::class.java)

internal val consumerConfiguration = project.configurations.create(nmcpConsumerConfigurationName) {
it.isCanBeResolved = true
it.isCanBeConsumed = false

it.configureAttributes(project)
}

val zipTaskProvider = project.tasks.register("zipAggregationPublication", Zip::class.java) {
it.archiveFileName.set("publicationAggregated.zip")
it.destinationDirectory.set(project.layout.buildDirectory.dir("nmcp/zip"))
it.from(consumerConfiguration.elements.map {
check (it.isNotEmpty()) {
"nmcp: aggregation is empty. Make sure to create publications in sub-projects and specify projects to publish by adding them to the 'nmcpAggregation' configuration."
}
it.map {
project.zipTree(it)
}
})
}

init {
project.registerPublishTask(
taskName = "publishAggregatedPublicationToCentralPortal",
inputFile = zipTaskProvider.flatMap { it.archiveFile },
spec = spec
)
}

/**
* Configures the central portal parameters
*/
fun centralPortal(action: Action<NmcpSpec>) {
action.execute(spec)
}

/**
* Applies the `com.gradleup.nmcp` plugin to every project that also applies `maven-publish` and adds the
* `publishAggregatedPublicationToCentralPortal` task to publish a bundle containing all projects.
*
* This is breaking project isolation
*/
fun publishAllProjectsProbablyBreakingProjectIsolation() {
check(project === project.rootProject) {
"publishAllProjectsProbablyBreakingProjectIsolation() must be called from root project"
}

project.allprojects { aproject ->
aproject.pluginManager.withPlugin("maven-publish") {
aproject.pluginManager.apply("com.gradleup.nmcp")

consumerConfiguration.dependencies.add(aproject.dependencies.create(aproject))
}
}
}
}


Loading