diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8060056..198c322 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index ee53f84..963c4f5 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -3,7 +3,6 @@ plugins { alias(libs.plugins.gradle.pluginPublish) alias(libs.plugins.jacoco.testkit) alias(libs.plugins.publicationsReport) - alias(libs.plugins.buildConfig) jacoco } @@ -70,12 +69,37 @@ tasks.withType { } 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) } diff --git a/plugin/src/test/kotlin/com/github/gmazzo/buildconfig/BuildConfigPluginTest.kt b/plugin/src/test/kotlin/com/github/gmazzo/buildconfig/BuildConfigPluginTest.kt index 4c5cc28..63c6fde 100644 --- a/plugin/src/test/kotlin/com/github/gmazzo/buildconfig/BuildConfigPluginTest.kt +++ b/plugin/src/test/kotlin/com/github/gmazzo/buildconfig/BuildConfigPluginTest.kt @@ -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 @@ -65,7 +64,7 @@ class BuildConfigPluginTest { """ pluginManagement { repositories { - maven { url file("../../../../../${BuildConfig.LOCAL_REPO}") } + maven { url file("../../../../../${TestConstants.LOCAL_REPO}") } gradlePluginPortal() } } @@ -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'