[GRADLE-3528] Exec tasks never up-to-date due to changing environment variables Created: 18/Aug/16 Updated: 25/Aug/16 Resolved: 25/Aug/16 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | 3.0 |
Fix Version/s: | 3.1-rc-1 |
Type: | Bug | ||
Reporter: | Sterling Greene | Assignee: | Stefan Wolf |
Resolution: | Fixed | Votes: | 0 |
Known Issue Of: |
Description |
On macOS (at least), three environment variables (APP_NAME, APP_ICON, JAVA_MAIN_CLASS) are inherited by all Exec tasks that change names on every build. These aren't actually passed to the process, something between the up-to-date checks and actually starting the process strips these environment variables out. Reproducible: apply plugin: 'base' task createScript << { def script = file("script.sh") script.executable = true script.text = '''#!/bin/sh echo "$*" ''' file("package.json").text = "{}" } task run(type: Exec) { dependsOn createScript commandLine './script.sh', 'install' inputs.files 'package.json' outputs.dir 'node_modules' } Workaround (add this to the Exec task): def iter = environment.iterator() while(iter.hasNext()) { def entry = iter.next() if (entry.key =~ /APP_NAME_\d+|APP_ICON_\d+|JAVA_MAIN_CLASS_\d+/) { iter.remove() } } |
Comments |
Comment by Lóránt Pintér [ 19/Aug/16 ] |
The problem is caused by this line: https://github.com/gradle/gradle/blob/dad0adec96ff641ef904d90c300d5bd6156b95f4/subprojects/core/src/main/java/org/gradle/api/tasks/AbstractExecTask.java#L177-L177 It used to have no annotation prior to 3.0, and is now annotated as @Optional @Input. Instead it should be annotated as @Internal to preserve the original behavior, and ignore the environment for up-to-date checks for now. |
Comment by Lóránt Pintér [ 19/Aug/16 ] |
The @Optional @Input annotation needs to be replaced with @Internal here as well: https://github.com/gradle/gradle/blob/0595e592a454dc7468212ece39ba25fbd334bdf4/subprojects/core/src/main/java/org/gradle/api/tasks/JavaExec.java#L372-L372 |
Comment by Lóránt Pintér [ 19/Aug/16 ] |
The tasks affected by this problem are: Exec, JavaExec and the native RunTestExecutable. The Java Test task is not affected. |
Comment by Stefan Wolf [ 25/Aug/16 ] |
Fixed by replacing @Input by @Internal on environment properties. |