[英]sbt-assembly include test classes
I follow sbt-assembly : including test classes from a config described in https://github.com/sbt/sbt-assembly that work ok doing assembly我遵循sbt-assembly :包括https://github.com/sbt/sbt-assembly中描述的配置中的测试类, 这些类可以正常进行组装
When I load sbt I get当我加载 sbt 我得到
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"
^
So, I comment import line and run sbt:assembly but that begin the test but dont generate any -test- .jar.所以,我注释导入行并运行 sbt:assembly 但这开始测试但不生成任何-test- .jar。
Any one know how to generate the jar that include the test classes?有人知道如何生成包含测试类的 jar 吗? Thanks
谢谢
I had to remove this line (I think it is now autoimported based on https://github.com/sbt/sbt-assembly/blob/546d200477b64e2602beeb65bfa04306122cd9f5/Migration.md )我不得不删除这一行(我认为它现在是基于https://github.com/sbt/sbt-assembly/blob/546d200477b64e2602beeb65bfa04306122cd9f5/Migration.md 自动导入的)
import sbtassembly.AssemblyKeys._
And I added the rest (ie the two lines below) to build.sbt instead of assembly.sbt :我将其余的(即下面的两行)添加到build.sbt而不是assembly.sbt :
Project.inConfig(Test)(baseAssemblySettings)
jarName in (Test, assembly) := s"${name.value}-test-${version.value}.jar"
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.
采取这些步骤后, test:assembly确实为我生成了一个测试 jar,
但是我希望 jar 只包含测试类(类似于
test:package ),但它似乎也包含非测试类。
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 .
换句话说,如果我有
src/main/scala/Foo.scala和
src/test/scala/FooTest.scala那么我认为
test:assembly生成的 jar 只会包含
FooTest.class但它似乎也包含
Foo .class 。
Hopefully that's not an issue for you as I'm not yet sure how to workaround that.
希望这对您来说不是问题,因为我还不确定如何解决这个问题。
EDIT: 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:编辑:如果您希望 jar 只包含来自src/test 的类(就像我所做的那样),那么您可以将以下内容添加到您的 build.sbt 以过滤掉您的类路径中可能存在的所有其他内容:
fullClasspath in (Test, assembly) := {
val cp = (fullClasspath in (Test, assembly)).value
cp.filter({x => x.data.getPath.contains("test-classes")})
}
This works for me:这对我有用:
lazy val root = project.settings(
assembly / fullClasspath := (assembly / fullClasspath).value ++ (Test / fullClasspath).value
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.