jamesfredley commented on code in PR #11:
URL: https://github.com/apache/grails-micronaut/pull/11#discussion_r4225112905


##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy:
##########
@@ -155,6 +175,60 @@ class CompilePlugin implements Plugin<Project> {
         }
     }
 
+    /**
+     * Writes the Groovy compiler configuration for {@code compile}, including 
the shared
+     * reproducibility script and this project's published version.
+     *
+     * <p>The published version is captured in {@code afterEvaluate}, after 
the build script assigns
+     * {@code version}. The script file is produced by a task, not written 
during configuration, so
+     * {@code clean compileGroovy} in one invocation regenerates it after 
{@code clean} deletes
+     * {@code build/}.</p>
+     */
+    private static void configurePublishedVersionScript(Project project, 
GroovyCompile compile) {
+        File baseScript = GradleUtils.findRootGrailsCoreDir(project)
+                .file('gradle/groovy-compile-configscript.groovy').asFile
+        File output = 
project.layout.buildDirectory.file("groovy-compiler/${compile.name}-config.groovy").get().asFile
+        // Captured here, inside afterEvaluate, so version is the build 
script's value and the
+        // writer action does not touch the project. A configuration-time 
write would not survive
+        // `clean`, and compileGroovy would then fail because nothing 
regenerates its input.
+        String version = project.version?.toString() ?: ''
+        String name = project.name
+        String writerName = "grailsCompilerConfig${compile.name.capitalize()}"
+        // mustRunAfter(clean): `clean compileGroovy` schedules both, and 
command-line order is not a
+        // dependency. Without this, clean can delete the script after the 
writer creates it.
+        Task writer = project.tasks.register(writerName) { Task task ->
+            task.mustRunAfter('clean')
+            
task.inputs.file(baseScript).withPathSensitivity(PathSensitivity.NONE).withPropertyName('reproducibleCompilerScript')
+            task.inputs.property('publishedVersion', version)
+            task.inputs.property('publishedName', name)
+            task.outputs.file(output)
+            task.doLast {
+                writePublishedVersionScript(baseScript, output, version, name)
+            }
+        }.get()
+        compile.dependsOn(writer)
+        compile.groovyOptions.configurationScript = output
+    }
+
+    private static void writePublishedVersionScript(File baseScript, File 
output, String version, String name) {
+        output.parentFile.mkdirs()
+        String base = baseScript.exists() ? 
baseScript.getText(StandardCharsets.UTF_8.name()) : ''

Review Comment:
   Dropped the fallback. The base script is a required `@InputFile`, so a 
missing file fails input validation instead of writing an empty base. Fixed in 
d03db59a81.



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy:
##########
@@ -145,6 +147,24 @@ class CompilePlugin implements Plugin<Project> {
                 // when both are present.
                 it.groovyOptions.configurationScript =
                         
GradleUtils.findRootGrailsCoreDir(project).file('gradle/groovy-compile-configscript.groovy').asFile
+            }
+                // Stamp this repository's published version onto compiled 
classes after the build
+                // script has assigned version. Without the stamp, the Grails 
transform falls back to
+                // grails-core's Implementation-Version, so a snapshot build 
of this plugin would
+                // advertise the released framework version. The script is 
generated by a task so
+                // `clean compileGroovy` can recreate it after `clean` deletes 
`build/`.

Review Comment:
   That comment moved with the block it describes. The mis-indented 
`afterEvaluate` note is gone. Fixed in d03db59a81.



##########
build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/CompilePluginSpec.groovy:
##########
@@ -116,6 +116,90 @@ class CompilePluginSpec extends Specification {
         result.output.contains('TEST_INDY=true')
     }
 
+    def "compiler configuration stamps the published project version"() {
+        given:
+        testProjectDir.resolve('build.gradle').toFile().text = """
+            plugins {
+                id 'groovy'
+                id 'org.apache.grails.buildsrc.compile'
+            }
+
+            version = '8.0.0-SNAPSHOT'
+
+            ext {
+                javaVersion = 21
+                grailsVersion = '8.0.0'
+                formattedBuildDate = '2026-01-01'
+            }
+
+            repositories {
+                mavenCentral()
+            }
+        """
+
+        when:
+        def result = GradleRunner.create()
+                .withProjectDir(testProjectDir.toFile())
+                .withArguments(['grailsCompilerConfigCompileGroovy', 
'--stacktrace'])
+                .withPluginClasspath()
+                .build()
+
+        then:
+        result.task(':grailsCompilerConfigCompileGroovy').outcome == 
TaskOutcome.SUCCESS
+        def script = 
testProjectDir.resolve('build/groovy-compiler/compileGroovy-config.groovy').toFile().text
+        script.contains("putNodeMetaData('projectVersion', '8.0.0-SNAPSHOT')")
+        script.contains("putNodeMetaData('projectName',")

Review Comment:
   The spec now runs `-PprojectVersion=8.0.0` and 
`-PprojectVersion=8.0.0-SNAPSHOT`, asserts `projectName` is `grails-micronaut`, 
and checks that a project which does not apply the publish plugin keeps the 
shared script and does not register the writer. CI also configures `./gradlew 
help -PprojectVersion=8.0.0`. Fixed in d03db59a81.



##########
README.md:
##########
@@ -20,7 +20,7 @@ limitations under the License.
 
 This repository contains the Grails Micronaut plugin, its Micronaut-specific 
BOMs, and focused integration examples.
 
-The build consumes published `org.apache.grails` artifacts from the Grails 
8.0.x repositories. Only the four artifacts owned by this repository are built 
locally:
+The build consumes the released Grails 8.0.0 artifacts (`grailsVersion` in 
`gradle.properties`). This repository's own version stays `8.0.0-SNAPSHOT` 
until its release tag. Only the four artifacts owned by this repository are 
built locally:

Review Comment:
   README now points at `grailsVersion` and `projectVersion` in 
`gradle.properties` instead of hard-coding `8.0.0`. The user guide uses 
`$grailsMicronautVersion` for both the BOM and `grails-micronaut`, since the 
BOM does not constrain the plugin. Fixed in d03db59a81.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to