Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6794533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:14:00+00:00 2026-05-26T18:14:00+00:00

I have a multimodule web project with a dependency graph similar to this WAR-project

  • 0

I have a multimodule web project with a dependency graph similar to this

WAR-project
- A1
-- A2
-- A3
- B1
-- B2
---- B22
-- B3

that is the war project depends on A1 which in turn depends on A2 and A3 and so on.

Now prior to the packageing of the war project I want to copy some web resources from its dependent projects into the webapp. So my question is how do I programmatically traverse a SBT project’s dependency graph ? i.e. in pseudu code

resourcesToCopy = []
visitedProjects = []
traverseProjectDependencies(project) {
  visitedProjects += project
  if(project has resourceFolder) {
    resourcesToCopy += resourceFolder.getPath
  }
  for(projectDependency in project) {
    if(projectDependency is not visited) {
      traverseProjectDependencies(projectDependency)
    }
  }
}

Note I am aware that if I add the resource folder to the classpath of each of the dependencies then I could retrieve it from the fullClasspath in the web project. But I would like to avoid this solution and also there are other scenarios where programmatically traversing and interfacing with dependencies could be useful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:14:01+00:00Added an answer on May 26, 2026 at 6:14 pm

    The following code adds a aggr-res task that will aggregate all resources for dependent projects:

    val aggrRes= TaskKey[Seq[File]]("aggr-res", "show aggregate resources")
    
    val aggrResTask = aggrRes in Compile <<= {
      (thisProjectRef, buildStructure) flatMap aggrResources(resources in Compile)
    }
    
    def aggrResources[T](key: ScopedTask[Seq[T]])(proj: ProjectRef, struct: Load.BuildStructure) = {
      val deps = collectDeps(_.dependencies.map(_.project))(proj, struct)
      deps.flatMap(key in (_, Compile) get struct.data).join.map(_.flatten)
    }
    
    def collectDeps(op: ResolvedProject => Seq[ProjectRef])(projRef: ProjectRef, struct: Load.BuildStructure): Seq[ProjectRef] = {
      val deps = Project.getProject(projRef, struct).toSeq.flatMap(op)
      deps.flatMap(ref => ref +: collectDeps(op)(ref, struct)).distinct
    }
    

    I have made a gist with a more complete example here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multimodule project. Can I make it somehow work that when calling compile
I have a Multimodule project like this: parent entities jibx-exporter I have configured jibx
I have a new web app that is packaged as a WAR as part
I have a multi-module Maven project that is a Java web application. I am
I have multimodule maven project like this myproject framework1 f1-presentation *.java f1-core *.java f1-tag
I have a multimodule maven project. the service module depends on domain module using
I have multimodule project Project |--src |-JavaFile.java Web-Project |-Web-Content |-images | |-logo.PNG |-pages |-WEB-INF
I have a multimodule maven setup for my project, made of 5 modules, which
I have a multi module web project. Four modules of the project are packaged
I have a maven multimodule project. What the best practices for creating groupId? Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.