Fallback for publishing with no Gradle metadata
The following parts of the publications are affected:
* root publication
* with Gradle metadata, it is published and references the
other publications using the `available-at` mechanism
* without metadata opt-in, it is not published
* Kotlin metadata variant
* with Gradle metadata, it is added as an additional variant to the
platform-specific publications to allow the IDE to discover it
* without metadata opt-in, it is added as a dependency to the platform-
specific modules (like in old MPP)
This commit is contained in:
+112
@@ -439,6 +439,66 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPublishWithoutGradleMetadata() {
|
||||
val libProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")
|
||||
|
||||
with (libProject) {
|
||||
setupWorkingDir()
|
||||
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") }
|
||||
|
||||
build("publish") {
|
||||
assertSuccessful()
|
||||
val groupRepoDir = "repo/com/example"
|
||||
|
||||
// No root publication:
|
||||
assertNoSuchFile("$groupRepoDir/sample-lib")
|
||||
|
||||
// Check that the platform publications have the metadata dependency
|
||||
listOf("jvm6", "nodejs", "wasm32", nativeHostTargetName.toLowerCase()).forEach { targetAppendix ->
|
||||
val targetPomPath = "$groupRepoDir/sample-lib-$targetAppendix/1.0/sample-lib-$targetAppendix-1.0.pom"
|
||||
assertFileContains(
|
||||
targetPomPath,
|
||||
"<groupId>com.example</groupId>",
|
||||
"<artifactId>sample-lib-metadata</artifactId>",
|
||||
"<version>1.0</version>"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDependenciesOnMppLibraryPartsWithNoMetadata() {
|
||||
val repoDir = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
setupWorkingDir()
|
||||
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") }
|
||||
build("publish") { assertSuccessful() }
|
||||
projectDir.resolve("repo")
|
||||
}
|
||||
|
||||
with(Project("sample-app", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().modify {
|
||||
it.replace("implementation 'com.example:sample-lib:1.0'", "implementation 'com.example:sample-lib-metadata:1.0'") + "\n" + """
|
||||
repositories { maven { url '${repoDir.toURI()}' } }
|
||||
|
||||
dependencies {
|
||||
allJvmImplementation 'com.example:sample-lib-jvm6:1.0'
|
||||
nodeJsMainImplementation 'com.example:sample-lib-nodejs:1.0'
|
||||
wasm32MainImplementation 'com.example:sample-lib-wasm32:1.0'
|
||||
${nativeHostTargetName}MainImplementation 'com.example:sample-lib-${nativeHostTargetName.toLowerCase()}:1.0'
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
build("assemble") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(listOf("Jvm6", "NodeJs", "Wasm32", nativeHostTargetName.capitalize()).map { ":compileKotlin$it" })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPublishingOnlySupportedNativeTargets() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
val (publishedVariant, nonPublishedVariant) = when {
|
||||
@@ -462,6 +522,58 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNonMppConsumersOfLibraryPublishedWithNoMetadataOptIn() {
|
||||
val repoDir = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
setupWorkingDir()
|
||||
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview", "// enableFeaturePreview") }
|
||||
build("publish") { assertSuccessful() }
|
||||
projectDir.resolve("repo")
|
||||
}
|
||||
|
||||
with(Project("sample-old-style-app", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().appendText("\nallprojects { repositories { maven { url '${repoDir.toURI()}' } } }")
|
||||
gradleBuildScript("app-common").modify { it.replace("com.example:sample-lib:", "com.example:sample-lib-metadata:") }
|
||||
gradleBuildScript("app-jvm").modify { it.replace("com.example:sample-lib:", "com.example:sample-lib-jvm6:") }
|
||||
gradleBuildScript("app-js").modify { it.replace("com.example:sample-lib:", "com.example:sample-lib-nodejs:") }
|
||||
|
||||
build("assemble", "run") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":app-common:compileKotlinCommon", ":app-jvm:compileKotlin", ":app-jvm:run", ":app-js:compileKotlin2Js")
|
||||
}
|
||||
|
||||
// Then run again without even reading the metadata from the repo:
|
||||
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview('GRADLE_METADATA')", "") }
|
||||
|
||||
build("assemble", "run", "--rerun-tasks") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":app-common:compileKotlinCommon", ":app-jvm:compileKotlin", ":app-jvm:run", ":app-js:compileKotlin2Js")
|
||||
}
|
||||
}
|
||||
|
||||
with(Project("sample-app-without-kotlin", gradleVersion, "new-mpp-lib-and-app")) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().modify {
|
||||
it.replace("com.example:sample-lib:1.0", "com.example:sample-lib-jvm6:1.0") + "\n" + """
|
||||
repositories { maven { url '${repoDir.toURI()}' } }
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
build("run") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":compileJava", ":run")
|
||||
}
|
||||
|
||||
// Then run again without even reading the metadata from the repo:
|
||||
projectDir.resolve("settings.gradle").modify { it.replace("enableFeaturePreview('GRADLE_METADATA')", "") }
|
||||
build("run", "--rerun-tasks") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(":compileJava", ":run")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOptionalExpectations() = with(Project("new-mpp-lib-with-tests", gradleVersion)) {
|
||||
setupWorkingDir()
|
||||
|
||||
+8
-1
@@ -1,7 +1,14 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'application'
|
||||
}
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.example:sample-lib:1.0'
|
||||
}
|
||||
}
|
||||
|
||||
mainClassName = 'A'
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
import com.example.lib.CommonKt;
|
||||
|
||||
public class A {
|
||||
public void useKotlinClass() {
|
||||
public static void main(String[] args) {
|
||||
CommonKt.id(123);
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'application'
|
||||
|
||||
dependencies {
|
||||
compile 'com.example:sample-lib:1.0'
|
||||
}
|
||||
}
|
||||
|
||||
mainClassName = 'com.example.app.JvmAppKt'
|
||||
Reference in New Issue
Block a user