how to get the sub project path in sbt multi project build

前端 未结 1 945
太阳男子
太阳男子 2021-01-18 08:34

I am trying to get the location of sub project in multi-project build in sbt. But I am able to get only the root project directory.

lazy val copyToResources          


        
相关标签:
1条回答
  • 2021-01-18 08:59

    If you define your subproject like this

    lazy val subProject = project in file("sub_project") // ...
    

    then you can get its path using the scoped baseDirectory setting:

    baseDirectory.in(subProject).value.getAbsolutePath
    

    Or in the sbt console:

    > show subProject/baseDirectory
    

    About the problem with your code (beside that you mixed up root and sub-project in the output) is the usage of relative paths. Sbt documentation on Paths explicitly says

    Relative files should only be used when defining the base directory of a Project, where they will be resolved properly.

    Elsewhere, files should be absolute or be built up from an absolute base File. The baseDirectory setting defines the base directory of the build or project depending on the scope.

    0 讨论(0)
提交回复
热议问题