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


##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy:
##########
@@ -155,6 +170,57 @@ class CompilePlugin implements Plugin<Project> {
         }
     }
 
+    /**
+     * Stamps {@code project.version} onto every source set's Groovy compile.
+     *
+     * <p>The writer is registered from the source-set container. Registering 
a task while
+     * iterating {@code tasks.withType(GroovyCompile)} throws {@code 
ConcurrentModificationException}
+     * once {@code projectVersion} is not a snapshot. Wiring
+     * {@code configurationScriptFile} to the writer's output makes the 
compile task depend on
+     * the writer, including after {@code clean} deletes {@code build/}.</p>
+     */
+    private static void configurePublishedVersionScript(Project project) {
+        SourceSetContainer sourceSets = 
project.extensions.getByType(SourceSetContainer)
+        sourceSets.configureEach { SourceSet sourceSet ->
+            registerPublishedVersionScript(project, 
sourceSet.getCompileTaskName('groovy'))
+        }
+
+        project.tasks.withType(GroovyCompile).configureEach { GroovyCompile 
compile ->
+            TaskProvider<PublishedVersionCompilerScriptTask> writer = 
project.tasks.named(
+                    publishedVersionScriptTaskName(compile.name),
+                    PublishedVersionCompilerScriptTask
+            )
+            compile.groovyOptions.configurationScriptFile.set(writer.flatMap { 
PublishedVersionCompilerScriptTask task ->
+                task.outputFile
+            })
+        }

Review Comment:
   Compiler scripts are now registered per source set and wired with 
`tasks.named(compileTaskName, GroovyCompile).configure`. A `GroovyCompile` 
created outside a source set keeps the shared reproducibility script. The 
`tasks.names.contains` guard is gone, because `configureEach` runs once per 
source set. The published fixture registers `compileExtraGroovy`, and the spec 
checks that it keeps the shared script and does not get a writer. Fixed in 
00a9bf8ea8.



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy:
##########
@@ -87,7 +95,7 @@ class CompilePlugin implements Plugin<Project> {
 
             jar.manifest.attributes(
                     'Implementation-Title': 'Apache Grails',
-                    'Implementation-Version': lookupPropertyByType(project, 
'grailsVersion', String),
+                    'Implementation-Version': project.version.toString(),

Review Comment:
   The manifest now stores `project.provider { project.version.toString() }`, 
so Implementation-Version is read when the jar is written. CompilePluginSpec 
realizes `jar` before `version = projectVersion`, builds the jar, and reads 
Implementation-Version from `META-INF/MANIFEST.MF`. The snapshot and 
`-PprojectVersion=8.0.0` jars both stamp the assigned version. Fixed in 
00a9bf8ea8.



##########
build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/CompilePluginSpec.groovy:
##########
@@ -116,6 +116,159 @@ class CompilePluginSpec extends Specification {
         result.output.contains('TEST_INDY=true')
     }
 
+    def "compiler configuration stamps the published project version"() {
+        given:
+        usePublishedBuild('projectVersion')
+
+        when:
+        def result = GradleRunner.create()
+                .withProjectDir(testProjectDir.toFile())
+                .withArguments(['grailsCompilerConfigCompileGroovy', 
'printManifestVersion', '-PprojectVersion=8.0.0-SNAPSHOT', '--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', 'grails-micronaut')")
+        result.output.contains('IMPL_VERSION=8.0.0-SNAPSHOT')
+        !script.contains('7.9.9')
+    }
+
+    def "release version configures and stamps project.version"() {
+        given:
+        usePublishedBuild('projectVersion')
+
+        when:
+        def result = GradleRunner.create()
+                .withProjectDir(testProjectDir.toFile())
+                .withArguments(['grailsCompilerConfigCompileGroovy', 
'printManifestVersion', '-PprojectVersion=8.0.0', '--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')")
+        !script.contains('SNAPSHOT')
+        !script.contains('7.9.9')
+        script.contains("putNodeMetaData('projectName', 'grails-micronaut')")
+        result.output.contains('IMPL_VERSION=8.0.0')
+        !result.output.contains('IMPL_VERSION=8.0.0-SNAPSHOT')
+        !result.output.contains('IMPL_VERSION=7.9.9')
+    }
+
+    def "compiler version stamp is limited to published projects"() {
+        given:
+        testProjectDir.resolve('build.gradle').toFile().text = '''
+            plugins {
+                id 'groovy'
+                id 'org.apache.grails.buildsrc.compile'
+            }
+
+            version = '0.1'
+
+            ext {
+                javaVersion = 21
+                grailsVersion = '8.0.0'
+                formattedBuildDate = '2026-01-01'
+            }
+
+            repositories {
+                mavenCentral()
+            }
+
+            tasks.register('printCompilerScript') {
+                def compileTask = tasks.named('compileGroovy', 
org.gradle.api.tasks.compile.GroovyCompile)
+                doLast {
+                    println 
"HAS_WRITER=${tasks.names.contains('grailsCompilerConfigCompileGroovy')}"
+                    println 
"SCRIPT=${compileTask.get().groovyOptions.configurationScript}"
+                }
+            }
+        '''
+
+        when:
+        def result = GradleRunner.create()
+                .withProjectDir(testProjectDir.toFile())
+                .withArguments(['printCompilerScript', '--stacktrace'])
+                .withPluginClasspath()
+                .build()
+
+        then:
+        result.task(':printCompilerScript').outcome == TaskOutcome.SUCCESS
+        result.output.contains('HAS_WRITER=false')
+        result.output.contains('groovy-compile-configscript.groovy')
+        !result.output.contains('IMPL_VERSION=')

Review Comment:
   Dropped the unpublished-project `IMPL_VERSION` assertion. That build never 
registers `printManifestVersion`, so the line could not fail. Fixed in 
00a9bf8ea8.



-- 
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