Exec task with declared inputs and outputs never up-to-date in gradle 3.0

issue-resolved
gradle-3528

(Jeremy Mailen) #1

Gradle Version: 3.0
Operating System: OSX 10.11.6
Regression from 2.14.1

When inputs not changed and outputs already exist the task should be up-to-date. This works in 2.14.1, broken in 3.0. Hint: I think perhaps 3.0 considers environment as well as files for “up-to-datedness” of an Exec task and there are some env vars that are always changing? Just a guess.

Repro, use sample below and:

gradle wrapper
./gradlew execBug
./gradlew execBug
(notice was not UP-TO-DATE)

gradle oldWrapper
./gradlew execBug
./gradlew execBug
(notice is UP-TO-DATE)

build.gradle

apply plugin: 'base'

task execBug(type: Exec) {
    commandLine 'npm', 'install'
    inputs.files 'package.json'
    outputs.dir 'node_modules'
}

task wrapper(type: Wrapper) {
    gradleVersion = '3.0'
}

task oldWrapper(type: Wrapper) {
    gradleVersion = '2.14.1'
}

package.json

{
  "name": "exec-not-uptodate",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "lodash": "^4.15.0"
  }
}

(Jochen Berger) #2

I observed something similar. When I run my build with i, the following appear in the logs:

  Output property '$1$59703' has been removed for task 'compileScripts'
  Output property '$1$59702' has been removed for task 'compileScripts'
  Output property '$1$59701' has been removed for task 'compileScripts'

I don’t add those proerties to my task outputs however, so something must be doing this internally.


(Andrew Craft) #3

i have the same problem after upgrading, i have a very similar task, I did see this in debug log:

‘Value of input property ‘environment’ has changed for task :blah’


(Chris Doré) #4

I suspect these issues may be related to the new tracking properties for input/output files mentioned in the release notes. Have you tried using withPropertyName when declaring the input/output files to see if that resolves the up-to-date checking issues you are seeing?


(Jeremy Mailen) #5

No, I don’t think that’s it.

With -i turned on it shows:

Value of input property 'environment' has changed for task...

I did what suggested, didn’t work, but hopefully I got it right? The withPropertyName seems magical in this context…

task execBug(type: Exec) {
    commandLine 'npm', 'install'
    inputs.files 'package.json' withPropertyName 'inputFiles'
    outputs.dir 'node_modules' withPropertyName 'outputDir'
}

Running with -d, I can see each time there are two changed env vars:
APP_NAME_SOMENUMBER=Gradle
APP_ICON_SOMENUMBER=some/path/to/gradle.icns


(Sterling Greene) #6

Thanks for finding this. I raised https://issues.gradle.org/browse/GRADLE-3528

There are at least three environment variables that are visible to the up-to-date checks, but they’re not actually passed to the process.

As a workaround, you can add this to your Exec task’s configuration block:


    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()
        }
    }

(Stefan Wolf) #7

Hi,

This has been fixed for Gradle 3.1. Can you try out the latest nightly to confirm it works for you now?

Thanks,
Stefan


(Jeremy Mailen) #8

Works in gradle-3.1-20160829000022+0000! Thank you – keep up the great work on Gradle.