Skip to content

Commit

Permalink
Removed plugin self reference for tests 🤦 (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo authored Jul 9, 2024
1 parent db8737f commit 1deb2c3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mockk = { module = "io.mockk:mockk", version = "1.13.11" }

[plugins]
android = { id = "com.android.application", version = "8.5.0" }
buildConfig = "com.github.gmazzo.buildconfig:5.3.5"
gradle-pluginPublish = { id = "com.gradle.plugin-publish", version = "1.2.1" }
jacoco-testkit = { id = "pl.droidsonroids.jacoco.testkit", version = "1.0.12" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Expand Down
34 changes: 29 additions & 5 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ plugins {
alias(libs.plugins.gradle.pluginPublish)
alias(libs.plugins.jacoco.testkit)
alias(libs.plugins.publicationsReport)
alias(libs.plugins.buildConfig)
jacoco
}

Expand Down Expand Up @@ -70,12 +69,37 @@ tasks.withType<Test> {
}

val localRepoDir = layout.buildDirectory.dir("repo")
val localRepo = publishing.repositories.maven(localRepoDir) { name = "Local" }
buildConfig {
buildConfigField("LOCAL_REPO", localRepoDir.map { it.asFile.relativeToOrSelf(tasks.test.get().workingDir) })
buildConfigField("LOCAL_VERSION", provider { version.toString() })

publishing.repositories.maven(localRepoDir) { name = "Local" }

val generateTestLocalConstants by tasks.registering {
val localVersion = provider { project.version }
val localRepo = layout.buildDirectory.dir("repo")
.map { it.asFile.toRelativeString(tasks.test.get().workingDir) }

inputs.property("version", localVersion)
inputs.property("localRepo", localRepo)
outputs.dir(temporaryDir)
notCompatibleWithConfigurationCache("uses Task.project")
doLast {
temporaryDir.resolve("TestLocalConstants.kt").writeText(
"""
package com.github.gmazzo.buildconfig
object TestConstants {
const val LOCAL_VERSION = "${localVersion.get()}"
const val LOCAL_REPO = "${localRepo.get()}"
}
""".trimIndent()
)
}
}

kotlin.sourceSets.test {
kotlin.srcDirs(generateTestLocalConstants)
}


tasks.pluginUnderTestMetadata {
pluginClasspath.from(pluginUnderTestDependencies)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.gmazzo.buildconfig

import com.github.gmazzo.buildconfig.plugin.BuildConfig
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.tooling.internal.consumer.DefaultGradleConnector
Expand Down Expand Up @@ -65,7 +64,7 @@ class BuildConfigPluginTest {
"""
pluginManagement {
repositories {
maven { url file("../../../../../${BuildConfig.LOCAL_REPO}") }
maven { url file("../../../../../${TestConstants.LOCAL_REPO}") }
gradlePluginPortal()
}
}
Expand All @@ -77,7 +76,7 @@ class BuildConfigPluginTest {
projectDir.resolve("build.gradle").writeText("""
plugins {
id ${kotlinVersion?.let { "'org.jetbrains.kotlin.jvm' version '$kotlinVersion'" } ?: "'java'"}
id 'com.github.gmazzo.buildconfig' version '${BuildConfig.LOCAL_VERSION}'
id 'com.github.gmazzo.buildconfig' version '${TestConstants.LOCAL_VERSION}'
}
""" + (if (withPackage) """
group = 'gs.test'
Expand Down

0 comments on commit 1deb2c3

Please sign in to comment.