Skip to content

Conversation

OliverO2
Copy link
Contributor

@OliverO2 OliverO2 commented Jun 17, 2024

  • Define an input dependency for the task updateKotestPluginConstants, to prevent Gradle from skipping it with "NO-SOURCE".
  • Avoid failing the build with an undefined symbol "KOTEST_COMPILER_PLUGIN_VERSION".
  • Make the clean task compatible with the configuration cache.

OliverO2 added 2 commits June 17, 2024 17:36
* Define an input dependency for the task `updateKotestPluginConstants`,
  to prevent Gradle from skipping it with "NO-SOURCE".
* Avoid failing the build with an undefined symbol
  "KOTEST_COMPILER_PLUGIN_VERSION".
* Make the delete task compatible with the configuration cache.
Otherwise:
> Inconsistent JVM-target compatibility detected for tasks
  'compileJava' (17) and 'compileKotlin' (1.8).
@OliverO2 OliverO2 requested a review from aSemy June 17, 2024 16:15
@OliverO2 OliverO2 enabled auto-merge June 17, 2024 16:27
@OliverO2 OliverO2 disabled auto-merge June 17, 2024 16:49
@aSemy
Copy link
Contributor

aSemy commented Jun 17, 2024

Oh, interesting! Good catch. I guess that TextResource isn't compatible with configuration cache.

@OliverO2
Copy link
Contributor Author

With the dedicated task class, there was no longer a need for TextResource. The configuration cache complaints were caused by $projectDir in the clean task configuration.

@aSemy
Copy link
Contributor

aSemy commented Jun 17, 2024

Do you mind if I refactor it to use the dynamic task dsl? I find it more appropriate for tasks that are defined in a build script.

val updateKotestPluginConstants by tasks.registering {
   val kotestPluginConstants = """
      |// Generated file, do not edit manually
      |@file:org.gradle.api.Generated
      |
      |package io.kotest.framework.multiplatform.gradle
      |
      |const val KOTEST_COMPILER_PLUGIN_VERSION: String = "${Ci.gradleVersion}"
      |
   """.trimMargin()

   inputs.property("kotestPluginConstants", kotestPluginConstants)

   val outputDir = layout.buildDirectory.dir("generated/src/main/kotlin/")
   outputs.dir(outputDir).withPropertyName("outputDir")

   doLast {
      val kotestPluginConstantsFile = outputDir.get().asFile
         .resolve("io/kotest/framework/multiplatform/gradle/kotestPluginConstants.kt")

      kotestPluginConstantsFile.apply {
         parentFile.deleteRecursively()
         parentFile.mkdirs()
         writeText(kotestPluginConstants)
      }
   }
}

kotlin.sourceSets.main {
   kotlin.srcDir(updateKotestPluginConstants)
}

(GitHub won't let me add this as a code suggestion)

Otherwise, I'd prefer moving the class-based task into buildSrc.

@OliverO2
Copy link
Contributor Author

No, I don't mind at all. That's what I've tried to achieve first. Just could not find the input.property trick. I'm just a casual Gradle user after all... ;-)

@OliverO2 OliverO2 enabled auto-merge June 17, 2024 22:20
@OliverO2 OliverO2 added this pull request to the merge queue Jun 17, 2024
Merged via the queue into master with commit e7f7e52 Jun 17, 2024
@OliverO2 OliverO2 deleted the oo2/fix-gradle-plugin-build branch June 17, 2024 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants