Skip to content

Commit

Permalink
Fix issue #5 caused by incompatible Gradle API
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonlee committed May 18, 2022
1 parent c9ff9b3 commit 8a01b57
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
java-version: '8'

- name: build
run: ./gradlew build -S --no-daemon
run: ./gradlew check -S --no-daemon
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {

testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
testImplementation("com.didiglobal.booster:booster-kotlinx:4.8.0")
}

gradlePlugin {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package io.johnsonlee.gradle.publish

import com.didiglobal.booster.kotlinx.file
import com.didiglobal.booster.kotlinx.touch
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import java.io.File
import kotlin.test.Test
import kotlin.test.assertTrue

class KotlinLibraryFunctionalTest {

private val tmp = File("build", "tmp").also(File::mkdirs)

@Test
fun `publish kotlin library to maven local with gradle 6_2`() {
val result = publishToMavenLocal("6.2")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_2_1`() {
val result = publishToMavenLocal("6.2.1")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_2_2`() {
val result = publishToMavenLocal("6.2.2")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_3`() {
val result = publishToMavenLocal("6.3")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_4`() {
val result = publishToMavenLocal("6.4")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_4_1`() {
val result = publishToMavenLocal("6.4.1")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_5`() {
val result = publishToMavenLocal("6.5")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_5_1`() {
val result = publishToMavenLocal("6.5.1")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_6`() {
val result = publishToMavenLocal("6.6")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_6_1`() {
val result = publishToMavenLocal("6.6.1")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_7`() {
val result = publishToMavenLocal("6.7")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_7_1`() {
val result = publishToMavenLocal("6.7.1")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_8`() {
val result = publishToMavenLocal("6.8")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_8_1`() {
val result = publishToMavenLocal("6.8.1")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_8_2`() {
val result = publishToMavenLocal("6.8.2")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_8_3`() {
val result = publishToMavenLocal("6.8.3")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}

@Test
fun `publish kotlin library to maven local with gradle 6_9`() {
val result = publishToMavenLocal("6.9")
assertTrue(result.tasks.none { it.outcome == TaskOutcome.FAILED })
}
private fun publishToMavenLocal(gradleVersion: String): BuildResult {
val projectDir = createTempDir(directory = tmp).apply {
file("settings.gradle.kts").writeText("")
file("build.gradle.kts").writeText("""
plugins {
kotlin("jvm") version embeddedKotlinVersion
id("io.johnsonlee.sonatype-publish-plugin")
}
repositories {
mavenCentral()
google()
}
group = "io.johnsonlee.functional-test"
version = "1.0.0"
""".trimIndent())
file("src", "main", "kotlin", "Library.kt").touch().writeText("""
object Library {
fun init() {
}
}
""".trimIndent())
}

try {
return GradleRunner.create().apply {
forwardOutput()
withGradleVersion(gradleVersion)
withPluginClasspath()
withArguments("publishToMavenLocal", "-S")
withProjectDir(projectDir)
}.build()
} finally {
projectDir.deleteRecursively()
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.repositories
import org.gradle.util.GradleVersion

class AndroidLibraryPublishPlugin : AbstractLibraryPublishPlugin() {

Expand Down Expand Up @@ -49,11 +51,16 @@ class AndroidLibraryPublishPlugin : AbstractLibraryPublishPlugin() {
from(android.sourceSets["main"].java.srcDirs)
}

create(variant.name, MavenPublication::class.java) {
register(variant.name, MavenPublication::class) {
configure(project)
from(components[variant.name])
artifact(javadocJar)
artifact(sourcesJar)
if (GradleVersion.current() >= GRADLE_6_6) {
artifact(javadocJar)
artifact(sourcesJar)
} else {
artifact(javadocJar.get())
artifact(sourcesJar.get())
}
config.invoke(this)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/io/johnsonlee/gradle/publish/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.johnsonlee.gradle.publish

import org.gradle.util.GradleVersion

internal val GRADLE_6_6 = GradleVersion.version("6.6")
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.the
import org.gradle.util.GradleVersion

open class JavaLibraryPublishPlugin : AbstractLibraryPublishPlugin() {

Expand All @@ -32,8 +33,13 @@ open class JavaLibraryPublishPlugin : AbstractLibraryPublishPlugin() {

configure(project)
from(components["java"])
artifact(javadocJar)
artifact(sourcesJar)
if (GradleVersion.current() >= GRADLE_6_6) {
artifact(javadocJar)
artifact(sourcesJar)
} else {
artifact(javadocJar.get())
artifact(sourcesJar.get())
}
config.invoke(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.the
import org.gradle.util.GradleVersion

open class KotlinLibraryPublishPlugin : AbstractLibraryPublishPlugin() {

Expand All @@ -31,8 +32,13 @@ open class KotlinLibraryPublishPlugin : AbstractLibraryPublishPlugin() {

configure(project)
from(components["java"])
artifact(javadocJar)
artifact(sourcesJar)
if (GradleVersion.current() >= GRADLE_6_6) {
artifact(javadocJar)
artifact(sourcesJar)
} else {
artifact(javadocJar.get())
artifact(sourcesJar.get())
}
config.invoke(this)
}
}
Expand Down

0 comments on commit 8a01b57

Please sign in to comment.