Skip to content

Commit

Permalink
Merge pull request deepmedia#13 from 0xera/classpath_dependencies
Browse files Browse the repository at this point in the history
add dependencies from grease configuration to compileOnly
  • Loading branch information
0xera authored Oct 8, 2024
2 parents c081400 + 6b7559d commit c4dae7c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
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

0 comments on commit c4dae7c

Please sign in to comment.