Skip to content

Commit

Permalink
Test publishing shadowed Gradle plugin (GradleUp#1156)
Browse files Browse the repository at this point in the history
* Add publishShadowedGradlePluginWithMavenPublishPlugin

* Disable CC for publish task to fix the flaky results

* Revert "Disable CC for publish task to fix the flaky results"

This reverts commit b49478c.

* Disable automatedPublishing

* Revert "Disable automatedPublishing"

This reverts commit 2374943.

* Add plugin-publish-with-shadow project for testing

* Revert "Add plugin-publish-with-shadow project for testing"

This reverts commit eb90843.

* Apply com.gradle.plugin-publish and fix flaky tests

* Tweak checks

* Note com.gradle.plugin-publish in plugin publication doc

* Cleanups
  • Loading branch information
Goooler authored Jan 18, 2025
1 parent 66e89ce commit 1845e43
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
implementation(libs.plexus.xml)

testPluginClasspath(libs.foojayResolver)
testPluginClasspath(libs.pluginPublish)

lintChecks(libs.androidx.gradlePluginLints)
}
Expand Down
2 changes: 1 addition & 1 deletion src/docs/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A simple Gradle plugin can use this feature by applying the `shadow` plugin and

```groovy
plugins {
id 'java-gradle-plugin'
id 'java-gradle-plugin' // May have to apply the latest `com.gradle.plugin-publish` for better publishing support.
id 'com.gradleup.shadow'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ abstract class BasePluginTest {
gradlePluginBlock = """
gradlePlugin {
plugins {
create("myPlugin") {
create('myPlugin') {
id = '$pluginId'
implementationClass = '$pluginClass'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import assertk.assertions.contains
import assertk.assertions.containsOnly
import assertk.assertions.isEmpty
import assertk.assertions.isEqualTo
import assertk.assertions.single
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME
import com.github.jengelman.gradle.plugins.shadow.util.GradleModuleMetadata
import com.github.jengelman.gradle.plugins.shadow.util.Issue
Expand All @@ -21,7 +20,8 @@ import java.nio.file.Path
import kotlin.io.path.appendText
import kotlin.io.path.exists
import kotlin.io.path.inputStream
import kotlin.io.path.isRegularFile
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name
import kotlin.io.path.readText
import kotlin.io.path.writeText
import org.apache.maven.model.Model
Expand All @@ -36,6 +36,8 @@ import org.gradle.testkit.runner.BuildResult
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.io.TempDir
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource

class PublishingTest : BasePluginTest() {
private val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
Expand Down Expand Up @@ -90,6 +92,43 @@ class PublishingTest : BasePluginTest() {
assertShadowVariantCommon(gmmAdapter.fromJson(repoPath("shadow/maven/1.0/maven-1.0.module")))
}

@ParameterizedTest
@ValueSource(booleans = [false, true])
fun publishShadowedGradlePluginWithMavenPublishPlugin(legacy: Boolean) {
writeGradlePluginModule(legacy)
projectScriptPath.appendText(
publishConfiguration(
projectBlock = """
apply plugin: 'com.gradle.plugin-publish'
group = 'my.plugin'
version = '1.0'
""".trimIndent(),
shadowBlock = """
archiveClassifier = ''
""".trimIndent(),
publicationsBlock = """
pluginMaven(MavenPublication) {
artifactId = 'my-gradle-plugin'
}
""".trimIndent(),
),
)

publish()

val artifactRoot = "my/plugin/my-gradle-plugin/1.0"
assertThat(repoPath(artifactRoot).listDirectoryEntries("*.jar").map(Path::name)).containsOnly(
"my-gradle-plugin-1.0.jar",
"my-gradle-plugin-1.0-javadoc.jar",
"my-gradle-plugin-1.0-sources.jar",
)

val artifactPrefix = "$artifactRoot/my-gradle-plugin-1.0"
assertShadowJarCommon(repoJarPath("$artifactPrefix.jar"))
assertPomCommon(repoPath("$artifactPrefix.pom"))
assertShadowVariantCommon(gmmAdapter.fromJson(repoPath("$artifactPrefix.module")))
}

@Issue(
"https://github.com/GradleUp/shadow/issues/860",
"https://github.com/GradleUp/shadow/issues/945",
Expand Down Expand Up @@ -256,7 +295,6 @@ class PublishingTest : BasePluginTest() {
private fun repoPath(relative: String): Path {
return remoteRepoPath.resolve(relative).also {
check(it.exists()) { "Path not found: $it" }
check(it.isRegularFile()) { "Path is not a regular file: $it" }
}
}

Expand Down

0 comments on commit 1845e43

Please sign in to comment.