Skip to content

Replace the info.app tokens in the integration test resources - #17305

Open
matrei wants to merge 4 commits into
7.0.xfrom
fix/integration-test-application-yml
Open

matrei wants to merge 4 commits into
7.0.xfrom
fix/integration-test-application-yml

Conversation

@matrei

@matrei matrei commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

The integration test source set has grails-app/conf as a resource directory of its own, so processIntegrationTestResources copies application.yml to build/resources/integrationTest without replacing its @info.app.name@, @info.app.version@ and @info.app.grailsVersion@ tokens, as processResources does for the main resources. That copy comes before the processed build/resources/main/application.yml on the classpath of the integration tests, and Metadata reads the first application.yml on the classpath. So in integration tests:

  • the name, version and Grails version of the application are the tokens, and
  • DefaultGrailsPluginManager logs for every plugin, whenever the application starts, that it may not be compatible:
Plugin [quartz:7.0.17] may not be compatible with this application as the application Grails version is less than the plugin requires. Plugin is compatible with Grails version 7.0.0 > * but app is @info.app.grailsVersion@

This happens in every application that sets these properties in the first document of its application.yml, as the applications generated by Forge do.

This replaces the tokens in the resources of the integration tests as processResources does in the main resources, with the same tokens. grails-app/conf stays a resource directory of the integration tests, so they see the same files as before, including the spring/resources.groovy of a plugin, which processResources of a plugin leaves out. Only the files that contain a token are filtered, so the others are copied unchanged, whatever their encoding. The check reads the file with the filteringCharset of the task, the charset that ReplaceTokens reads it with. A file that an earlier filter changes, such as an expand of a convention of the build, is filtered without the check: getFile() fails for it, and reading it with open() would run that filter once more. That filter decodes and encodes the file anyway, so a file without tokens is written as it leaves it.

The values of the tokens are an input of processIntegrationTestResources, and now also of processResources, which had the same gap: without it, processResources stays up to date when the version changes, and leaves the old version in application.yml.

8.0.x removed grails-app/conf from the resources of the test phases instead, in 289519a ("Prevent duplicate resources on the classpath", part of #15541), which needed 75e7336 for resources.groovy. This keeps it, so that nothing else changes in a patch release.

Merging up: 7.1.x moved this code to TestPhasesGradlePlugin, which adds grails-app/conf to the resources of every test phase. #17306 replaces the tokens in the resources of every test phase there. 8.0.x no longer copies grails-app/conf, so it doesn't need this.

Results that change

In integration tests, info.app.name, info.app.version and info.app.grailsVersion, and so grailsApplication.metadata, have the values of the running application instead of the tokens. The same tokens are replaced in the other *.groovy, *.yml and *.xml files of the integration test resources that contain them, as in the main resources. processResources and processIntegrationTestResources run again when the name or version of the project or the Grails version changes. I don't see a use for the old results, so this adds no setting.

Testing

IntegrationTestGradlePluginSpec checks:

  • that processIntegrationTestResources replaces the tokens in application.yml, which fails without the change;
  • that processResources and processIntegrationTestResources write the new version after it changed in build.gradle, which fails without the input of either;
  • that a file in ISO-8859-1 without tokens is copied unchanged, which fails when every file is filtered;
  • that the tokens are replaced in a file in UTF-16 when filteringCharset is UTF-16, which fails when the check reads the file as ISO-8859-1;
  • that the tokens are replaced after a filter that numbers the lines, which a convention in settings.gradle adds before the Grails plugin is applied, and that a file without tokens is numbered once, which fails with UnsupportedOperationException when the check calls getFile() without handling it, and with 2: a: 1 when it reads the file with open();
  • that the integration tests of a plugin still get its spring/resources.groovy, which fails without the copy of grails-app/conf.

./gradlew build codeStyle passes in grails-gradle, and so do the integration tests of the issue11005 and cache examples, whose build/resources/integrationTest/application.yml has the values instead of the tokens.

@jdaugherty

Copy link
Copy Markdown
Contributor

Isn't this a breaking change? we've always told people that grails/conf is where you configure environments, and by not copying that config, you're now expecting people to define their config with the test resources directory instead. I'm not against this change, but this feels breaking and thus should go on a major release.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. An integration test loses the Spring beans that were left out of the packaged resources.

for (File srcDir in sourceDirs) {
registerSourceDir(integrationTest, srcDir)
acceptedSourceDirs.add(srcDir)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A plugin leaves spring/resources.groovy out of the packaged resources, and an integration test needs the bean it defines. The test should see that file. It does not, because this no longer copies the configuration the package excludes. Keep that copy, and still use the processed application.yml.

The integration tests have grails-app/conf as a resource directory of
their own, which comes before the main resources on their classpath.
processIntegrationTestResources copied its application.yml without
replacing the info.app tokens, as processResources does in the main
resources, so the integration tests read the tokens instead of the
values, and every plugin logged that it may not be compatible with the
Grails version '@info.app.grailsVersion@'.

Replace the tokens in the resources of the integration tests too.
@matrei
matrei force-pushed the fix/integration-test-application-yml branch from 5746f44 to cb077a9 Compare December 3, 2026 20:52
@matrei matrei changed the title Read the processed application.yml in integration tests Replace the info.app tokens in the integration test resources Dec 3, 2026
@matrei
matrei requested a review from jdaugherty December 3, 2026 21:50

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier missing Spring beans are addressed. Requested changes. A changed version can leave the old value in the processed file, and a file with no token can be rewritten.

return
}
project.tasks.named(integrationTest.processResourcesTaskName, ProcessResources).configure { ProcessResources task ->
Map<String, String> replaceTokens = resolveReplaceTokens(project, grailsVersion)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version changes between two runs, and a file contains that token. The second run should write the new version. It can keep the old one, because this does not record the token values as inputs. Record them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 726524a: the token values are now an input of processIntegrationTestResources, and of processResources, which had the same gap. IntegrationTestGradlePluginSpec changes the version between two runs and checks both outputs.

project.tasks.named(integrationTest.processResourcesTaskName, ProcessResources).configure { ProcessResources task ->
Map<String, String> replaceTokens = resolveReplaceTokens(project, grailsVersion)
task.filesMatching(['**/*.groovy', '**/*.yml', '**/*.xml']) { FileCopyDetails details ->
details.filter([tokens: replaceTokens], ReplaceTokens)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A file has no token and is not UTF-8. It should be copied unchanged. A character is corrupted, because this filters every file. Leave a file with no token alone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 726524a: only the files that contain one of the tokens are filtered now, so the others are copied byte for byte, as before. IntegrationTestGradlePluginSpec checks it with an ISO-8859-1 file.

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is right: keeping grails-app/conf on the integration test resources and replacing the tokens there fixes the plugin compatibility warnings without changing what's on the classpath. Two things before I approve:

  1. The token values aren't task inputs. A small Gradle 8.14 build shows it: change version and rerun, and the resources task is UP-TO-DATE with the old value in application.yml. Please add task.inputs.properties(replaceTokens) (or one map-valued property), and ideally do the same for the main processResources, which has the same gap. A test that changes the version and checks the output would cover it.
  2. Every .groovy/.yml/.xml in the integration test resources is now decoded and re-encoded, so a non-UTF-8 XML fixture in src/integration-test/resources gets corrupted where it used to be copied byte for byte. Main resources already behave this way, so I can live with it if that's deliberate, but filtering only files that contain @info.app. would avoid it.

Please also reply to Jeff's comment: the current version keeps grails-app/conf, so it isn't the breaking change he was worried about.

- Record the values of the tokens as an input of processResources and
  processIntegrationTestResources, so that they run again when the
  version changes, instead of leaving the old version in the processed
  application.yml
- Filter only the integration test resources that contain a token, so
  that the others are copied unchanged, whatever their encoding
@matrei

matrei commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@jdaugherty Fair point: 8.0.x made that change in a major release. I've changed this PR to keep grails-app/conf in the integration test resources and only replace the info.app tokens in it, as processResources does for the main resources. The integration tests see the same files as before, and only the tokens differ.

@matrei

matrei commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

@sbglasius Thanks! Both are done in 726524a: the token values are inputs of processIntegrationTestResources and processResources, with a test that changes the version between two runs, and only the files that contain a token are filtered, so a non-UTF-8 file without tokens is copied unchanged, as before.

@matrei
matrei requested a review from sbglasius December 4, 2026 10:55

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. An earlier copy filter can now fail the task, including for a file that has no token.

Map<String, String> replaceTokens = resolveReplaceTokens(project, grailsVersion)
task.inputs.property('replaceTokens', replaceTokens)
task.filesMatching(['**/*.groovy', '**/*.yml', '**/*.xml']) { FileCopyDetails details ->
if (containsReplaceToken(details.file, replaceTokens)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a convention registers filter or expand before this action, Gradle throws UnsupportedOperationException when the action reads details.file. A matching file with no Grails token fails instead of being copied. Read the file without depending on another filter having left it unread.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 37b8e91: the check reads the file with details.open(), which applies the earlier filters, instead of details.file. IntegrationTestGradlePluginSpec adds an expand from a convention, configured in settings.gradle before the Grails plugin is applied, and checks a file with a token and one without. Without the fix, it fails with this UnsupportedOperationException.

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 726524a. My earlier concern about removing grails-app/conf is addressed: the integration tests still receive that directory, including a plugin spring/resources.groovy. Recording the token map as a task input also addresses the stale-version problem.

One remaining correction before approval: the details.file read can fail after a convention has registered an earlier filter or expand action. I independently reproduced the existing finding on Gradle 8.14.8 with a minimal Copy task: an XML file containing no Grails token copies successfully with the earlier filter alone, but adding this filesMatching action throws UnsupportedOperationException from DefaultFileCopyDetails.getFile. Please make the token check work with an existing filter chain and cover that ordering in the plugin tests, while retaining the byte-for-byte test for files without tokens.

Existing thread: #17305 (comment)

FileCopyDetails.getFile() fails once a file has a filter, so a filter or
expand that a convention of the build added to
processIntegrationTestResources before failed the task, even for a file
without tokens. Read the file with open() instead, which applies those
filters.
@matrei

matrei commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

@jdaugherty Thanks for reproducing it. Fixed in 37b8e91, see the thread. The byte-for-byte test for files without tokens is unchanged.

@matrei
matrei requested a review from jdaugherty December 5, 2026 09:52

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. An earlier filter can still fail the task, and a UTF-16 resource keeps an unresolved token.

* ASCII, so they are found in the bytes of a file in UTF-8, ISO-8859-1 or another encoding that extends ASCII.
*/
protected static boolean containsReplaceToken(FileCopyDetails details, Map<String, String> replaceTokens) {
String content = details.open().withStream { InputStream input ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A token-free file with an earlier expand filter is opened here to look for tokens. That runs the earlier filter before the copy decides to skip the file. A missing property in that filter fails the task. Previously the file was copied without running the filter. Do not run the earlier filters to decide whether a token is present.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c1ec106: the check no longer runs the earlier filters. A file that already has a filter, for which getFile() fails, is filtered without the check: that filter decodes and encodes the file anyway, so a file without tokens is written as it leaves it, and an expand with a missing property no longer runs for a file that a later action excludes. The convention in IntegrationTestGradlePluginSpec now numbers the lines, and the file without a token gets 1: a: 1, as on the base.

*/
protected static boolean containsReplaceToken(FileCopyDetails details, Map<String, String> replaceTokens) {
String content = details.open().withStream { InputStream input ->
new String(input.bytes, StandardCharsets.ISO_8859_1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A UTF-16 XML file that contains @info.app.name@, with filteringCharset set to UTF-16, is scanned as ISO-8859-1. The token is not seen, so the integration-test resource keeps the placeholder while the main resource gets the name. Scan with the charset the copy uses.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c1ec106: the check reads the file with the filteringCharset of the task, the charset that ReplaceTokens reads it with. IntegrationTestGradlePluginSpec checks a UTF-16 file with filteringCharset = 'UTF-16'.

sbglasius
sbglasius previously approved these changes Dec 5, 2026

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 37b8e91.

Both points from my earlier review are fixed in 726524a: the token values are inputs of processIntegrationTestResources and processResources, and a file without a token is copied byte for byte. IntegrationTestGradlePluginSpec covers both. 37b8e91 reads the file through details.open(), so the expand of a convention no longer fails the check. The spec passes locally (5 tests).

On the two points from today, compared against the base 0b73627:

  • An expand with a missing property on a .yml without a token fails on the base as well, in processIntegrationTestResources and in processResources, because the copy runs that filter anyway. The only new failure I could make is a file that such a filter fails on and that a later filesMatching { exclude() } leaves out: the base never reads it, while the token check now runs the filter on it. That seems narrow enough not to block this.
  • A UTF-16 .xml with a token and filteringCharset = 'UTF-16' keeps the token here, and also kept it on the base, so nothing regresses; the Javadoc says the check assumes an encoding that extends ASCII. Scanning with task.filteringCharset would cover it, if you want to.

Approving.

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A follow-up to my approval: the earlier-filter point that James raised on #17306 applies here too, since containsReplaceToken is the same. A convention filter that numbers lines with a counter writes 2: a: 1 instead of 1: a: 1 for a .yml without a token, because the check runs the filter once more before the copy. Details on #17306. Please carry the fix over to this PR as well.

Reading a file with open() to look for the tokens ran the filters that
a convention of the build added before once more, so a filter that
numbers the lines started at 2. Filter a file that already has a filter
without looking for the tokens, since that filter decodes and encodes it
anyway, and read the other files with the filtering charset of the
task, so that the tokens of a file in UTF-16 are found.
@matrei

matrei commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

@sbglasius Thanks! Carried over in c1ec106: the check no longer runs the earlier filters, and your numbering convention from #17306 is the regression test, with 1: a: 1 for the file without a token. I've also taken your suggestion to read the files with filteringCharset.

@github-actions
github-actions Bot dismissed sbglasius’s stale review December 5, 2026 16:39

Dismissed automatically: the pull request changed after this approval, from 37b8e91 to c1ec106.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. An earlier filter no longer fails the task by itself. A UTF-16 resource added on a child copy still keeps an unresolved token.

} catch (UnsupportedOperationException ignored) {
return true
}
String content = new String(file.bytes, charset)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A UTF-16 XML file added with from(...) { filteringCharset = 'UTF-16' }, under a task whose charset is UTF-8, is scanned with the task charset. The token is not seen, so the integration-test resource keeps @info.app.name@. Scan with the charset of the copy that owns the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave this one as it is, because the charset of the copy that owns a file isn't available to a copy action: FileCopyDetails has no getter for it, and it is only in the internal CopySpecResolver of the copy. The bytes can't tell it either: a UTF-16 file in a child copy with filteringCharset = 'UTF-16' has the same bytes as a UTF-16 fixture in a UTF-8 copy, which should be copied unchanged. Looking for the tokens in every charset would garble that fixture, and reading the charset of the copy would need reflection on Gradle internals.

It isn't a regression: the base doesn't replace the tokens in the integration test resources at all. processResources doesn't replace them in a child copy either, whatever its charset, since its filters are on its own copies of the source set's resources. The integration tests already replace them in a child copy that has the charset of the task.

@testlens-app

testlens-app Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

🚨 All tests passed but jobs failed 🚨

Failed Jobs without Test Failures

❌ CI / Hibernate5 Functional Tests (25)

🏷️ Commit: c1ec106
▶️ Tests: 58444 executed
⚪️ Checks: 58/58 completed

Rerun Controls

Click the checkbox to trigger a rerun:

  • Rerun jobs

Learn more about TestLens at testlens.app/docs.

@matrei
matrei requested a review from sbglasius December 5, 2026 19:34

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants