sbt-assembly 包括测试类 [英] sbt-assembly include test classes

查看:31
本文介绍了sbt-assembly 包括测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循sbt-assembly:包括测试类,来自https://github.com/sbt/sbt-assembly 可以正常组装

I follow sbt-assembly : including test classes from a config described in https://github.com/sbt/sbt-assembly that work ok doing assembly

当我加载 sbt 时我得到

When I load sbt I get

assembly.sbt:5: error: reference to jarName is ambiguous;
it is imported twice in the same scope by
import sbtassembly.AssemblyKeys._
and import _root_.sbtassembly.AssemblyPlugin.autoImport._
jarName in (Test, assembly) := s"${name.value}-test-${version.value}.jar"
^

所以,我注释导入行并运行 sbt:assembly 但这开始测试但不生成任何 -test-.jar.

So, I comment import line and run sbt:assembly but that begin the test but dont generate any -test-.jar.

有人知道如何生成包含测试类的jar吗?谢谢

Any one know how to generate the jar that include the test classes? Thanks

推荐答案

我不得不删除这一行(我认为它现在基于 https://github.com/sbt/sbt-assembly/blob/546d200477b64e2602fa0420602b52b52b52b52b52b52b52b122525252588888888888888.md" rel="noreferrer">

I had to remove this line (I think it is now autoimported based on https://github.com/sbt/sbt-assembly/blob/546d200477b64e2602beeb65bfa04306122cd9f5/Migration.md)

import sbtassembly.AssemblyKeys._

我将其余的(即下面的两行)添加到 build.sbt 而不是 assembly.sbt:

And I added the rest (i.e. the two lines below) to build.sbt instead of assembly.sbt:

Project.inConfig(Test)(baseAssemblySettings)
jarName in (Test, assembly) := s"${name.value}-test-${version.value}.jar"

采取这些步骤后,test:assembly 确实为我生成了一个测试 jar 但是我希望 jar 只包含测试类(类似于 test:package>),但它似乎也包括非测试类.换句话说,如果我有 src/main/scala/Foo.scalasrc/test/scala/FooTest.scala 那么我认为 生成的 jar>test:assembly 只会包括 FooTest.class 但它似乎也包括 Foo.class.希望这对您来说不是问题,因为我还不确定如何解决这个问题.

After taking those steps, test:assembly does produce a test jar for me however I expected the jar to only include test classes (similar to test:package), but it seems to include non-test classes as well. In other words, if I have src/main/scala/Foo.scala and src/test/scala/FooTest.scala then I thought that the jar produced by test:assembly would only include FooTest.class but it seems to also include Foo.class. Hopefully that's not an issue for you as I'm not yet sure how to workaround that.

如果您希望 jar 只包含来自 src/test 的类(就像我所做的那样),那么您可以将以下内容添加到您的 build.sbt 中过滤掉您的类路径中可能存在的所有其他内容:

If you want the jar to only include classes from src/test (like I did), then you can add the following to your build.sbt to filter out everything else that may be on your classpath:

fullClasspath in (Test, assembly) := {
  val cp = (fullClasspath in (Test, assembly)).value
  cp.filter({x => x.data.getPath.contains("test-classes")})
}

这篇关于sbt-assembly 包括测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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