Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KT-64377 Maven dev publish #3433

Merged
merged 72 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
c31dd23
KT-64377 - remove gradle wrapper files for integration test projects …
adam-enko Dec 19, 2023
61889af
Merge branch 'master' into KT-64377/update-integration-test-build-config
adam-enko Dec 20, 2023
74a1b20
Merge remote-tracking branch 'origin/master' into KT-64377/update-int…
adam-enko Jan 2, 2024
20e0984
refactor integration test properties to use DokkaBuildProperties util…
adam-enko Jan 12, 2024
66287db
Merge branch 'master' into KT-64377/update-integration-test-build-config
adam-enko Jan 12, 2024
28f4d7a
disable explicit API mode in non-published integration-test utilities…
adam-enko Jan 12, 2024
7af0394
Merge remote-tracking branch 'origin/master' into KT-64377/update-int…
adam-enko Jan 15, 2024
10fe4b5
Restructure Gradle Integration tests to use Java Test Suites
adam-enko Jan 15, 2024
5f35a73
revert GitHub smoke test Gradle task back to 'test'
adam-enko Jan 16, 2024
0babb2c
auto-discover and set ANDROID_SDK, and also search for local.properti…
adam-enko Jan 16, 2024
9c6c80e
add TODO link for integration tests - doNotTrackState()
adam-enko Jan 16, 2024
b1c95de
Merge branch 'master' into KT-64377/java-test-suites
adam-enko Jan 22, 2024
28a1c74
tidy up after merge
adam-enko Jan 22, 2024
70fd4f8
Use Maven Dev Publish plugin
adam-enko Jan 22, 2024
8a24b4d
Merge remote-tracking branch 'origin/master' into KT-64377/java-test-…
adam-enko Jan 22, 2024
57b93cf
merge cleanup
adam-enko Jan 22, 2024
a974d9b
change plugin `test-suite-base` -> `jvm-test-suite`
adam-enko Jan 23, 2024
852fc7b
move registerTestProjectSuite() to top-level function
adam-enko Jan 23, 2024
ba0c484
move gradle-specific test utils to gradle integration test
adam-enko Jan 23, 2024
6d5ab63
move unused systemVariableProviders.kt back
adam-enko Jan 23, 2024
14364ea
move `multimodule-inter-module-links` to test-suite
adam-enko Jan 23, 2024
84255e2
register DOKKA_TEST_OUTPUT_PATH as a test task input, and the dir as …
adam-enko Jan 23, 2024
37581f2
Merge branch 'master' into KT-64377/java-test-suites
adam-enko Jan 23, 2024
f6d1cca
rm old import
adam-enko Jan 23, 2024
9fe882b
make testOutputPath optional
adam-enko Jan 23, 2024
59594dd
re-add integrationTest lifecycle task
adam-enko Jan 23, 2024
d249e64
fix `it-multimodule-inter-module-links` dir, add property name to tem…
adam-enko Jan 24, 2024
ed0365f
comment to explain test-suites are independent
adam-enko Jan 24, 2024
50a6ef4
add property names to coroutines/serialization project dirs
adam-enko Jan 24, 2024
99fc753
use jvm11 for kotlinx.serialization
adam-enko Jan 24, 2024
75d6e34
Merge branch 'KT-64377/java-test-suites' into KT-64377/maven-dev-publish
adam-enko Jan 24, 2024
654df1a
update maven-dev-plugin usage
adam-enko Jan 26, 2024
47b3dc8
Merge branch 'master' into KT-64377/java-test-suites
adam-enko Jan 26, 2024
cd554b0
revert MaxMetaspaceSize in Coroutines test, and add comment to explain
adam-enko Jan 26, 2024
668c661
environment workaround for https://github.com/gradle/gradle/issues/11534
adam-enko Jan 31, 2024
939d577
update CI build properties
adam-enko Jan 31, 2024
42cd06c
remove `allWarningsAsErrors = false`
adam-enko Jan 31, 2024
df52ca1
remove 'check' task dependency
adam-enko Jan 31, 2024
a956a36
Merge branch 'KT-64377/java-test-suites' into KT-64377/maven-dev-publish
adam-enko Jan 31, 2024
0310637
Merge branch 'master' into KT-64377/maven-dev-publish
adam-enko Jan 31, 2024
6eff18d
Merge branch 'master' into KT-64377/java-test-suites
adam-enko Jan 31, 2024
fe0d7f3
Merge branch 'KT-64377/java-test-suites' into KT-64377/maven-dev-publish
adam-enko Jan 31, 2024
457b162
tidy
adam-enko Jan 31, 2024
85a7528
remove `integrationTestPreparation` (it was less useful than I though…
adam-enko Jan 31, 2024
4d4c313
Merge branch 'master' into KT-64377/maven-dev-publish
adam-enko Feb 7, 2024
ab5bd72
update git patches, and dev-maven injection
adam-enko Feb 7, 2024
c63cea7
tidying
adam-enko Feb 7, 2024
4ebb134
fix dokka version in IT projects
adam-enko Feb 7, 2024
7bb6270
Merge remote-tracking branch 'origin/master' into KT-64377/maven-dev-…
adam-enko Feb 9, 2024
916d07c
Merge branch 'master' into KT-64377/maven-dev-publish
adam-enko Feb 14, 2024
c0cb8aa
remove unnecessary `.toString()`
adam-enko Feb 14, 2024
53f123d
revert change to Dokkatoo util
adam-enko Feb 14, 2024
7b562ab
move dev maven repo task input registration to util function
adam-enko Feb 14, 2024
5e3a5f3
replace `System.getenv("dokka_it_dokka_version")` with `providers.gra…
adam-enko Feb 14, 2024
71964c5
update dev-repos after git patches
adam-enko Feb 14, 2024
d2ecb3a
update coroutines and serialization patches
adam-enko Feb 14, 2024
9647b63
fix coroutines git patch
adam-enko Feb 14, 2024
e689864
fomatting
adam-enko Feb 14, 2024
e39fa37
bump dev-publish-plugin version
adam-enko Feb 16, 2024
67ba564
restore deleted it-multimodule-inter-module-links/gradle.properties
adam-enko Feb 16, 2024
b29f542
replace `dev.adamko.dev-publish` with custom implementation that uses…
adam-enko Feb 23, 2024
b963d07
Merge branch 'master' into KT-64377/maven-dev-publish
adam-enko Feb 23, 2024
537d5e0
remove old kotlinx-serialization git submodule
adam-enko Feb 23, 2024
4164cdf
fix CC compatibility
adam-enko Feb 23, 2024
53a1704
fixin' build caching
adam-enko Mar 8, 2024
72a2206
Merge remote-tracking branch 'origin/master' into KT-64377/maven-dev-…
adam-enko Mar 8, 2024
fa79d74
Merge branch 'master' into KT-64377/maven-dev-publish
adam-enko Mar 12, 2024
1655ee0
Merge remote-tracking branch 'origin/master' into KT-64377/maven-dev-…
adam-enko Mar 18, 2024
d6e55de
use `tasks.check {}` dsl accessor
adam-enko Mar 18, 2024
5ee709d
update IB comment
adam-enko Mar 22, 2024
75e43fe
Merge remote-tracking branch 'origin/master' into KT-64377/maven-dev-…
adam-enko Mar 27, 2024
aa226fa
update comment regarding Maven Metadata exclusions
adam-enko Mar 27, 2024
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
6 changes: 0 additions & 6 deletions build-logic/src/main/kotlin/dokkabuild.base.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

val integrationTestPreparation by tasks.registering {
description =
"lifecycle task for preparing the project for integration tests (for example, publishing to the test Maven repo)"
group = VERIFICATION_GROUP
}
adam-enko marked this conversation as resolved.
Show resolved Hide resolved
122 changes: 122 additions & 0 deletions build-logic/src/main/kotlin/dokkabuild.dev-maven-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
import dokkabuild.DevMavenPublishExtension
import dokkabuild.DevMavenPublishExtension.Companion.DEV_MAVEN_PUBLISH_EXTENSION_NAME
import dokkabuild.internal.consumable
import dokkabuild.internal.declarable
import dokkabuild.internal.resolvable
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 = [email protected]
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.files,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*/

plugins {
id("dokkabuild.base")
`maven-publish`
signing
id("dokkabuild.dev-maven-publish")
}

publishing {
Expand Down Expand Up @@ -33,13 +35,6 @@ publishing {
password = System.getenv("DOKKA_SPACE_PACKAGES_SECRET")
}
}
// Publish to a project-local Maven directory, for verification. To test, run:
// ./gradlew publishAllPublicationsToProjectLocalRepository
// and check $rootDir/build/maven-project-local
maven {
name = "projectLocal"
url = uri(rootProject.layout.buildDirectory.dir("maven-project-local"))
}
}

publications.withType<MavenPublication>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ val integrationTest by tasks.registering(NonCacheableIntegrationTest::class) {
}

environment("isExhaustive", dokkaBuild.integrationTestExhaustive.get())

testLogging {
exceptionFormat = TestExceptionFormat.FULL
events(TestLogEvent.SKIPPED, TestLogEvent.FAILED)
Expand Down
60 changes: 60 additions & 0 deletions build-logic/src/main/kotlin/dokkabuild/DevMavenPublishExtension.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.Task
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileTree
import org.gradle.api.tasks.PathSensitivity.RELATIVE
import org.gradle.process.JavaForkOptions

abstract class DevMavenPublishExtension(
/**
* Resolves Dev Maven repos from the current project's `devPublication` dependencies.
*
* Must only contain directories.
*/
private val devMavenRepositories: FileCollection,
) {

/**
* Files suitable for registering as a task input (as in, the files are reproducible-build compatible).
*/
private val devMavenRepositoriesInputFiles: FileTree = devMavenRepositories
.asFileTree
.matching {
// Exclude Maven Metadata files because they contain timestamps,
// meaning tasks that use devMavenRepositories as an input will
// never be up-to-date.
// The Gradle Module Metadata contains the same information (and more),
// so no issues are expected.
exclude("**/maven-metadata*.xml")
}

/**
* Configures [task] to register [devMavenRepositories] as a task input,
* and (if possible) adds `devMavenRepository` as a [JavaForkOptions.systemProperty].
*/
fun configureTask(task: Task) {
task.inputs.files(devMavenRepositoriesInputFiles)
.withPropertyName("devMavenPublish.devMavenRepositoriesInputFiles")
.withPathSensitivity(RELATIVE)

task.dependsOn(devMavenRepositories)

if (task is JavaForkOptions) {
task.doFirst("devMavenRepositories systemProperty") {
// workaround https://github.com/gradle/gradle/issues/24267
task.systemProperty(
"devMavenRepositories",
devMavenRepositories.joinToString(",") { it.canonicalFile.invariantSeparatorsPath }
)
}
}
}

companion object {
const val DEV_MAVEN_PUBLISH_EXTENSION_NAME = "devMavenPublish"
}
}
61 changes: 61 additions & 0 deletions build-logic/src/main/kotlin/dokkabuild/internal/gradleUtils.kt
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
}
45 changes: 35 additions & 10 deletions dokka-integration-tests/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Disabled

plugins {
id("dokkabuild.kotlin-jvm")
id("dokkabuild.dev-maven-publish")
`jvm-test-suite`
`java-test-fixtures`
}
Expand All @@ -27,6 +28,30 @@ dependencies {
api(libs.junit.jupiterParams)

api(gradleTestKit())

val dokkaVersion = project.version.toString()
// We're using Gradle included-builds and dependency substitution, so we
// need to use the Gradle project name, *not* the published Maven artifact-id
devPublication("org.jetbrains.dokka:plugin-all-modules-page:$dokkaVersion")
devPublication("org.jetbrains.dokka:analysis-kotlin-api:$dokkaVersion")
devPublication("org.jetbrains.dokka:analysis-kotlin-descriptors:$dokkaVersion")
devPublication("org.jetbrains.dokka:analysis-kotlin-symbols:$dokkaVersion")
devPublication("org.jetbrains.dokka:analysis-markdown-jb:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-android-documentation:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-base:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-base-test-utils:$dokkaVersion")
devPublication("org.jetbrains.dokka:dokka-core:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-gfm:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-gfm-template-processing:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-javadoc:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-jekyll:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-jekyll-template-processing:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-kotlin-as-java:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-mathjax:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-templating:$dokkaVersion")
devPublication("org.jetbrains.dokka:plugin-versioning:$dokkaVersion")

devPublication("org.jetbrains.dokka:runner-gradle-plugin-classic:$dokkaVersion")
}

kotlin {
Expand All @@ -42,14 +67,7 @@ val aggregatingProject = gradle.includedBuild("dokka")
val templateSettingsGradleKts = layout.projectDirectory.file("projects/template.settings.gradle.kts")
val templateProjectsDir = layout.projectDirectory.dir("projects")

tasks.integrationTestPreparation {
// TODO remove this in https://github.com/Kotlin/dokka/pull/3433
dependsOn(aggregatingProject.task(":publishToMavenLocal"))
}

tasks.withType<Test>().configureEach {
dependsOn(tasks.integrationTestPreparation)

setForkEvery(1)
maxHeapSize = "2G"
dokkaBuild.integrationTestParallelism.orNull?.let { parallelism ->
Expand All @@ -69,7 +87,11 @@ tasks.withType<Test>().configureEach {
dokkaBuild.isCI.map { isCi -> if (isCi) "ALWAYS" else "ON_SUCCESS" }.get(),
)

environment("DOKKA_VERSION", project.version)
val dokkaVersion = provider { project.version.toString() }
inputs.property("dokkaVersion", dokkaVersion)
doFirst("set DOKKA_VERSION environment variable (workaround for https://github.com/gradle/gradle/issues/24267)") {
environment("DOKKA_VERSION", dokkaVersion.get())
}

// environment() isn't Provider API compatible yet https://github.com/gradle/gradle/issues/11534
dokkaBuild.integrationTestExhaustive.orNull?.let { exhaustive ->
Expand All @@ -87,8 +109,9 @@ tasks.withType<Test>().configureEach {
showStackTraces = true
}

// TODO remove this in https://github.com/Kotlin/dokka/pull/3433
doNotTrackState("uses artifacts from Maven Local")
// The tests produce report data and generated Dokka output.
// Always cache them so Gradle can skip running integration tests if nothing has changed.
outputs.cacheIf("always cache") { true }
}

testing {
Expand Down Expand Up @@ -200,6 +223,8 @@ fun TestingExtension.registerTestProjectSuite(
templateSettingsGradleKts.asFile.invariantSeparatorsPath,
)

devMavenPublish.configureTask(this)

if (jvm != null) {
javaLauncher = javaToolchains.launcherFor { languageVersion = jvm }
}
Expand Down
Loading
Loading