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

add specific support to Gradle plugin publish plugin #543

Merged
merged 2 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
sources jar creation for Kotlin/JS projects anymore starting with 1.8.20. The `KotlinJs` constructor
with a `sourcesJar` parameter has been deprecated.
- Fix incompatibility with Gradle 8.1 for `java-test-fixtures` projects
- Fix incompatibility with `com.gradle.plugin-publish` 1.0.0 and 1.1.0
- New minimum supported versions:
- Gradle 7.4
- Android Gradle Plugin 7.3.0
- Kotlin Gradle Plugin 1.7.0
- `com.gradle.plugin-publish` 1.0.0
- Note: Starting with Kotlin 1.8.20-Beta the `common` sources jar for multiplatform projects will only contain
the sources of the common source set instead of containing the sources from all source sets.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The output of the following Gradle plugins is supported to be published with thi
- `java`
- `java-library`
- `java-gradle-plugin`
- `com.gradle.plugin-publish`
- `java-platform`
- `version-catalog`

Expand Down
29 changes: 27 additions & 2 deletions docs/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ For projects using the `org.jetbrains.kotlin.multiplatform` plugin.

### Gradle Plugin


For projects using the `java-gradle-plugin` plugin.
For projects using the `java-gradle-plugin` plugin. When also using `com.gradle.plugin-publish` please
use [GradlePublishPlugin](#gradle-publish-plugin)

=== "build.gradle"

Expand Down Expand Up @@ -338,6 +338,31 @@ For projects using the `java-gradle-plugin` plugin.
}
```

### Gradle Publish Plugin

For projects using the `com.gradle.plugin-publish` plugin. This will always publish a sources jar
and a javadoc jar.

=== "build.gradle"

```groovy
import com.vanniktech.maven.publish.GradlePublishPlugin

mavenPublishing {
configure(new GradlePublishPlugin())
}
```

=== "build.gradle.kts"

```kotlin
import com.vanniktech.maven.publish.GradlePublishPlugin

mavenPublishing {
configure(GradlePublishPlugin())
}
```

### Java Platform


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,36 @@ class MavenPublishPluginPlatformTest {
)
}

@TestParameterInjectorTest
fun javaGradlePluginWithPluginPublishProject(@TestParameter gradlePluginPublish: GradlePluginPublish) {
val project = javaGradlePluginWithGradlePluginPublish(gradlePluginPublish)
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()
assertThat(result).module().exists()
assertThat(result).module().isSigned()
assertThat(result).sourcesJar().exists()
assertThat(result).sourcesJar().isSigned()
assertThat(result).sourcesJar().containsAllSourceFiles()
assertThat(result).javadocJar().exists()
assertThat(result).javadocJar().isSigned()

val pluginId = "com.example.test-plugin"
val pluginMarkerSpec = project.copy(group = pluginId, artifactId = "$pluginId.gradle.plugin")
val pluginMarkerResult = result.copy(projectSpec = pluginMarkerSpec)
assertThat(pluginMarkerResult).pom().exists()
assertThat(pluginMarkerResult).pom().isSigned()
assertThat(pluginMarkerResult).pom().matchesExpectedPom(
"pom",
PomDependency("com.example", "test-artifact", "1.0.0", null),
)
}

@TestParameterInjectorTest
fun javaGradlePluginKotlinProject(
@TestParameter(valuesProvider = KotlinVersionProvider::class) kotlinVersion: KotlinVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private fun writeSettingFile(path: Path) {
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val kotlinMultiplatformPlugin = PluginSpec("org.jetbrains.kotlin.multiplatform")
val kotlinJsPlugin = PluginSpec("org.jetbrains.kotlin.js")
val kotlinAndroidPlugin = PluginSpec("org.jetbrains.kotlin.android")
val androidLibraryPlugin = PluginSpec("com.android.library")
val gradlePluginPublishPlugin = PluginSpec("com.gradle.plugin-publish")

val fixtures = Paths.get("src/integrationTest/fixtures2").toAbsolutePath()

Expand Down Expand Up @@ -88,6 +89,14 @@ fun javaGradlePluginProjectSpec() = ProjectSpec(
basePluginConfig = "configure(new GradlePlugin(new JavadocJar.Empty(), true))",
)

fun javaGradlePluginWithGradlePluginPublish(gradlePluginPublish: GradlePluginPublish): ProjectSpec {
val base = javaGradlePluginProjectSpec()
return base.copy(
plugins = base.plugins + gradlePluginPublishPlugin.copy(version = gradlePluginPublish.version),
basePluginConfig = "configure(new GradlePublishPlugin())",
)
}

fun javaGradlePluginKotlinProjectSpec(version: KotlinVersion): ProjectSpec {
val plainJavaGradlePluginProject = javaGradlePluginProjectSpec()
return plainJavaGradlePluginProject.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ enum class GradleVersion(val value: String) {
val GRADLE_7_6 = GRADLE_8_0
}
}

enum class GradlePluginPublish(val version: String) {
// minimum supported
GRADLE_PLUGIN_PUBLISH_1_0("1.0.0"),

// stable
GRADLE_PLUGIN_PUBLISH_1_1("1.1.0"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ private fun Project.configurePlatform() {
when {
plugins.hasPlugin("org.jetbrains.kotlin.multiplatform") -> {} // Handled above.
plugins.hasPlugin("com.android.library") -> {} // Handled above.
plugins.hasPlugin("com.gradle.plugin-publish") ->
baseExtension.configure(GradlePublishPlugin())
plugins.hasPlugin("java-gradle-plugin") ->
baseExtension.configure(GradlePlugin(defaultJavaDocOption() ?: javadoc()))
plugins.hasPlugin("org.jetbrains.kotlin.jvm") ->
Expand Down
16 changes: 16 additions & 0 deletions plugin/src/main/kotlin/com/vanniktech/maven/publish/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ data class GradlePlugin @JvmOverloads constructor(
}
}

/**
* To be used for `com.gradle.plugin-publish` projects. Uses the default publication that gets created by that plugin.
*/
class GradlePublishPlugin : Platform() {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
class GradlePublishPlugin : Platform() {
object GradlePublishPlugin : Platform() {

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Object is awkward to use from Groovy unfortunately


override val javadocJar: JavadocJar = JavadocJar.Javadoc()
override val sourcesJar: Boolean = true

override fun configure(project: Project) {
// setup is fully handled by com.gradle.plugin-publish already
}

override fun equals(other: Any?): Boolean = other is GradlePublishPlugin
override fun hashCode(): Int = this::class.hashCode()
}

/**
* To be used for `com.android.library` projects. Applying this creates a publication for the component of the given
* `variant`. Depending on the passed parameters for [javadocJar] and [sourcesJar], `-javadoc` and `-sources` jars will
Expand Down