Skip to content

Commit

Permalink
Update Gradle module metadata warnings: don't warn when it's enabled
Browse files Browse the repository at this point in the history
Also add a suggestion to enable the module metadata publishing in
Gradle 5.3+ projects that consume Gradle module metadata by default but
don't produce it unless explicitly enabled.

Issue #KT-31023 Fixed
  • Loading branch information
h0tk3y committed Jun 17, 2019
1 parent 1b5d281 commit d693620
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
Expand Up @@ -4,6 +4,7 @@
*/
package org.jetbrains.kotlin.gradle

import org.jetbrains.kotlin.gradle.internals.GRADLE_NO_METADATA_WARNING
import org.jetbrains.kotlin.gradle.plugin.ProjectLocalConfigurations
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmWithJavaTargetPreset
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
Expand Down Expand Up @@ -1834,4 +1835,20 @@ class NewMultiplatformIT : BaseGradleIT() {
doTestPomRewriting(mppProjectDependency = false, legacyPublishing = false, keepPomIntact = true)
doTestPomRewriting(mppProjectDependency = false, legacyPublishing = true, keepPomIntact = true)
}

@Test
fun testSuggestionToEnableMetadata() = with(Project("sample-lib", GradleVersionRequired.AtLeast("4.7"), "new-mpp-lib-and-app")) {
build {
assertNotContains(GRADLE_NO_METADATA_WARNING)

gradleSettingsScript().modify { it.replace("enableFeaturePreview(", "//") }
build {
if (testGradleVersionAtLeast("5.3-rc-2")) {
assertContains(GRADLE_NO_METADATA_WARNING)
} else {
assertNotContains(GRADLE_NO_METADATA_WARNING)
}
}
}
}
}
Expand Up @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
import org.jetbrains.kotlin.gradle.utils.checkGradleCompatibility
import org.jetbrains.kotlin.gradle.utils.isGradleVersionAtLeast
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.konan.target.presetName

Expand Down Expand Up @@ -145,11 +146,14 @@ class KotlinMultiplatformPlugin(

private fun configurePublishingWithMavenPublish(project: Project) = project.pluginManager.withPlugin("maven-publish") { _ ->

if (project.multiplatformExtension.run { isGradleMetadataAvailable && isGradleMetadataExperimental }) {
SingleWarningPerBuild.show(
project,
GRADLE_METADATA_WARNING
)
if (isGradleVersionAtLeast(5, 3) &&
project.multiplatformExtension.run { isGradleMetadataExperimental && !isGradleMetadataAvailable }
) {
SingleWarningPerBuild.show(project, GRADLE_NO_METADATA_WARNING)
}

if (!isGradleVersionAtLeast(4, 8) && project.multiplatformExtension.isGradleMetadataAvailable) {
SingleWarningPerBuild.show(project, GRADLE_OLD_METADATA_WARNING)
}

val targets = project.multiplatformExtension.targets
Expand Down Expand Up @@ -230,12 +234,16 @@ class KotlinMultiplatformPlugin(
companion object {
const val METADATA_TARGET_NAME = "metadata"

const val GRADLE_METADATA_WARNING =
// TODO point the user to some MPP docs explaining this in more detail
"This build is set up to publish Kotlin multiplatform libraries with experimental Gradle metadata. " +
"Future Gradle versions may fail to resolve dependencies on these publications. " +
"You can disable Gradle metadata usage during publishing and dependencies resolution by removing " +
"`enableFeaturePreview('GRADLE_METADATA')` from the settings.gradle file."
internal const val GRADLE_NO_METADATA_WARNING = "This build consumes Gradle module metadata but does not produce " +
"it when publishing Kotlin multiplatform libraries. \n" +
"To enable Gradle module metadata in publications, add 'enableFeaturePreview(\"GRADLE_METADATA\")' " +
"to the settings.gradle file. \n" +
"See: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#experimental-metadata-publishing-mode"

internal const val GRADLE_OLD_METADATA_WARNING = "This build is set up to publish a Kotlin multiplatform library " +
"with an outdated Gradle module metadata format, which newer Gradle versions won't be able to consume. \n" +
"Please update the Gradle version to 5.3 or newer. \n" +
"See: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#experimental-metadata-publishing-mode"
}
}

Expand Down
@@ -0,0 +1,9 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package org.jetbrains.kotlin.gradle.internals

const val GRADLE_NO_METADATA_WARNING =
org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin.GRADLE_NO_METADATA_WARNING

0 comments on commit d693620

Please sign in to comment.