Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular dependency error when build includes itself #141

Closed
stiost opened this issue Jun 24, 2024 · 8 comments · Fixed by #143
Closed

Circular dependency error when build includes itself #141

stiost opened this issue Jun 24, 2024 · 8 comments · Fixed by #143

Comments

@stiost
Copy link

stiost commented Jun 24, 2024

I get the following error when using this on a project that does dependency substitution:

Circular dependency between the following tasks:
:ForceDependencyResolutionPlugin_resolveAllDependencies
\--- :ForceDependencyResolutionPlugin_resolveAllDependencies (*)

Relevant snippet from settings.gradle (it works if I remove this block):

includeBuild(".") {
  dependencySubstitution {
    substitute module("x") using project(':')
  }
}
@bigdaz
Copy link
Member

bigdaz commented Jun 27, 2024

Thanks for the report. I can reproduce this without any substitution rules, with a simple:
includeBuild('.').

Can you explain the use case for adding the root build as an included build? This is inherently circular.

@bigdaz bigdaz changed the title Circular dependency error when using dependency subtitution Circular dependency error when build includes itself Jun 27, 2024
@bigdaz bigdaz closed this as completed in 5209723 Jun 27, 2024
@stiost
Copy link
Author

stiost commented Jun 28, 2024

Thanks for the report. I can reproduce this without any substitution rules, with a simple: includeBuild('.').

Can you explain the use case for adding the root build as an included build? This is inherently circular.

This is mentioned here in the official gradle docs https://docs.gradle.org/current/userguide/composite_builds.html#included_build_declaring_substitutions

@bigdaz
Copy link
Member

bigdaz commented Jun 28, 2024

@stiost Yes, I understand the use case for using dependencySubstitution. But that's not the cause of the problem in this case.

The error is caused by the fact that the build is including itself, via includeBuild('.'). I'm wondering what the use case is for this pattern. If you can describe what you're achieving with this includeBuild block, it might help me craft a better solution.

@stiost
Copy link
Author

stiost commented Jul 1, 2024

Basically it allows you to use

dependencies {
    implementation "company.group:artifact-name"
}

instead of

dependencies {
    implementation project(":artifact-name")
}

Which in our huge composite build looks a lot better and you use the same syntax no matter which composite build project you're in. We need it for our shared convention plugins to work.

@sschuberth
Copy link
Contributor

@stiost if that's the goal, I'd recommend to use type-safe project accessors instead.

@stiost
Copy link
Author

stiost commented Jul 1, 2024

@sschuberth That looks very cool and I'm definitely going to try it, I'm already using a dependency catalogue with type-safe accessors. But it doesn't seem to work with composite builds?

@sschuberth
Copy link
Contributor

But it doesn't seem to work with composite builds?

I don't know. But you definitely need to opt-in to it first via enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS").

@bigdaz
Copy link
Member

bigdaz commented Jul 2, 2024

@stiost Thanks for the explanation.

My understanding:

  • You want to substitute a module dependency (like implementation "company.group:artifact-name") with a project dependency (like implementation project(":artifact-name"))
  • The project :artifact-name lives in the same build as the consumer where the module dependency is declared.

The normal way to do this would be to use dependencySubstitution without a wrapping includeBuild, like this. But I can see how includeBuild('.') could be more consistent when you have other substitutions that do involve other included builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants