# Gradle 2.4 - Cache unreliable

**URL:** <https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861>\
**Category:** Bugs\
**Created:** [May 28, 2015, 11:20pm UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861 "2015-05-28T23:20:52Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [May 29, 2015, 6:19pm UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/21 "2015-05-29T18:19:36Z")

</div>

Ok, that sounds more flexible than what I’m currently doing.

> [@mark\_vieira](#):
>
> Yes, you can define a dependency on a particular project configuration, which would include the artifact containing the required files.

How would I access the generated files/binaries in the dependent project/task then? And do I have to create a ZIP file for the artifact and then unzip it again? (According to the documentation, ArtifactHandler expects an AbstractArchiveTask.) Because that seems like overkill for passing a few files from one subproject to another.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [May 29, 2015, 7:13pm UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/22 "2015-05-29T19:13:47Z")

</div>

> [@Moe](#):
>
> How would I access the generated files/binaries in the dependent project/task then? And do I have to create a ZIP file for the artifact and then unzip it again?

Yes, you would typically pass the files in the form of a bundled archive. This is the “proper” way to model this type of cross-project dependency. Also, in a way, defining strict lines of separation helps identify instances in where your project structure is perhaps non-optimal.

The benefit of this type of dependency is that it is explicit. By declaring a project dependency you are establishing a contract between that project and others. By essentially “reaching over” into other projects to consume output from their tasks, we are creating a very brittle scenario, in which changes to build implementation build details might cause issues (as we’ve already seen).

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [May 29, 2015, 11:28pm UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/23 "2015-05-29T23:28:33Z")

</div>

> [@mark\_vieira](#):
>
> Also, in a way, defining strict lines of separation helps identify instances in where your project structure is perhaps non-optimal.

True, our previous Maven build had a lot of flaws, not all of which were Maven’s fault. (It’s a huge project and the build configuration grew over time.) During the migration to Gradle they’re now becoming more obvious. I still wish there’d be a way to define a set of files (folder) as an artifact and skip the archiving step.

I’ll try to figure out the easiest way to pass source files and regular files between subprojects via artifacts now. Thanks a lot for your help so far.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [May 30, 2015, 12:12am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/24 "2015-05-30T00:12:55Z")

</div>

> [@Moe](#):
>
> During the migration to Gradle they’re now becoming more obvious. I still wish there’d be a way to define a set of files (folder) as an artifact and skip the archiving step.

An intermedium would be to declare your input to be the generate task itself. This both solves the problem of not hard-coding against a particular output directory and creates and inferred dependency between tasks (which should facilitate parallel builds).

```
inputs.files files(project(':otherProject').generate)

```

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [June 3, 2015, 12:49am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/25 "2015-06-03T00:49:13Z")

</div>

> [@mark\_vieira](#):
>
> inputs.files files(project(‘:otherProject’).generate)

That doesn’t work for me, gradle is telling me that the property generate doesn’t exist on the other project.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [June 3, 2015, 12:54am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/26 "2015-06-03T00:54:16Z")

</div>

Probably an evaluation ordering issue. Try adding `evaluationDependsOn(':otherProject')` to your build script.

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [June 3, 2015, 1:15am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/27 "2015-06-03T01:15:52Z")

</div>

Thanks, that did the trick

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [June 3, 2015, 1:18am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/28 "2015-06-03T01:18:05Z")

</div>

Note that having to explicitly declare an evaluation order is an indication that Gradle does not know that there is a dependency between these two projects. This is precisely the reason why using project dependencies (as I showed above) is the more correct way to model these types of inter-project dependencies.

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [June 3, 2015, 1:23am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/29 "2015-06-03T01:23:36Z")

</div>

I’m still having some trouble trying to understand how configurations and tasks interact, though. How do I tell gradle that tasks belong to a specific configuration and that therefore the configuration’s dependencies should run before any of those tasks? And how do I specify the dependency between the builtin configuration (compile) and my `generatedFiles` configuration then?

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [June 3, 2015, 2:09am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/30 "2015-06-03T02:09:53Z")

</div>

Essentially you add artifacts (usually the output of some kind of archive task) to a configuration in the producing project. Then you add a dependency to that configuration in a dependent project and assign the dependency to a configuration. A `Configuration` is really just a `FileCollection` so you can treat it as such.

Take a look at the docs on [`ArtifactHandler`](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.ArtifactHandler.html) for more details.

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [June 3, 2015, 2:14am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/31 "2015-06-03T02:14:51Z")

</div>

> [@mark\_vieira](#):
>
> Essentially you add artifacts (usually the output of some kind of archive task) to a configuration in the producing project. Then you add a dependency to that configuration in a dependent project and assign the dependency to a configuration.

That’s the part I get. What I don’t get is how to tell gradle which tasks belong to the dependent configuration in the dependent project, i.e. which tasks in the dependent project depend on the artifact of the producing project. Also, is there an easier way to specify a dependency between different configurations in a single subproject than using `project(path: ':myself', configuration: 'other_configuration')`?

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [June 3, 2015, 2:16am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/32 "2015-06-03T02:16:23Z")

</div>

> [@Moe](#):
>
> i.e. which tasks in the dependent project depend on the artifact of the producing project

You would simply declare the configuration as an input of that task.

> [@Moe](#):
>
> Also, is there an easier way to specify a dependency between different configurations in a single subproject than using project(path: ‘:myself’, configuration: ‘other\_configuration’)?

No, not currently.

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [June 3, 2015, 2:21am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/33 "2015-06-03T02:21:01Z")

</div>

> [@mark\_vieira](#):
>
> You would simply declare the configuration as an input of that task.

Ah, that’s the part I was missing.

> [@mark\_vieira](#):
>
> No, not currently.

OK, I just suspected there might be a more elegant version. Thanks again for your help!

---

<div class="post-metadata">

**Author:** ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.gradle.org/u/Moe)\
**Post date:** [June 3, 2015, 2:31am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/34 "2015-06-03T02:31:02Z")

</div>

Just one last question, to make sure I understood this correctly: So I basically need two additional configurations in `projectB`, then, right? One to specify the dependencies on `projectA`'s `generatedFiles` artifact, which I use as an input to `projectB`'s own generation tasks. And one to hold `projectB`'s own `generatedFiles` artifact which other subprojects can then consume?

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [June 3, 2015, 3:19am UTC](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861/35 "2015-06-03T03:19:21Z")

</div>

Yes, that is correct.

[Previous page](https://discuss.gradle.org/t/gradle-2-4-cache-unreliable/9861.md?page=1)
