Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GradleRunner withEnvironment() behaves differently in 8.8-rc-1 #29000

Open
staktrace opened this issue Apr 29, 2024 · 3 comments · May be fixed by #29218
Open

GradleRunner withEnvironment() behaves differently in 8.8-rc-1 #29000

staktrace opened this issue Apr 29, 2024 · 3 comments · May be fixed by #29218
Labels
a:regression This used to work in:build-environment Gradle, project, system and environment properties, CLI flags in:internal-native-libraries bindings for various native APIs
Milestone

Comments

@staktrace
Copy link

Current Behavior

Setting GradleRunner.withEnvironment in a test for a gradle plugin seems to not set the environment variable for the gradle execution.

Expected Behavior

It should set the environment variable during the gradle execution as it did in 8.7 and previous versions

Context (optional)

We have a custom gradle plugin, and one of the tests for the plugin fails when run with gradle 8.8-rc-1.

Steps to Reproduce

https://github.com/staktrace/20240429-gradle-88rc1-envvar contains a minimal reproducible test case. Follow instructions in the README

Gradle version

8.8-rc-1

Gradle version that used to work

8.7

Build scan URL (optional)

https://scans.gradle.com/s/qt7d3u5jb4ywk/tests/overview

Your Environment (optional)

No response

@staktrace staktrace added a:regression This used to work to-triage labels Apr 29, 2024
@asodja
Copy link
Member

asodja commented Apr 29, 2024

This is an interesting consequence of fixing org.gradle.native handling.

Before 8.8 Gradle ignored org.gradle.native flag, which was basically a bug. That was fixed with #28021 in 8.8. Unfortunately our ForkingTestClassProcessor had also a performance optimization that disabed loading native services in workers, and it did that by setting org.gradle.native=false: that system property is not set anymore with #28401.
That worked fine before with Gradle <= 8.7, since Gradle <= 8.7 just ignored org.gradle.native flag.

But now if you use Gradle 8.7 wrapper that still sets org.gradle.native=false system property and you test Gradle 8.8-rc-1, 8.8-rc-1 build will correctly handle that flag and disable the native services -> so env. variables won't be passed in the build.

To fix that one of these options will work:

  1. Use Gradle 8.8-rc-1 wrapper
  2. Or do System.clearProperty("org.gradle.native") somewhere at the start of your test
  3. Or do System.setProperty("org.gradle.native", "true") somewhere at the start of your test
  4. Or in your build script do
tasks.withType<Test>().configureEach {
  systemProperty("org.gradle.native", true)
}

@staktrace
Copy link
Author

Ah thank you for the explanation, that makes sense! For now we will set the property and presumably once we upgrade our main gradle version to 8.8 we can take it back out.

@ov7a ov7a added in:build-environment Gradle, project, system and environment properties, CLI flags in:internal-native-libraries bindings for various native APIs and removed to-triage labels Apr 30, 2024
@ov7a ov7a added this to the 8.8 milestone Apr 30, 2024
@eric-isakson
Copy link

Thanks for the workaround with setting org.gradle.native. Not sure if this is related but in 8.7 if the env var has the value of an empty string withEnvironment(Map.of("FOO",""), the environment var under the gradle runner will exist with an empty string value. In 8.8-rc-1, it will not be set so System.getenv("FOO") will return null

@ljacomet ljacomet modified the milestones: 8.8, 8.8 RC2 May 7, 2024
asodja added a commit that referenced this issue May 20, 2024
@asodja asodja linked a pull request May 20, 2024 that will close this issue
asodja added a commit that referenced this issue May 20, 2024
@asodja asodja linked a pull request May 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:regression This used to work in:build-environment Gradle, project, system and environment properties, CLI flags in:internal-native-libraries bindings for various native APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants