-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2717
- Loading branch information
Showing
5 changed files
with
310 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
buildSrc/src/main/kotlin/publishing-check-conventions.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
object TestPublishing { | ||
const val configurationName = "testRepository" | ||
} | ||
|
||
val testRepositoryDependency = configurations.create(TestPublishing.configurationName) { | ||
isVisible = true | ||
isCanBeResolved = false | ||
isCanBeConsumed = false | ||
} | ||
|
||
|
||
val testRepositories = configurations.create("testRepositories") { | ||
isVisible = false | ||
isCanBeResolved = true | ||
// this config consumes modules from OTHER projects, and cannot be consumed by other projects | ||
isCanBeConsumed = false | ||
|
||
attributes { | ||
attribute(Attribute.of("kotlinx.serialization.repository", String::class.java), "test") | ||
} | ||
extendsFrom(testRepositoryDependency) | ||
} | ||
|
||
tasks.register<ArtifactsCheckTask>("checkArtifacts") { | ||
repositories.from(testRepositories) | ||
} | ||
|
||
abstract class ArtifactsCheckTask: DefaultTask() { | ||
|
||
@get:InputFiles | ||
@get:PathSensitive(PathSensitivity.RELATIVE) | ||
abstract val repositories: ConfigurableFileCollection | ||
|
||
@TaskAction | ||
fun check() { | ||
val artifactsFile = project.rootDir.resolve("gradle/artifacts.txt") | ||
|
||
val actualArtifacts = repositories.files.flatMap { file -> | ||
file.resolve("org/jetbrains/kotlinx").list()?.toSet() ?: emptySet() | ||
}.toSortedSet() | ||
|
||
if (project.hasProperty("dumpArtifacts")) { | ||
artifactsFile.bufferedWriter().use { writer -> | ||
actualArtifacts.forEach { artifact -> writer.appendLine(artifact) } | ||
} | ||
return | ||
} | ||
|
||
val expectedArtifacts = artifactsFile.readLines().toSet() | ||
|
||
if (expectedArtifacts == actualArtifacts) { | ||
logger.lifecycle("All artifacts are published") | ||
} else { | ||
val missedArtifacts = expectedArtifacts - actualArtifacts | ||
val unknownArtifacts = actualArtifacts - expectedArtifacts | ||
val message = "The published artifacts differ from the expected ones." + | ||
(if (missedArtifacts.isNotEmpty()) missedArtifacts.joinToString(prefix = "\n\tMissing artifacts: ") else "") + | ||
(if (unknownArtifacts.isNotEmpty()) unknownArtifacts.joinToString(prefix = "\n\tUnknown artifacts: ") else "") + | ||
"\nTo save current list of artifacts as expecting, call 'checkArtifacts -PdumpArtifacts'" | ||
|
||
logger.error(message) | ||
throw GradleException("The published artifacts differ from the expected ones") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.