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

also setup test fixtures sources jar for Kotlin/JVM, suppress warnings #486

Merged
merged 3 commits into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,6 @@
package com.vanniktech.maven.publish.test

/**
* Just a test fixture class in Kotlin.
*/
public class TestFixtureKotlinClass
Expand Up @@ -76,7 +76,10 @@ class MavenPublishPluginPlatformTest {
assertThat(result).artifact("jar").isSigned()
assertThat(result).pom().exists()
assertThat(result).pom().isSigned()
assertThat(result).pom().matchesExpectedPom(PomDependency("com.example", "test-artifact", "1.0.0", "compile", true))
assertThat(result).pom().matchesExpectedPom(
// TODO: Gradle currently adds a self dependency when test fixtures are published https://github.com/gradle/gradle/issues/14936
PomDependency("com.example", "test-artifact", "1.0.0", "compile", true),
)
assertThat(result).module().exists()
assertThat(result).module().isSigned()
assertThat(result).sourcesJar().exists()
Expand Down Expand Up @@ -169,6 +172,42 @@ class MavenPublishPluginPlatformTest {
assertThat(result).javadocJar().isSigned()
}

@TestParameterInjectorTest
fun kotlinJvmWithTestFixturesProject(@TestParameter kotlinVersion: KotlinVersion) {
val default = kotlinJvmProjectSpec(kotlinVersion)
val project = default.copy(
plugins = default.plugins + javaTestFixturesPlugin,
sourceFiles = default.sourceFiles + listOf(
SourceFile("testFixtures", "java", "com/vanniktech/maven/publish/test/TestFixtureClass.java"),
SourceFile("testFixtures", "kotlin", "com/vanniktech/maven/publish/test/TestFixtureKotlinClass.kt"),
)
)
val result = project.run(fixtures, testProjectDir, testOptions)

assertThat(result).outcome().succeeded()
assertThat(result).artifact("jar").exists()
assertThat(result).artifact("jar").isSigned()
assertThat(result).pom().exists()
assertThat(result).pom().isSigned()
assertThat(result).pom().matchesExpectedPom(
kotlinStdlibJdk(kotlinVersion),
// TODO: Gradle currently adds a self dependency when test fixtures are published https://github.com/gradle/gradle/issues/14936
PomDependency("com.example", "test-artifact", "1.0.0", "compile", true),
)
assertThat(result).module().exists()
assertThat(result).module().isSigned()
assertThat(result).sourcesJar().exists()
assertThat(result).sourcesJar().isSigned()
assertThat(result).sourcesJar().containsSourceSetFiles("main")
assertThat(result).javadocJar().exists()
assertThat(result).javadocJar().isSigned()
assertThat(result).artifact("test-fixtures", "jar").exists()
assertThat(result).artifact("test-fixtures", "jar").isSigned()
assertThat(result).sourcesJar("test-fixtures").exists()
assertThat(result).sourcesJar("test-fixtures").isSigned()
assertThat(result).sourcesJar("test-fixtures").containsSourceSetFiles("testFixtures")
}

@TestParameterInjectorTest
fun kotlinJsProject(@TestParameter kotlinVersion: KotlinVersion) {
val project = kotlinJsProjectSpec(kotlinVersion)
Expand Down
30 changes: 22 additions & 8 deletions plugin/src/main/kotlin/com/vanniktech/maven/publish/Platform.kt
Expand Up @@ -57,14 +57,7 @@ data class JavaLibrary @JvmOverloads constructor(
it.withJavadocJar { project.javadocJarTask(javadocJar) }
}

if (sourcesJar) {
// TODO: remove after https://github.com/gradle/gradle/issues/20539 is resolved
project.plugins.withId("java-test-fixtures") {
project.serviceOf<JvmModelingServices>().createJvmVariant("testFixtures") {
it.withSourcesJar().published()
}
}
}
setupTestFixtures(project, sourcesJar)
}
}

Expand Down Expand Up @@ -278,6 +271,8 @@ data class KotlinJvm @JvmOverloads constructor(
it.withSourcesJar { project.javaSourcesJar(sourcesJar) }
it.withJavadocJar { project.javadocJarTask(javadocJar) }
}

setupTestFixtures(project, sourcesJar)
}
}

Expand Down Expand Up @@ -430,6 +425,25 @@ private fun MavenPublication.withJavadocJar(factory: () -> TaskProvider<*>?) {
}
}

private fun setupTestFixtures(project: Project, sourcesJar: Boolean) {
project.plugins.withId("java-test-fixtures") {
if (sourcesJar) {
// TODO: remove after https://github.com/gradle/gradle/issues/20539 is resolved
project.serviceOf<JvmModelingServices>().createJvmVariant("testFixtures") {
it.withSourcesJar().published()
}
}

// test fixtures can't be mapped to the POM because there is no equivalent concept in Maven
project.mavenPublications {
it.suppressPomMetadataWarningsFor("testFixturesApiElements")
it.suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
it.suppressPomMetadataWarningsFor("testFixturesSourcesElements")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last one isn't present in eithernet because it gets added by the it.withSourcesJar().published() above which didn't run on eithernet since it's a Kotlin project


}
}
}

private class MissingVariantException(name: String) : RuntimeException(
"Invalid MavenPublish Configuration. Unable to find variant to publish named $name." +
" Try setting the 'androidVariantToPublish' property in the mavenPublish" +
Expand Down