-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace
dev.adamko.dev-publish
with custom implementation that uses…
… `maven.repo.local`
- Loading branch information
Showing
11 changed files
with
291 additions
and
49 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
124 changes: 124 additions & 0 deletions
124
build-logic/src/main/kotlin/dokkabuild.dev-maven-publish.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,124 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import dokkabuild.internal.consumable | ||
import dokkabuild.internal.declarable | ||
import dokkabuild.internal.resolvable | ||
import dokkabuild.DevMavenPublishExtension | ||
import dokkabuild.DevMavenPublishExtension.Companion.DEV_MAVEN_PUBLISH_EXTENSION_NAME | ||
import org.gradle.kotlin.dsl.support.uppercaseFirstChar | ||
|
||
/** | ||
* Utility for publishing a project to a local Maven directory for use in integration tests. | ||
* | ||
* Using a local directory is beneficial because Maven Local | ||
* [has some flaws](https://docs.gradle.org/8.6/userguide/declaring_repositories.html#sec:case-for-maven-local), | ||
* and we can more tightly control what artifacts are published and are persisted. | ||
* | ||
* It's possible to publish to a local directory using a regular [PublishToMavenRepository] task, | ||
* but when the project has a SNAPSHOT version the output will be timestamped, so Gradle will | ||
* _always_ publish a new artifact. This causes two issues: | ||
* | ||
* - The publication tasks, and any test tasks, will _always_ be out-of-date, even if no code changed. | ||
* - The local directory will endlessly grow in size | ||
* (which can be remedied by running `./gradlew clean`, but this is not ideal) | ||
* | ||
* To overcome this we manually set the system property `maven.repo.local` to a local directory. | ||
* Gradle will respect this property, and publish artifacts to the local directory only when | ||
* they have changed, improving performance. | ||
*/ | ||
plugins { | ||
base | ||
} | ||
|
||
/** | ||
* Directory for the output of the current subproject's 'publishToMavenLocal' | ||
*/ | ||
val currentProjectDevMavenRepo = gradle.rootProject.layout.buildDirectory.dir("dev-maven-repo") | ||
|
||
val devMavenPublishAttribute = Attribute.of("dev-maven-publish", String::class.java) | ||
|
||
dependencies { | ||
attributesSchema { | ||
attribute(devMavenPublishAttribute) | ||
} | ||
} | ||
|
||
val publishToDevMavenRepo by tasks.registering { | ||
description = "Publishes all Maven publications to the dev Maven repository." | ||
group = PublishingPlugin.PUBLISH_TASK_GROUP | ||
} | ||
|
||
|
||
plugins.withType<MavenPublishPlugin>().all { | ||
extensions | ||
.getByType<PublishingExtension>() | ||
.publications | ||
.withType<MavenPublication>().all publication@{ | ||
val publicationName = this@publication.name | ||
val installTaskName = "publish${publicationName.uppercaseFirstChar()}PublicationToDevMavenRepo" | ||
|
||
// Register a new publication task for each publication. | ||
val installTask = tasks.register<PublishToMavenLocal>(installTaskName) { | ||
description = "Publishes Maven publication '$publicationName' to the test Maven repository." | ||
group = PublishingPlugin.PUBLISH_TASK_GROUP | ||
publication = this@publication | ||
|
||
val destinationDir = currentProjectDevMavenRepo.get().asFile | ||
inputs.property("currentProjectDevMavenRepoPath", destinationDir.invariantSeparatorsPath) | ||
|
||
doFirst { | ||
/** | ||
* `maven.repo.local` will set the destination directory for this [PublishToMavenLocal] task. | ||
* | ||
* @see org.gradle.api.internal.artifacts.mvnsettings.DefaultLocalMavenRepositoryLocator.getLocalMavenRepository | ||
*/ | ||
System.setProperty("maven.repo.local", destinationDir.absolutePath) | ||
} | ||
} | ||
|
||
publishToDevMavenRepo.configure { | ||
dependsOn(installTask) | ||
} | ||
|
||
tasks.check { | ||
mustRunAfter(installTask) | ||
} | ||
} | ||
} | ||
|
||
|
||
val devPublication: Configuration by configurations.creating { | ||
description = "Depend on project-local Dev Maven repositories" | ||
declarable() | ||
} | ||
|
||
val devPublicationResolver: Configuration by configurations.creating { | ||
description = "Resolve project-local Dev Maven repositories" | ||
resolvable() | ||
extendsFrom(devPublication) | ||
attributes { | ||
attribute(devMavenPublishAttribute, "devMavenRepo") | ||
} | ||
} | ||
|
||
val devPublicationConsumable: Configuration by configurations.creating { | ||
description = "Provide project-local Dev Maven repositories dependencies" | ||
consumable() | ||
attributes { | ||
attribute(devMavenPublishAttribute, "devMavenRepo") | ||
} | ||
outgoing { | ||
artifact(currentProjectDevMavenRepo) { | ||
builtBy(publishToDevMavenRepo) | ||
} | ||
} | ||
} | ||
|
||
val devMavenPublishExtension = extensions.create<DevMavenPublishExtension>( | ||
DEV_MAVEN_PUBLISH_EXTENSION_NAME, | ||
// fetch Dev Maven Repos from the dependencies | ||
devPublicationResolver.incoming.artifacts.resolvedArtifacts.map { incoming -> | ||
incoming.map { it.file } | ||
} | ||
) |
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
18 changes: 18 additions & 0 deletions
18
build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt
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,18 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
package dokkabuild | ||
|
||
import org.gradle.api.provider.Provider | ||
import java.io.File | ||
|
||
abstract class DevMavenPublishExtension( | ||
/** | ||
* Resolves Dev Maven repos from the current project's dependencies. | ||
*/ | ||
val devMavenRepositories: Provider<List<File>>, | ||
) { | ||
companion object { | ||
const val DEV_MAVEN_PUBLISH_EXTENSION_NAME = "devMavenPublish" | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
build-logic/src/main/kotlin/dokkabuild/internal/gradleUtils.kt
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,61 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dokkabuild.internal | ||
|
||
import org.gradle.api.artifacts.Configuration | ||
|
||
/** | ||
* Mark this [Configuration] as one that will be consumed by other subprojects. | ||
* | ||
* ``` | ||
* isCanBeResolved = false | ||
* isCanBeConsumed = true | ||
* isCanBeDeclared = false | ||
* ``` | ||
*/ | ||
fun Configuration.consumable( | ||
visible: Boolean = false | ||
) { | ||
isVisible = visible | ||
isCanBeResolved = false | ||
isCanBeConsumed = true | ||
isCanBeDeclared = false | ||
} | ||
|
||
/** | ||
* Mark this [Configuration] as one that will consume artifacts from other subprojects (also known as 'resolving') | ||
* | ||
* ``` | ||
* isCanBeResolved = true | ||
* isCanBeConsumed = false | ||
* isCanBeDeclared = false | ||
* ``` | ||
*/ | ||
fun Configuration.resolvable( | ||
visible: Boolean = false | ||
) { | ||
isVisible = visible | ||
isCanBeResolved = true | ||
isCanBeConsumed = false | ||
isCanBeDeclared = false | ||
} | ||
|
||
/** | ||
* Mark this [Configuration] as one that will be used to declare dependencies. | ||
* | ||
* ``` | ||
* isCanBeResolved = false | ||
* isCanBeConsumed = false | ||
* isCanBeDeclared = true | ||
* ``` | ||
*/ | ||
fun Configuration.declarable( | ||
visible: Boolean = false | ||
) { | ||
isVisible = visible | ||
isCanBeResolved = false | ||
isCanBeConsumed = false | ||
isCanBeDeclared = true | ||
} |
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
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
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.