codeconsole commented on code in PR #16528:
URL: https://github.com/apache/grails-core/pull/16528#discussion_r4190835157


##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/FoundMainClassValueSource.groovy:
##########
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.gradle.plugin.core
+
+import groovy.transform.CompileStatic
+
+import org.gradle.api.file.RegularFileProperty
+import org.gradle.api.provider.ValueSource
+import org.gradle.api.provider.ValueSourceParameters
+
+/**
+ * The main class the {@code findMainClass} task wrote to its cache file, or 
no value before the task has run.
+ *
+ * <p>Unlike a {@code project.provider}, which the configuration cache 
evaluates once when it stores an entry,
+ * Gradle obtains this value again whenever it is read from a reused entry, so 
a task reading it sees the class the

Review Comment:
   One case the javadoc doesn't cover. Once anything reads 
`springBoot.mainClass` or `mainClassName` while the build is configured, Gradle 
obtains the value source at that moment, keeps that value for the rest of the 
build, and stores it in the entry. On a clean build, every later read in that 
build gets `null`. That includes a task's `doLast` after `findMainClass` has 
run, with or without the configuration cache. With the old `project.provider` 
and the cache off, that task saw the class.
   
   I reproduced it on Gradle 9.8.0 with a value source that reads a file a task 
writes, plus an `afterEvaluate` read. After deleting `build/`, both the 
configuration read and the task's read print `null`. Without the 
`afterEvaluate` read, the task gets the value, as `printMainClass` does in your 
spec.
   
   It's narrow: Grails' own tasks use `getMainClassProvider`, and it only 
affects a build where some script or plugin reads the value during 
configuration. In that build, though, "a task reading it sees the class the 
current build found" doesn't hold. Could the javadoc say so?
   



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