[GRADLE-1276] processResources task considered up-to-date although its spec has changed Created: 29/Dec/10  Updated: 17/Nov/16  Resolved: 17/Nov/16

Status: Resolved
Project: Gradle
Affects Version/s: 0.9
Fix Version/s: None

Type: Bug
Reporter: Peter Niederwieser Assignee: Unassigned
Resolution: Duplicate Votes: 10

Issue Links:
Related
Related to GRADLE-1298 Change in filtered resource not picke... Resolved
dependent
dependent on GRADLE-1646 Copy tasks do not consider filter/exp... Resolved

 Description   

Given a Java project with the following processResources spec:

processResources {
    expand buildNumber: "0"
}

When I change buildNumber to "1" and run Gradle again, the processResources task is considered up-to-date and isn't run. "cleanProcessResources" doesn't help either.



 Comments   
Comment by Joern Huxhorn [ 16/Jul/16 ]

Integration test for this issue.

Uncomment one of the two commented lines in the processResources section to make the test green. Those are the currently available workarounds.

CopySpecExpandTest.groovy
/*
 * Copyright 2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.integtests

import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import spock.lang.Issue

class CopySpecFilterTest extends AbstractIntegrationSpec {
    @Issue(['GRADLE-1276', 'GRADLE-1298', 'GRADLE-1646'])
    def 'CopyTask is not considered up-to-date if expand input changed.'() {
        setup: 'a minimal java build'
        buildScript("""
            apply plugin: 'java'

            def expandMap = [timestamp: System.currentTimeMillis()]

            processResources {
                //outputs.upToDateWhen { false }
                //inputs.properties expandMap
                expand expandMap
            }
        """)
        file('src/main/resources/app.properties') << 'application.timestamp=${timestamp}'
        def appPropertiesOutputFile = file('build/resources/main/app.properties')

        when: 'a build is executed'
        succeeds('clean', 'build')

        then: 'app.properties file exists in output as expected'
        appPropertiesOutputFile.exists()

        when: 'only java source file is deleted, leaving empty input source directory'
        def appPropertiesContent = appPropertiesOutputFile.text
        Thread.sleep(1000) // wait a sec to make sure System.currentTimeMillis() changed on any OS

        and: 'another build is executed'
        succeeds('build')

        then: 'app.properties file in output is updated with different timestamp'
        appPropertiesContent != appPropertiesOutputFile.text
    }

    @Issue(['GRADLE-1276', 'GRADLE-1298', 'GRADLE-1646'])
    def 'CopyTask is not considered up-to-date if nested expand input changed.'() {
        setup: 'a minimal java build'
        buildScript("""
            apply plugin: 'java'

            def expandMap = [timestamp: System.currentTimeMillis()]

            processResources {
                //outputs.upToDateWhen { false }
                //inputs.properties expandMap
                filesMatching '**/*.properties', { expand expandMap }
            }
        """)
        file('src/main/resources/app.properties') << 'application.timestamp=${timestamp}'
        def appPropertiesOutputFile = file('build/resources/main/app.properties')

        when: 'a build is executed'
        succeeds('clean', 'build')

        then: 'app.properties file exists in output as expected'
        appPropertiesOutputFile.exists()

        when: 'only java source file is deleted, leaving empty input source directory'
        def appPropertiesContent = appPropertiesOutputFile.text
        Thread.sleep(1000) // wait a sec to make sure System.currentTimeMillis() changed on any OS

        and: 'another build is executed'
        succeeds('build')

        then: 'app.properties file in output is updated with different timestamp'
        appPropertiesContent != appPropertiesOutputFile.text
    }
}

The straight-forward idea of adding the line getInputs().properties(properties); to AbstractCopyTask.expand(Map<String, ?> properties) fixes the first but not the second test.

As I expected.

Comment by Joern Huxhorn [ 16/Jul/16 ]

I suspect this requires a rather complex architectural change to the whole CopySpec concept, unfortunately...

Anyway, this is another bug that prevents a 100% reliable Gradle 3.0 cache.

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Joern Huxhorn [ 15/Nov/16 ]

Created https://github.com/gradle/gradle/issues/861

Comment by Eric Wendelin [ 17/Nov/16 ]

Moved to https://github.com/gradle/gradle/issues/861

Generated at Wed Jun 30 11:51:26 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.