Skip to content

Commit a98c1ae

Browse files
[build] fix env vars causing gradle build error (#705)
Context: dotnet/android#5044 (comment) Context: https://docs.microsoft.com/visualstudio/msbuild/exec-task An env var can break the build such as running the following powershell: > $env:FOO="`nFoo.cs(123,1) error: oh dear!" A new line in the string is required to hit an issue. (```n`` is PowerShell-ese for a `\n` newline.) This results in a confusing build error: (_BuildJava target) -> EXEC : Foo.cs(123,1) error : oh dear! `gradlew -d` prints every environment variable, and if there is a line that looks like an MSBuild error then `msbuild` will emit the error. We can set `IgnoreStandardErrorWarningFormat="true"` to disable this. This could commonly happen on CI systems, if a commit message contains an error message. In the case of Azure DevOps, `%BUILD_SOURCEVERSIONMESSAGE%` will contain the full commit message. I also fixed the `_CleanJava` target that was not running at all. `java-source-utils.csproj` now properly cleans now.
1 parent 75354b9 commit a98c1ae

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/java-source-utils/Directory.Build.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Command=""$(GradleWPath)" -d $(GradleArgs) -PjavaSourceVer=$(JavacSourceVersion) -PjavaTargetVer=$(JavacTargetVersion) jar"
1212
EnvironmentVariables="JAVA_HOME=$(JavaSdkDirectory);APP_HOME=$(GradleHome)"
1313
WorkingDirectory="$(MSBuildThisFileDirectory)"
14+
IgnoreStandardErrorWarningFormat="true"
1415
/>
1516
<Copy
1617
SourceFiles="build\libs\java-source-utils.jar"
@@ -72,7 +73,7 @@
7273
/>
7374
</Target>
7475

75-
<Target Name="_CleanJava" DependsOnTargets="Clean">
76+
<Target Name="_CleanJava" BeforeTargets="Clean">
7677
<Delete Files="$(OutputPath)java-source-utils.jar" />
7778
<Exec
7879
Command="&quot;$(GradleWPath)&quot; clean $(GradleArgs)"

0 commit comments

Comments
 (0)