【问题标题】:Exclude generated source package directory in SBT project在 SBT 项目中排除生成的源包目录
【发布时间】:2017-05-05 15:59:47
【问题描述】:

我有一个 SBT 项目,它使用 sbt-xjc 插件从 QTI XSD(特别是 this one)创建 JAXB Java 类。我的 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?

我尝试了类似于this answer 的方法,但它不起作用。 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 类。

【问题讨论】:

  • 您是否尝试打印您的托管来源?它们是否包含您要排除的文件?

标签: java scala jaxb sbt xjc


【解决方案1】:

您使用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")) }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2016-06-03
    • 2015-11-07
    相关资源
    最近更新 更多