Reputation: 9
I am trying to find the path of the modules present inside the SBT built projects.
For example, take this project -> https://github.com/scala/scala
In this project, I executed the dependency tree and got the following list of first level modules.
[info] org.scala-lang:root_2.13:2.13.11-bin-SNAPSHOT [S]
[info] org.scala-lang:scala-reflect:2.13.11-bin-SNAPSHOT [S]
[info] org.scala-lang:scala-compiler:2.13.11-bin-SNAPSHOT [S]
[info] org.scala-lang:scalap:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:scala-compiler-doc:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:scala-compiler-interactive:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:scala-tastytest:2.13.11-bin-SNAPSHOT [S]
[info] org.scala-lang:scala-testkit:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:repl:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:scala-dist:2.13.11-bin-SNAPSHOT [S]
[info] org.scala-lang:tasty:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:scalacheck:2.13.11-bin-SNAPSHOT [S]
[info] org.scala-lang:scala-repl-frontend:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:junit:2.13.11-bin-SNAPSHOT
[info] org.scala-lang:scala-partest:2.13.11-bin-SNAPSHOT [S]
This is the directory structure of the mentioned project (src and test folder)
├── src
│ ├── compiler
│ ├── intellij
│ ├── interactive
│ ├── library
│ ├── library-aux
│ ├── manual
│ ├── partest
│ ├── partest-javaagent
│ ├── reflect
│ ├── repl
│ ├── repl-frontend
│ ├── scaladoc
│ ├── scalap
│ ├── tastytest
│ └── testkit
├── test
│ ├── async
│ ├── benchmarks
│ ├── files
│ ├── instrumented
│ ├── jcstress
│ ├── junit
│ ├── macro-annot
│ ├── osgi
│ ├── scalacheck
│ ├── scaladoc
│ ├── script-tests
│ └── tasty
Main Issue:
As you can see, I cant exactly map the modules straightforwardly to a folder in the directories.
I need
[info] org.scala-lang:scala-reflect:2.13.11-bin-SNAPSHOT [S] -> /path/src/reflect/
[info] org.scala-lang:scalacheck:2.13.11-bin-SNAPSHOT [S] -> /path/test/scalacheck/
For now, I had another SBT project as reference, where it was quite straightforward to map the module to source code directory.
Apache Pekko -> https://github.com/apache/pekko
We can just take the artifact name and append it to the base source code path.
Example Code:
String gavid = line.substring(startIndex, line.lastIndexOf(":"));
System.out.println("GAV id: " + gavid);
String[] parts1 = gavid.split(":");
String[] parts2 = parts1[1].split("_");
int hyphenIndex = parts2[0].indexOf('-');
String directory = parts2[0].substring(hyphenIndex + 1);
new_module.setSrcCodePath(object.getSrcCodePath() + directory + '/');
Upvotes: 1
Views: 47
Reputation: 9
import sbt._
import Keys._
val printModuleDetails = taskKey[Unit]("Prints the artifact name, project ID, and source code location for each module")
printModuleDetails := {
// Get all projects in the current session
val allProjects = thisProject.all(ScopeFilter(inAnyProject)).value
// Iterate over all projects and print their details
allProjects.foreach { project =>
println(s"Project ID: ${project.id}")
println(s"Source Code Location: ${project.base.getAbsolutePath}")
// Get the artifact name for the project using the correct ProjectRef
//println(s"Artifact Name: ${project.artifactName.getOrElse("Not specified")}")
//val artifactName = (project / Compile / packageBin / artifactPath).value.getName
//println(s"Artifact Name: $artifactName")
//val artifactName = (artifactPath in (project, Compile, packageBin)).value.getName
//println(s"Artifact Name: $artifactName")
println() // For readability
}
}
Upvotes: -1