gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.76k stars 4.69k forks source link

Zip task with copySpec that includes an empty list spins forever #9350

Closed martijndwars closed 4 years ago

martijndwars commented 5 years ago

I created a task of type Zip with a CopySpec that has includes set to an empty list. If I run the task, Gradle spins forever.

Expected Behavior

Gradle should create an empty zip (if this is possible, error otherwise). If I'm configuring the copySpec wrong, then Gradle should give me an informative error message.

Current Behavior

Gradle spins forever.

Context

This was caught by accident: Gradle ended up running forever when it should zip only about 100 files. We can easily work around this by not providing Gradle an empty list.

Steps to Reproduce

Create the following build.gradle:

plugins {
  id 'java'
}

wrapper {
  gradleVersion = '5.2'
}

task zipAlgorithmSources(type: Zip) {
  def x = []

  classifier 'java-source'
  from(projectDir) {
    include x
    into 'algorithms'
  }
}

Then run gradle wrapper to download the wrapper and ./gradlew :zipAlgorithmSources to run the task. You will see Gradle running forever. Strangely, if you inline the value [] where x is referenced, then Gradle immediately throws an error:

Could not get unknown property 'include' for object of type org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated.

Your Environment

I cannot finish a build scan since Gradle spins forever. I'm running on macOS 10.14.4, but I've seen the issue on the build server (Oracle Linux) as well.

martijndwars commented 5 years ago

I would like to contribute a fix (it looks like an easy bug), but I'd like to get a confirmation that this is indeed a bug and what the intended behavior would be.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

stale[bot] commented 4 years ago

This issue has been automatically closed due to inactivity. If you can reproduce this on a recent version of Gradle or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.

martijndwars commented 2 years ago

For what it's worth, the issue still exists in version 7.5.1. If I run:

./gradlew wrapper --gradle-version 7.5.1
./gradlew :zipAlgorithmSources

Then Gradle just hangs. If I add --info I see the logs:

> Task :zipAlgorithmSources
Deleting stale output file: /private/tmp/gradle-test/build/distributions/gradle-test-java-source.zip
Watching 1 directory hierarchies to track changes
Caching disabled for task ':zipAlgorithmSources' because:
  Build cache is disabled
Task ':zipAlgorithmSources' is not up-to-date because:
  No history is available.
<-------------> 0% EXECUTING [1m 54s]
> :zipAlgorithmSources

and this will keep going until I cancel it.

ljacomet commented 2 years ago

Hi @martijndwars

The recent activity is mostly us making sure that all issues closed by the stale bot are properly marked as "not planned" instead of looking like regular completed issues.

This issue has an easy workaround, so the fix is not high priority. So its state reflects this now.