Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions docs/src/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ nmcpSettings {

// optional: send publications serially instead of in parallel (might be slower)
uploadSnapshotsParallelism.set(1)

// optional: publish all checksums (md5, sha1, sha256, sha512, including for signature files)
publishAllChecksums.set(true)
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion librarian.root.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kdoc.olderVersions=
kdoc.artifactId=kdoc

pom.groupId=com.gradleup.nmcp
pom.version=1.5.1-SNAPSHOT
pom.version=1.6.0-SNAPSHOT
pom.description=New Maven Central Publishing
pom.vcsUrl=https://github.com/gradleup/nmcp
pom.developer=nmcp authors
Expand Down
1 change: 1 addition & 0 deletions nmcp/api/nmcp.api
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract interface class nmcp/NmcpAggregationExtension {
public abstract fun getAllFiles ()Lorg/gradle/api/file/FileCollection;
public abstract fun getAllowDuplicateProjectNames ()Lorg/gradle/api/provider/Property;
public abstract fun getAllowEmptyAggregation ()Lorg/gradle/api/provider/Property;
public abstract fun getPublishAllChecksums ()Lorg/gradle/api/provider/Property;
public abstract fun localRepository (Lorg/gradle/api/Action;)V
public abstract fun publishAllProjectsProbablyBreakingProjectIsolation ()V
}
Expand Down
10 changes: 10 additions & 0 deletions nmcp/src/main/kotlin/nmcp/NmcpAggregationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ interface NmcpAggregationExtension {
* See https://github.com/gradle/gradle/issues/36167 for more details.
*/
val allowDuplicateProjectNames: Property<Boolean>

/**
* By default, Nmcp tries to avoid publishing the checksums.
* Especially, it filters out the `.sha256` and `.sha512` files, as well as all the signature checksums
* (`.asc.md5`, `.asc.sha1`, `.asc.sha256`, `.asc.sha512`).
* This is to play nicer with [Maven Central publishing limits](https://central.sonatype.org/publish/maven-central-publishing-limits/).
*
* Default: false
*/
val publishAllChecksums: Property<Boolean>
}
1 change: 1 addition & 0 deletions nmcp/src/main/kotlin/nmcp/NmcpExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nmcp

import org.gradle.api.Action
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Property

interface NmcpExtension {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import org.gradle.api.artifacts.result.ArtifactResult
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.gradle.api.attributes.Usage
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider

@GExtension(
pluginId = "com.gradleup.nmcp.aggregation",
Expand All @@ -32,6 +35,8 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro

override val allFiles: ConfigurableFileCollection = project.files()

private val zipProvider: Provider<RegularFile>

init {
allFiles.from(
consumerConfiguration
Expand All @@ -43,11 +48,12 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
it.filter(::isCompatible).map { it.file }
},
)
project.registerPublishToCentralPortalTasks(
zipProvider = project.registerPublishToCentralPortalTasks(
kind = Kind.aggregation,
inputFiles = allFiles,
spec = spec,
allowEmptyFiles = allowEmptyAggregation
allowEmptyFiles = allowEmptyAggregation,
publishAllChecksums = publishAllChecksums
)

project.afterEvaluate {
Expand Down Expand Up @@ -77,7 +83,7 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
action.execute(options)
project.registerNmcpPublishFileByFileToFileSystemTask(
taskName = "nmcpPublishAggregationTo${options.name.get().capitalizeFirstLetter()}Repository",
inputFiles = allFiles,
inputFiles = project.zipTree(zipProvider),
m2AbsolutePath = project.provider { project.file(options.path.get()).absolutePath },
parallelism = project.provider { 1 },
)
Expand All @@ -100,6 +106,8 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro

abstract override val allowEmptyAggregation: Property<Boolean>

abstract override val publishAllChecksums: Property<Boolean>

abstract override val allowDuplicateProjectNames: Property<Boolean>
}

Expand Down
3 changes: 2 additions & 1 deletion nmcp/src/main/kotlin/nmcp/internal/DefaultNmcpExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ internal abstract class DefaultNmcpExtension(private val project: Project): Nmcp
kind = Kind.allPublications,
inputFiles = m2Files,
spec = spec,
allowEmptyFiles = project.provider { false }
allowEmptyFiles = project.provider { false },
publishAllChecksums = project.provider { false }
)
}
}
Expand Down
32 changes: 24 additions & 8 deletions nmcp/src/main/kotlin/nmcp/internal/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.gradle.api.attributes.HasConfigurableAttributes
import org.gradle.api.attributes.Usage
import org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Provider
import org.gradle.api.publish.plugins.PublishingPlugin.PUBLISH_TASK_GROUP
import org.gradle.api.tasks.bundling.Zip
Expand Down Expand Up @@ -53,8 +54,9 @@ internal fun Project.registerPublishToCentralPortalTasks(
kind: Kind,
inputFiles: FileCollection,
spec: CentralPortalOptions,
allowEmptyFiles: Provider<Boolean>
) {
allowEmptyFiles: Provider<Boolean>,
publishAllChecksums: Provider<Boolean>
): Provider<RegularFile> {
val name = kind.name

val releaseTaskName = "nmcpPublish${name.capitalizeFirstLetter()}ToCentralPortal"
Expand Down Expand Up @@ -84,19 +86,31 @@ internal fun Project.registerPublishToCentralPortalTasks(
it.destinationDirectory.set(project.layout.buildDirectory.dir("nmcp/zip"))
it.archiveFileName.set(zipName)
it.eachFile {
// Exclude maven-metadata files, or the bundle is not recognized
// See https://slack-chats.kotlinlang.org/t/16407246/anyone-tried-the-https-central-sonatype-org-publish-publish-#c8738fe5-8051-4f64-809f-ca67a645216e
if (it.name.startsWith("maven-metadata")) {
it.exclude()
val publishAllChecksums = publishAllChecksums.getOrElse(false)
when {
it.name.startsWith("maven-metadata") -> {
// Exclude maven-metadata files, or the bundle is not recognized
// See https://slack-chats.kotlinlang.org/t/16407246/anyone-tried-the-https-central-sonatype-org-publish-publish-#c8738fe5-8051-4f64-809f-ca67a645216e
it.exclude()
}
!publishAllChecksums && (it.name.endsWith(".sha256") || it.name.endsWith(".sha512")) -> {
// It's not clear if those are used, and it reduces the number of files in the deployment
it.exclude()
}
!publishAllChecksums && (it.name.endsWith(".asc.md5") || it.name.endsWith(".asc.sha1")) -> {
// It's not clear if those are used, and it reduces the number of files in the deployment
it.exclude()
}
}
}
it.dependsOn(checkFilesTaskProvider)
}

val zipProvider = zipTaskProvider.flatMap { it.archiveFile }

val releaseTask = registerNmcpPublishWithPublisherApiTask(
taskName = releaseTaskName,
inputFile = zipTaskProvider.flatMap { it.archiveFile },
inputFile = zipProvider,
username = spec.username,
password = spec.password,
publicationName = spec.publicationName.orElse(checkFilesTaskProvider.flatMap { it.outputFile }.map { it.asFile.readText() }),
Expand Down Expand Up @@ -148,7 +162,7 @@ internal fun Project.registerPublishToCentralPortalTasks(
registerNmcpPublishFileByFileToFileSystemTask(
taskName = localTaskName,
m2AbsolutePath = project.provider { m2File.absolutePath },
inputFiles = inputFiles,
inputFiles = zipTree(zipProvider),
parallelism = spec.uploadSnapshotsParallelism.orElse(defaultParallelism),
)

Expand All @@ -171,6 +185,8 @@ internal fun Project.registerPublishToCentralPortalTasks(
}
}
}

return zipProvider
}

private fun taskPath(project: Project, taskName: String): String {
Expand Down
2 changes: 1 addition & 1 deletion nmcp/testProjects/duplicate-name/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("org.jetbrains.kotlin.jvm").version("2.3.0").apply(false)
id("com.gradleup.nmcp.aggregation").version("1.5.1-SNAPSHOT")
id("com.gradleup.nmcp.aggregation").version("1.6.0-SNAPSHOT")
}

group = "com.example"
Expand Down
2 changes: 1 addition & 1 deletion nmcp/testProjects/empty-aggregation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins {
id("com.gradleup.nmcp.aggregation").version("1.5.1-SNAPSHOT")
id("com.gradleup.nmcp.aggregation").version("1.6.0-SNAPSHOT")
}
5 changes: 3 additions & 2 deletions scripts/integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -e
set -x
./gradlew -p tests/jvm build
./gradlew -p tests/kmp publishAggregationToCentralPortal --configuration-cache
./gradlew -p tests/kmp nmcpPublishDeployment -PnmcpDeploymentId=599ab6f5-dd08-4e7b-ae5a-85b45031715a --configuration-cache
./gradlew -p tests/kmp publishAggregationToCentralPortal
./gradlew -p tests/kmp nmcpPublishDeployment -PnmcpDeploymentId=599ab6f5-dd08-4e7b-ae5a-85b45031715a
./gradlew -p tests/kmp build
./gradlew -p tests/publish-all-checksums build
12 changes: 3 additions & 9 deletions tests/jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ import nmcp.NmcpAggregationExtension
plugins {
id("base")
alias(libs.plugins.kgp).apply(false)
id("com.gradleup.nmcp.aggregation")
}

buildscript {
dependencies {
classpath("com.gradleup.nmcp:nmcp")
}
}

apply(plugin = "com.gradleup.nmcp.aggregation")

group = "net.mbonnin.tnmcp"
version = "0.0.3"

Expand Down Expand Up @@ -85,7 +78,8 @@ subprojects {
}
}

extensions.getByType<NmcpAggregationExtension>().apply {
nmcpAggregation {
@Suppress("DEPRECATION")
publishAllProjectsProbablyBreakingProjectIsolation()

centralPortal {
Expand Down
1 change: 1 addition & 0 deletions tests/jvm/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.configuration-cache=true
5 changes: 5 additions & 0 deletions tests/jvm/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ pluginManagement {
mavenCentral()
}
}
includeBuild("../../")
}

includeBuild("../../")

plugins {
id("com.gradleup.nmcp.settings").apply(false)
}

include(":module1", ":module2")
Loading
Loading