sbt sourceDirectories
仅显示当前项目的源目录,但不显示其依赖的项目的源目录
dependsOn(ProjectRef)
下面是简化的任务。
lazy val showAllSourceDirs = taskKey[Unit]("show source directories of all projects")
showAllSourceDirs := {
val projectRefs = loadedBuild.value.allProjectRefs.map(_._1)
projectRefs foreach { projectRef =>
/*
Below line is giving IllegalArgumentException exception :-
[error] java.lang.IllegalArgumentException: Could not find proxy for projectRef: sbt.ProjectRef in
List(value projectRef, value $anonfun, method sbtdef$1, method $sbtdef, object $7fb70afe92bc9a6fedc3,
package <empty>, package <root>) (currentOwner= method $sbtdef )
*/
val sources = (projectRef / Compile / sourceDirectories).value
sources.foreach( println )
}
}
简化项目的链接以重现问题:-
https://github.com/moglideveloper/Example
步骤:
从命令行转到 ApiSpec目录,并在以下命令下运行:-
sbt showAllSourceDirs
预期的输出:打印Api和ApiSpec项目的所有源目录
实际输出:抛出java.lang.IllegalArgumentException
答案 0 :(得分:1)
我相信您不能这样做,因为sbt与宏一起工作。您可以在此处执行的操作是将sourceDirectories
的{{1}}添加到Api
的{{1}}中。这意味着,如果您将以下内容添加到您的sbt中:
sourceDirectories
然后,在运行时:
ApiSpec
您将得到输出:
Compile / sourceDirectories ++= (apiModule / Compile / sourceDirectories).value
您需要注意一件事-您正在覆盖当前的sourceDirectories,因此请确保您没有在其他任何地方使用它。
另一个注意事项是,您需要在每个依赖项上添加此行。因此,我不确定您的项目有多大,这有多大可行性。
如果您要执行其他任务,则可以执行此操作,因为宏,因此可以自己使用模块,而不必通过反射。
sbt sourceDirectories