排除SBT项目中生成的源码包目录

Exclude generated source package directory in SBT project

我有一个特别使用 sbt-xjc plugin to create JAXB Java classes from the QTI XSD (this one 的 SBT 项目)。我的 XSD 依赖于 MathML,它会按预期创建 MathML 类 和 QTI。我目前使用的唯一 xjc 标志是 -verbose -extension.

这是我的目录树:

- src/main/resources/imsqti_v2p1.xsd
- target
  - classes/org
    - imsglobal/... - Contains QTI .class files
    - w3_1998/math/mathml/... - Contains MathML .class files
  - src_managed/main/org
    - imsglobal/... - Contains generated QTI .java files
    - w3/_1998/math/mathml/... - Contains MathML .java files

但是,我有另一个依赖于 MathML 的 JAXB 项目,该项目也生成 MathML 类。我想摆脱重复的 类。我创建了一个 MathML JAXB 项目并将其添加为其他 2 个项目的依赖项。我如何告诉 SBT 创建一个不包含 MathML 的 QTI autogen JAR 类?

我尝试了类似于 的方法,但它不起作用。 MathML 类 仍包含在 JAR 中。这是我添加到 build.sbt:

中的尝试
val mathmlPath = "org/w3/_1998/math/mathml"
def isInPath(path: String, file: File) = file.getCanonicalPath.startsWith(mathmlPath)
(managedSources in Compile) := managedSources.value.filterNot(file => isInPath(mathmlPath,file))

我将接受以下任何一项以使其正常工作:

  1. 将 sbt-xjc 配置为不生成 MathML 类。
  2. 将 sbt 配置为不编译 MathML 类。
  3. 将 sbt 配置为不打包 MathML 类。

您使用 mappings 键来定义 jar 的内容。参见:http://www.scala-sbt.org/0.13/docs/Howto-Package.html

在您的情况下,您可以通过 build.sbt 中的以下设置排除 MathML 文件(假设它们在 jar 中都以 org/w3_1998/math/mathml 开头):

mappings in (Compile, packageBin) ~= { _.filterNot {
  case (filePath, pathInJar) => pathInJar.startsWith("org/w3_1998/math/mathml")
}}

或不那么冗长(对某些人来说可读性较差):

mappings in (Compile, packageBin) ~= { _.filterNot(_._2.startsWith("org/w3_1998/math/mathml")) }