在基于SBT的Scala项目中组织文件 [英] Organizing files in a SBT-based scala project

查看:112
本文介绍了在基于SBT的Scala项目中组织文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是Intellij IDE的新手,没有Java背景.我查看了构建定义简要了解如何组织我的Scala文件,但它们的示例并未涵盖随附的基于SBT的项目的完整结构.

Newcomer to the Intellij IDE here, with no Java background. I've looked at Build Definition to get a brief idea on how should I organize my scala files, but their example doesn't cover the full structure of an SBT-based project shown attached.

您能否建议每个文件夹用于什么目的(例如,我的源文件应该存放在什么地方等),还可以指出我可以阅读更多内容的来源.

Can you advise what each folder should be used for (e.g. where my source files should go, etc.) and also point me to sources where I can go read up more.

非常感谢

推荐答案

在这里描述得很好: http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Directories.html

It is described pretty well here: http://www.scala-sbt.org/0.13.5/docs/Getting-Started/Directories.html

但是总结一下.

.想法: 它包含您的想法项目的项目文件,与sbt本身没有任何关系.但是,每次sbt构建文件更改时,想法(如果启用了自动刷新)都会更新其自己的项目.

.idea: This contains the project files for your idea project, and has nothing directly to do with sbt itself. However idea (if auto refresh is enabled) updates its own project, each time the sbt build files change.

项目: 除主构建文件(以.sbt结尾的文件)外,此文件包含sbt项目文件. Sbt构建本身是基于scala的,如果您需要在构建中包含一些scala代码(例如,代码生成/元编程,预编译器宏),则可以将scala源文件放置在此目录中.这些文件的代码可以在构建系统中使用,而不是项目本身的一部分.要真正了解构建的方式,则需要了解应如何放置构建的sbt文件和scala文件的区别.当您运行sbt时,它将在您站立的目录中搜索.sbt文件,当找到这些文件时,它将在项目目录中搜索scala文件.这些文件一起是构建系统的源,但是由于它们是源文件,因此需要先构建它们,然后才能使用它们.为了构建此构建系统,sbt使用sbt.因此,需要一个构建系统来构建构建系统.因此,它将在项目目录中查找sbt文件,并在项目/项目中查找此构建的scala文件,然后构建这些文件以获得构建系统,该构建系统可以构建构建系统(可以构建您的项目).实际上,它可以继续递归向下到任何project/project/project...目录,直到找到不包含scala文件的项目文件夹为止,因此在使用之前不需要构建.

project: This contains the sbt project files, except for the main build file (files ending in .sbt). Sbt build is itself based on scala, and if you need to have some scala code included in your build (e.g., code-generation/meta-programming, pre-compiler macros), then you can place scala source files in this directory. The code of these files can be used in your build system, and is not part of your project itself. To really understand how a build is made, then you will need to understand the difference in how sbt files and scala files for the build should be placed. When you run sbt, then it will search for .sbt files in the directory your are standing in, when these are found, it will search for scala files in the project directory. These files together are the source of the build system, but because these are source files, they need to be built before they can be used. To build this build system, sbt uses sbt. So a build system to build the build system is needed. It therefore looks for sbt files inside the project directory, and scala files for this build inside project/project and build these files to get a build system, that can build the build system (that can build your project). Actually it can continue recursive down to any project/project/project... directory, until it finds a project folder containing no scala files, and therefore needs no building before use.

项目内的目标文件夹是构建定义的sbt构建的目标文件夹.参见下面的目标文件夹.

The target folder inside project, is the target folder for the sbt build of your build definition. See below what a target folder is.

通常,您无需担心这一点;只要记住根目录中的build.sbt是项目的构建脚本即可. project/plugins.sbt定义为您的构建系统激活的插件,project/build.properties包含特殊的sbt属性.目前,我现在拥有的唯一sbt属性是应使用哪个版本的sbt.

Normally you would not need to be concerned about this; just remember that build.sbt in your root directory is the build script for your project. project/plugins.sbt defines plugins activated for your build system, and project/build.properties contains special sbt properties. Currently the only sbt property I now of, is what version of sbt should be used.

源代码: 在这里放置项目的源文件.您应该将任何Java源代码放置在src/main/java中,将scala源代码放置在src/main/scala中.资源放置在src/main/resources中.

src: This is where your place the source files of your project. You should place any java sources in src/main/java, scala sources in src/main/scala. Resources are placed in src/main/resources.

如果您有一些代码与不同版本的scala不兼容,则通常使用src/main/scala_2.11文件夹.在这种情况下,当为不同版本的scala构建时,您将能够配置sbt以使用不同的源文件.您可能不需要这个,所以我建议您删除src/main/scala_2.11文件夹.

The src/main/scala_2.11 folder is typically used, if you have some code that it not binary compatible with different versions of scala. In such cases you would be able to configure sbt to use different source files when building for different versions of scala. You probably do not need this, so I would advise to just delete the src/main/scala_2.11 folder.

测试源放置在src/test/javasource/test/scala内部,测试资源放置在src/test/resources中.

Test sources are placed inside src/test/java and source/test/scala, and test resources are placed in src/test/resources.

目标 该文件夹是sbt的目标文件夹.所有已编译的文件,生成的包等都放置在此目录中的某个位置.

target This folder is the target folder for sbt. All compiled files, generated packages and so on are placed somewhere inside this dir.

此目录中的大多数内容都没有那么有趣,因为其中大部分只是内部sbt内容.但是,如果您通过调用sbt package来构建jar文件,则它将被放置在target/scala-x内部(其中x是scala版本).还有很多不同的插件,可以用不同的方式打包您的应用程序,它们通常还会将打包文件放置在目标目录中的某个位置.

Most things in this dir are not so interesting, as most of it is just internal sbt things. However if your build a jar file by calling sbt package, then it will be placed inside target/scala-x (where x is the scala version). There are also a lot of different plugins, that can package your application in different ways, and they will normally also place the package files somewhere inside the target dir.

这篇关于在基于SBT的Scala项目中组织文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆