From c0814006d9c57429f34d459435f72c7255d8abc7 Mon Sep 17 00:00:00 2001 From: 0xera <56160164+0xera@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:25:21 +0300 Subject: [PATCH 1/4] Attempt to fix binary compatibility issue with agp 8.6 (#12) --- .../io/deepmedia/tools/grease/GreasePlugin.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt b/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt index 71b99a9..62e82cb 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/GreasePlugin.kt @@ -118,7 +118,7 @@ open class GreasePlugin : Plugin { val componentConfig = variant.componentCreationConfigOrThrow() - target.locateTask(componentConfig.computeTaskName("process", "Manifest"))?.configure { + target.locateTask(componentConfig.resolveTaskName("process", "Manifest"))?.configure { val processManifestTask = this as ProcessLibraryManifest val extraManifests = configurations.artifactsOf(AndroidArtifacts.ArtifactType.MANIFEST) @@ -218,7 +218,7 @@ open class GreasePlugin : Plugin { val creationConfig = variant.componentCreationConfigOrThrow() - target.locateTask(creationConfig.computeTaskName("copy", "JniLibsProjectAndLocalJars"))?.configure { + target.locateTask(creationConfig.resolveTaskName("copy", "JniLibsProjectAndLocalJars"))?.configure { val copyJniTask = this as LibraryJniLibsTask val extraJniLibs = configurations.artifactsOf(AndroidArtifacts.ArtifactType.JNI) dependsOn(extraJniLibs) @@ -315,7 +315,7 @@ open class GreasePlugin : Plugin { log.d { "Configuring variant ${variant.name}..." } val creationConfig = variant.componentCreationConfigOrThrow() - target.locateTask(creationConfig.computeTaskName("package", "Resources"))?.configure { + target.locateTask(creationConfig.resolveTaskName("package", "Resources"))?.configure { this as MergeResources val resourcesMergingWorkdir = target.greaseBuildDir.get().dir(variant.name).dir("resources") @@ -393,7 +393,7 @@ open class GreasePlugin : Plugin { val bundleLibraryTask = creationConfig.taskContainer.bundleLibraryTask val greaseExpandTask = target.tasks.locateOrRegisterTask( - creationConfig.computeTaskName("extract", "Aar").greasify(), + creationConfig.resolveTaskName("extract", "Aar").greasify(), ) { val bundleAar = bundleLibraryTask?.get() as BundleAar @@ -409,7 +409,7 @@ open class GreasePlugin : Plugin { } val greaseProcessTask = target.tasks.locateOrRegisterTask( - creationConfig.computeTaskName("process", "Jar").greasify(), + creationConfig.resolveTaskName("process", "Jar").greasify(), ) { // There are many options here. PROCESSED_JAR, PROCESSED_AAR, CLASSES, CLASSES_JAR ... @@ -440,7 +440,7 @@ open class GreasePlugin : Plugin { } val greaseShadowTask = target.tasks.locateOrRegisterTask( - creationConfig.computeTaskName("shadow", "Aar").greasify(), + creationConfig.resolveTaskName("shadow", "Aar").greasify(), ShadowJar::class.java ) { val compileTask = creationConfig.taskContainer.javacTask @@ -645,7 +645,7 @@ open class GreasePlugin : Plugin { val log = logger.child("configureVariantProguardFiles") log.d { "Configuring variant ${variant.name}..." } val creationConfig = variant.componentCreationConfigOrThrow() - target.locateTask(creationConfig.computeTaskName("merge", "ConsumerProguardFiles"))?.configure { + target.locateTask(creationConfig.resolveTaskName("merge", "ConsumerProguardFiles"))?.configure { val mergeFileTask = this as MergeFileTask // UNFILTERED_PROGUARD_RULES, FILTERED_PROGUARD_RULES, AAPT_PROGUARD_RULES, ... // UNFILTERED_PROGUARD_RULES is output of the AarTransform. FILTERED_PROGUARD_RULES @@ -661,7 +661,7 @@ open class GreasePlugin : Plugin { } } -private fun ComponentCreationConfig.computeTaskName(prefix: String, suffix: String): String = +private fun ComponentCreationConfig.resolveTaskName(prefix: String, suffix: String): String = prefix.appendCapitalized(name, suffix) private fun Variant.componentCreationConfigOrThrow(): ComponentCreationConfig { From c72fcf089c575fc1fb799222234809ce28ff5c09 Mon Sep 17 00:00:00 2001 From: 0xera <56160164+0xera@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:41:50 +0300 Subject: [PATCH 2/4] add dependencies from grease configuration to compileOnly --- .../src/main/kotlin/io/deepmedia/tools/grease/configurations.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt b/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt index abf86fe..c5f166c 100644 --- a/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt +++ b/grease/src/main/kotlin/io/deepmedia/tools/grease/configurations.kt @@ -80,7 +80,7 @@ private fun Project.createGrease(name: String, isTransitive: Boolean): Configura } configurations.configureEach { val other = this - if (other.name == nameOf(name, "compileClasspath")) { + if (other.name == nameOf(name, "compileOnly")) { other.extendsFrom(configuration) } } From 6b7559d70d029617a4973bda76afc97e264a8c27 Mon Sep 17 00:00:00 2001 From: 0xera <56160164+0xera@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:04:45 +0300 Subject: [PATCH 3/4] add function test to check pom file --- grease/build.gradle.kts | 18 +++ .../tools/grease/GeneratedPomFileTest.kt | 104 ++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt diff --git a/grease/build.gradle.kts b/grease/build.gradle.kts index cd9a10f..8144800 100644 --- a/grease/build.gradle.kts +++ b/grease/build.gradle.kts @@ -1,4 +1,5 @@ plugins { + `jvm-test-suite` `kotlin-dsl` alias(libs.plugins.publisher) } @@ -6,6 +7,21 @@ plugins { group = "io.deepmedia.tools" version = "0.3.2" +testing { + suites { + register("functionalTest") { + useJUnit() + testType.set(TestSuiteType.FUNCTIONAL_TEST) + + dependencies { + implementation(gradleTestKit()) + implementation(project.dependencies.kotlin("test") as String) + implementation(project.dependencies.kotlin("test-junit") as String) + } + } + } +} + gradlePlugin { plugins { create("grease") { @@ -13,6 +29,8 @@ gradlePlugin { implementationClass = "io.deepmedia.tools.grease.GreasePlugin" } } + + testSourceSets(sourceSets["functionalTest"]) } dependencies { diff --git a/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt b/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt new file mode 100644 index 0000000..98a15da --- /dev/null +++ b/grease/src/functionalTest/kotlin/io/deepmedia/tools/grease/GeneratedPomFileTest.kt @@ -0,0 +1,104 @@ +package io.deepmedia.tools.grease + +import org.gradle.testkit.runner.GradleRunner +import java.nio.file.Path +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.createTempDirectory +import kotlin.io.path.deleteRecursively +import kotlin.io.path.readText +import kotlin.io.path.writeText +import kotlin.test.AfterTest +import kotlin.test.BeforeTest +import kotlin.test.Test +import kotlin.test.assertContains +import kotlin.test.assertFails +import kotlin.test.assertFalse + +class GeneratedPomFileTest { + + private var testProjectDir = createTempDirectory("tmp") + private lateinit var settingsFile: Path + private lateinit var buildFile: Path + + @BeforeTest + fun setup() { + settingsFile = testProjectDir.resolve("settings.gradle.kts") + buildFile = testProjectDir.resolve("build.gradle.kts") + } + + @Test + fun test() { + buildFile.writeText( + """ + plugins { + `maven-publish` + id("com.android.library") version "8.1.4" + } + + apply() + + android { + namespace = "io.deepmedia.tools.grease.sample" + compileSdk = 34 + defaultConfig { + minSdk = 21 + } + publishing { + singleVariant("debug") { + withSourcesJar() + } + } + } + + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + + publishing { + publications { + create("Test", MavenPublication::class.java) { + afterEvaluate { + from(components["debug"]) + } + } + } + } + dependencies { + "grease"("com.otaliastudios:cameraview:2.7.2") + "greaseTree"("androidx.core:core:1.0.0") + } + """.trimIndent() + ) + + settingsFile.writeText(""" + pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } + } + + rootProject.name = "Sample" + """.trimIndent()) + + GradleRunner.create() + .withPluginClasspath() + .withProjectDir(testProjectDir.toFile()) + .forwardOutput() + .withArguments("generatePomFileForTestPublication") + .build() + + val pomContent = testProjectDir.resolve("build/publications/Test/pom-default.xml").readText() + assertFalse(pomContent.contains("androidx.core") ) + assertFalse(pomContent.contains("com.otaliastudios") ) + } + + @OptIn(ExperimentalPathApi::class) + @AfterTest + fun teardown() { + testProjectDir.deleteRecursively() + } +} \ No newline at end of file From 41d3a71d6862c731a3c93d6db14bfd78450b6436 Mon Sep 17 00:00:00 2001 From: 0xera <56160164+0xera@users.noreply.github.com> Date: Tue, 8 Oct 2024 17:32:34 +0300 Subject: [PATCH 4/4] Bump version to 0.3.3 (#14) --- README.md | 4 ++-- grease/build.gradle.kts | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a4213a..cea9342 100644 --- a/README.md +++ b/README.md @@ -18,11 +18,11 @@ pluginManagement { // build.gradle.kts plugins { id("com.android.library") - id("io.deepmedia.tools.grease") version "0.3.2" + id("io.deepmedia.tools.grease") version "0.3.3" } ``` -Note: it is important that Grease is applied *after* the Android library plugin. +Note: The minimum required version of Gradle is 8.3 ## Usage diff --git a/grease/build.gradle.kts b/grease/build.gradle.kts index 8144800..5489501 100644 --- a/grease/build.gradle.kts +++ b/grease/build.gradle.kts @@ -1,3 +1,5 @@ +@file:Suppress("UnstableApiUsage") + plugins { `jvm-test-suite` `kotlin-dsl` @@ -5,7 +7,7 @@ plugins { } group = "io.deepmedia.tools" -version = "0.3.2" +version = "0.3.3" testing { suites {