There is a dependency loop in your Unicorn configuration dependencies

Today I came across this exception: There is a dependency loop in your Unicorn configuration dependencies. Unresolved configurations Project.XXX, Feature.ZZZ. At first I didn't realize the cause for this even though the reason is quite simple.

Short answer 

Don't violate the Helix architecture dependency direction. In this case I had created a dependency from the feature layer to the project layer, which is not allowed according to the Helix architecture. Since the dependency direction goes from Project -> Feature -> Foundation, a dependency from feature to project results in a dependency loop.

Long answer

Scenario: I wanted to configure the serialization of a root item for some datasources (only the root) in one configuration file, and then configure the serialization of the children in other configuration files.

 

So I added this configuration to my serialization config file in the project layer:

...
<predicate>
  <include name="CustomSources" database="master" path="/sitecore/system/Custom sources">
    <exclude children="true" />
  </include>
</predicate>
...

And in my feature layer I added this configuration for the child datasource folder.

...
<predicate>
  <include name="ProductCategories" database="master" path="/sitecore/system/Custom sources/ProductCategories" />
</predicate>
...

 

In this case a folder for some product categories:

 

The problem is that I have created a dependency from the feature layer to the project layer. The ProductCategories item (feature layer) depends on the parent item (project layer), which violates the Helix dependency direction.

Solution: I moved the serialization of the root item to the foundation layer, which solved the issue.