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

MultiModules: Depend on all child projects by default #91

Open
hfhbd opened this issue Jun 13, 2023 · 1 comment
Open

MultiModules: Depend on all child projects by default #91

hfhbd opened this issue Jun 13, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@hfhbd
Copy link

hfhbd commented Jun 13, 2023

The current design requires to add all projects manually in the dependency block of the root project:

dependencies {
  dokkatoo(projects.foo)
}

Adding some default mechanism would be nice to not add all projects manually. This is somehow annoying with projects containing many projects.

One option:
Use a build service to register a project when the dokkatoo plugin is applied.
The root project should create the build service (it is evaluated at first) and could depend on the registered projects using dependencies.addLater.

Originally posted by @hfhbd in #14 (comment)

@aSemy aSemy added the enhancement New feature or request label Jun 14, 2023
@aSemy
Copy link
Contributor

aSemy commented Jun 14, 2023

Thanks for the request, I'll have to consider it.

At the moment I'm reluctant to add such behaviour

  • I'd rather have the usage be explicit, even if it is verbose

  • if depending on subprojects is added, does that open the door to conditionally excluding subprojects? Which would be complicated also

  • Perhaps this is a feature request for Gradle, not for Dokkatoo?

  • Perhaps it would be more useful for Dokkatoo dependencies to be transitive?

    For example, given two subprojects

    .
    └── root-project/
        ├── subproject-alpha/
        └── subproject-gamma/
    
    • if subproject-alpha has a dependency dokkatoo{projects.subprojectGamma),
    • and the root project depends on dokkatoo(projects.subprojectAlpha),
    • then the root project gets both subproject-alpha and subproject-gamma

In the meantime, could you try this workaround? It should automatically add all subprojects.

// build.gradle.kts

plugins {
  id("dev.adamko.dokkatoo-html")
}

configurations.dokkatoo.configure {
  dependencies.addAllLater(
    // lazily add subprojects
    provider {
      // get all projects
      rootProject.allprojects
        // don't add _this_ subproject as a self-dependency
        .filter { it.path != project.path }
        // only get projects that have the Dokkatoo HTML plugin 
        // (adjust to include the other plugins if necessary)
        .filter { it.pluginManager.hasPlugin("dev.adamko.dokkatoo-html") }
        // create a dependency on the other project
        .map { project.dependencies.create(it) }
    }
  )
}

Filtering by plugin is necessary because current Dokkatoo doesn't use artifactView { lenient(true) }. If Dokkatoo was updated to fetch dependencies leniently, then it should be possible to just add all projects as dependencies and then Dokkatoo won't complain if a subproject doesn't have the plugin.

I also found this suggestion on SO: https://stackoverflow.com/q/65092844/4161471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants