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 dependencies from grease configuration to compileOnly #13

Merged
merged 2 commits into from
Oct 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions grease/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
plugins {
`jvm-test-suite`
`kotlin-dsl`
alias(libs.plugins.publisher)
}

group = "io.deepmedia.tools"
version = "0.3.2"

testing {
suites {
register<JvmTestSuite>("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") {
id = "io.deepmedia.tools.grease"
implementationClass = "io.deepmedia.tools.grease.GreasePlugin"
}
}

testSourceSets(sourceSets["functionalTest"])
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<io.deepmedia.tools.grease.GreasePlugin>()

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("<groupId>androidx.core</groupId>") )
assertFalse(pomContent.contains("<groupId>com.otaliastudios</groupId>") )
}

@OptIn(ExperimentalPathApi::class)
@AfterTest
fun teardown() {
testProjectDir.deleteRecursively()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down