【问题标题】:Compiling scala file placed under resource folder and access it in test class编译放置在资源文件夹下的scala文件并在测试类中访问它
【发布时间】:2021-12-07 01:45:05
【问题描述】:

我有一个项目设置为:

Project
|__src
|  |_main
|  | |_src_file_1.scala
|  | |_src_file_2.scala
|  |
|  |_resources
|    |_resource_file_1.scala
|
|__test
   |_test_file_1.scala

main 中的源文件 (src_file_1.scala, src_file_2.scala) 均已编译,但资源文件夹 (resource_file_1.scala) 中的资源文件未编译。它包含一些需要测试的类下的scala代码。

有没有办法编译这个类并在test_file_1.scala 中访问它,这是一个测试文件并测试所有其他源文件。

注意:我想有一种方法可以读取源代码,使用 scala 编译器在测试类中编译它,然后将编译后的代码用于测试目的。

【问题讨论】:

  • 最好遵循将资源文件夹放在主文件夹中的做法,所以src/main/resources
  • 为什么要在资源文件夹中放一个 Scala 文件?

标签: scala sbt scalatest


【解决方案1】:

您希望拥有这样的项目结构是否有特定的原因?这里有一个 sbt 约定https://www.scala-sbt.org/1.x/docs/Directories.html

src/
  main/
    resources/
       <files to include in main jar here>
    scala/
       <main Scala sources>
    java/
       <main Java sources>
  test/
    resources
       <files to include in test jar here>
    scala/
       <test Scala sources>
    java/
       <test Java sources>

scala 中的所有内容都将被编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-27
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    相关资源
    最近更新 更多