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
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 getLenient ()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 @@ -71,4 +71,14 @@ interface NmcpAggregationExtension {
* Default: false
*/
val publishAllChecksums: Property<Boolean>

/**
* By default, the aggregation is not lenient so that configuration errors are easier to debug.
* Sometimes, it's easier to just do `allprojects {}` and collect all subprojects, even those that do not apply the `com.gradleup.nmcp` plugin.
* The settings plugin uses this for an example.
*
* In those cases, set `lenient.set(true)` to ignore those subprojects.
*
*/
val lenient: Property<Boolean>
}
9 changes: 4 additions & 5 deletions nmcp/src/main/kotlin/nmcp/NmcpExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ interface NmcpExtension {
*
* Use this to add publications whose files are not known until execution time.
*
* @param files the files to be added.
* The given paths are evaluated as per [org.gradle.api.Project.files].
* Typically, [files] is built from a [org.gradle.api.file.FileTree] or
* a [org.gradle.api.file.DirectoryProperty] so that the files also contain their relative path.
* @param artifactNotation the files to be added.
* The given paths are evaluated as per [org.gradle.api.artifacts.dsl.ArtifactHandler.add].
* Typically, [artifactNotation] is a directory or a task producing a directory.
*/
fun extraFiles(files: Any)
fun extraFiles(artifactNotation: Any)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.gradle.api.provider.Provider
internal abstract class DefaultNmcpAggregationExtension(private val project: Project) : NmcpAggregationExtension {
private val spec = project.objects.newInstance(CentralPortalOptions::class.java)

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

Expand All @@ -40,13 +40,18 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
init {
allFiles.from(
consumerConfiguration
.incoming
.artifactView { it.lenient(true) }
.artifacts
.resolvedArtifacts
.map {
it.filter(::isCompatible).map { it.file }
},
it.incoming
.artifactView {
it.lenient(lenient.getOrElse(false))
}
.artifacts
.resolvedArtifacts
.map {
it.filter(::isCompatible).map { it.file }
}
}

)
zipProvider = project.registerPublishToCentralPortalTasks(
kind = Kind.aggregation,
Expand Down Expand Up @@ -99,7 +104,9 @@ internal abstract class DefaultNmcpAggregationExtension(private val project: Pro
aproject.pluginManager.withPlugin("maven-publish") {
aproject.pluginManager.apply("com.gradleup.nmcp")

consumerConfiguration.dependencies.add(aproject.dependencies.create(aproject))
consumerConfiguration.configure {
it.dependencies.add(aproject.dependencies.create(aproject))
}
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions nmcp/src/main/kotlin/nmcp/internal/DefaultNmcpSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ abstract class DefaultNmcpSettings(settings: Settings): NmcpSettings {
if (project.rootProject == project) {
project.pluginManager.apply("com.gradleup.nmcp.aggregation")

project.extensions.getByType(NmcpAggregationExtension::class.java).centralPortal {
it.username.set(spec.username)
it.password.set(spec.password)
it.publishingType.set(spec.publishingType)
it.publicationName.set(spec.publicationName)
it.validationTimeout.set(spec.validationTimeout)
it.publishingTimeout.set(spec.publishingTimeout)
it.baseUrl.set(spec.baseUrl)
it.uploadSnapshotsParallelism.set(spec.uploadSnapshotsParallelism)
project.extensions.getByType(NmcpAggregationExtension::class.java).apply {
// subprojects may not all apply com.gradleup.nmcp
lenient.set(true)
centralPortal {
it.username.set(spec.username)
it.password.set(spec.password)
it.publishingType.set(spec.publishingType)
it.publicationName.set(spec.publicationName)
it.validationTimeout.set(spec.validationTimeout)
it.publishingTimeout.set(spec.publishingTimeout)
it.baseUrl.set(spec.baseUrl)
it.uploadSnapshotsParallelism.set(spec.uploadSnapshotsParallelism)
}
}

project.allprojects {
Expand Down
21 changes: 21 additions & 0 deletions nmcp/src/test/kotlin/MainTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import java.io.File
import kotlin.test.Test
import kotlin.test.assertFalse
import org.gradle.testkit.runner.GradleRunner

class MainTest {
Expand Down Expand Up @@ -38,4 +39,24 @@ class MainTest {

assert(result.output.contains("Nmcp: there are no files to publish"))
}

@Test
fun nonLenient() {
val dst = File("build/testProject")
val src = File("testProjects/non-lenient")

dst.deleteRecursively()
dst.mkdirs()

src.copyRecursively(dst, overwrite = true)

val result = GradleRunner.create()
.withProjectDir(dst)
.withArguments("nmcpZipAggregation")
.withDebug(true)
.buildAndFail()

assertFalse(result.output.contains("there are no files to publish"))
assert(result.output.contains("Expected task 'foo' output files to contain exactly one file, however, it contains more than one file"))
}
}
21 changes: 21 additions & 0 deletions nmcp/testProjects/non-lenient/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plugins {
id("maven-publish")
id("com.gradleup.nmcp").version("1.6.3-SNAPSHOT")
id("com.gradleup.nmcp.aggregation").version("1.6.3-SNAPSHOT")
}

val fooTask = tasks.register("foo") {
outputs.dir(layout.projectDirectory.file("dir1"))
outputs.dir(layout.projectDirectory.file("dir2"))
}

nmcp {
/**
* error: the task contains several outputs and therefore cannot be added as an artifact
*/
extraFiles(fooTask)
}

dependencies {
nmcpAggregation(project)
}
1 change: 1 addition & 0 deletions nmcp/testProjects/non-lenient/dir1/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello1
1 change: 1 addition & 0 deletions nmcp/testProjects/non-lenient/dir2/file2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello2
6 changes: 6 additions & 0 deletions nmcp/testProjects/non-lenient/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach {
it.mavenCentral()
it.maven("../../../build/m2")
}
}
3 changes: 3 additions & 0 deletions scripts/update-repo.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ updateRepo(
file("nmcp/testProjects/empty-aggregation/build.gradle.kts") {
replacePluginVersion("com.gradleup.nmcp.aggregation")
}
file("nmcp/testProjects/non-lenient/build.gradle.kts") {
replacePluginVersion("com.gradleup.nmcp.aggregation")
}
},
setVersionInDocs = {
file("docs/src/content/docs/index.mdx") {
Expand Down
Loading