Skip to content

Commit

Permalink
also publish the sources of java-test-fixtures (#480)
Browse files Browse the repository at this point in the history
* also publish the sources of java-test-fixtures

* Update CHANGELOG.md
  • Loading branch information
gabrielittner committed Dec 28, 2022
1 parent 6024f4d commit f238378
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -23,6 +23,7 @@ Updated docs can be found on [the new website](https://vanniktech.github.io/grad
which repository to drop by adding a `--repository` parameter with the id of the staging repository that was
printed during `publish`. If no repository is specified and there is only one staging repository, that one
will be dropped.
- Added workaround to also publish sources for the `java-test-fixtures` plugin
- Fixed publishing Kotlin/JS projects with the base plugin.
- Fixed that a POM configured through the DSL is incomplete when publishing Gradle plugins.
- The minimum supported Gradle version has been increased to 7.3.
Expand Down
@@ -0,0 +1,7 @@
package com.vanniktech.maven.publish.test;

/**
* Just a test fixture class.
*/
public class TestFixtureClass {
}
Expand Up @@ -61,6 +61,36 @@ class MavenPublishPluginPlatformTest {
assertThat(result).javadocJar().isSigned()
}

@TestParameterInjectorTest
fun javaLibraryWithTestFixturesProject() {
val default = javaLibraryProjectSpec()
val project = default.copy(
plugins = default.plugins + javaTestFixturesPlugin,
sourceFiles = default.sourceFiles +
SourceFile("testFixtures", "java", "com/vanniktech/maven/publish/test/TestFixtureClass.java")
)
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(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 javaGradlePluginProject() {
val project = javaGradlePluginProjectSpec()
Expand Down
Expand Up @@ -7,7 +7,13 @@ import org.apache.maven.model.License
import org.apache.maven.model.Model
import org.apache.maven.model.Scm

data class PomDependency(val groupId: String, val artifactId: String, val version: String, val scope: String?)
data class PomDependency(
val groupId: String,
val artifactId: String,
val version: String,
val scope: String?,
val optional: Boolean? = null,
)

fun kotlinStdlibCommon(version: KotlinVersion) = PomDependency("org.jetbrains.kotlin", "kotlin-stdlib-common", version.value, "compile")
fun kotlinStdlibJdk(version: KotlinVersion) = PomDependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8", version.value, "compile")
Expand Down Expand Up @@ -74,6 +80,9 @@ fun createMinimalPom(
this.artifactId = it.artifactId
this.version = it.version
this.scope = it.scope
if (it.optional != null) {
this.isOptional = it.optional
}
}
)
}
Expand All @@ -87,6 +96,9 @@ fun createMinimalPom(
this.artifactId = it.artifactId
this.version = it.version
this.scope = it.scope
if (it.optional != null) {
this.isOptional = it.optional
}
}
)
}
Expand Down
Expand Up @@ -5,6 +5,7 @@ import java.nio.file.Paths
val javaPlugin = PluginSpec("java")
val javaLibraryPlugin = PluginSpec("java-library")
val javaGradlePluginPlugin = PluginSpec("java-gradle-plugin")
val javaTestFixturesPlugin = PluginSpec("java-test-fixtures")
val javaPlatformPlugin = PluginSpec("java-platform")
val versionCatalogPlugin = PluginSpec("version-catalog")
val kotlinJvmPlugin = PluginSpec("org.jetbrains.kotlin.jvm")
Expand Down
Expand Up @@ -182,7 +182,7 @@ class SourcesJarSubject private constructor(
}

val facts = mutableListOf<Fact>()
if (missingFiles.isNotEmpty() && zipFiles.isNotEmpty()) {
if (missingFiles.isNotEmpty()) {
facts += fact("expected to contain", missingFiles)
facts += simpleFact("but did not.")
}
Expand Down
11 changes: 11 additions & 0 deletions plugin/src/main/kotlin/com/vanniktech/maven/publish/Platform.kt
Expand Up @@ -5,9 +5,11 @@ import com.vanniktech.maven.publish.tasks.JavadocJar.Companion.javadocJarTask
import com.vanniktech.maven.publish.tasks.SourcesJar.Companion.javaSourcesJar
import com.vanniktech.maven.publish.tasks.SourcesJar.Companion.kotlinSourcesJar
import org.gradle.api.Project
import org.gradle.api.plugins.jvm.internal.JvmModelingServices
import org.gradle.api.provider.Provider
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.TaskProvider
import org.gradle.configurationcache.extensions.serviceOf

/**
* Represents a platform that the plugin supports to publish. For example [JavaLibrary], [AndroidMultiVariantLibrary] or
Expand Down Expand Up @@ -54,6 +56,15 @@ data class JavaLibrary @JvmOverloads constructor(
it.withSourcesJar { project.javaSourcesJar(sourcesJar) }
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()
}
}
}
}
}

Expand Down

0 comments on commit f238378

Please sign in to comment.