Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add test-scoped artifacts of sbt project to another's test classpath?

Tags:

sbt

There are two sbt projects: common and projectX.

The project common has some dependencies in the test scope that I want to see on the test classpath in the projectX which has common as dependency.

This is the excerpt from build.sbt in projectX with test->test configuration mapping as described in Configurations:

libraryDependencies ++= Seq(
  "org" %% "common" % "0.1" % "compile->compile;test->test"
)

Upon executing test:compile in projectX the following error shows up:

[error] (*:update) sbt.ResolveException: unresolved dependency: org#common_2.10;0.1: configuration not public in org#common_2.10;0.1: 'test'. It was required from org#projectX_2.10;0.0.1-SNAPSHOT test

How to add the test-scoped dependencies in project common to the test classpath in the project projectX?

like image 472
Marek Avatar asked Jul 28 '14 20:07

Marek


1 Answers

I've never seen the error before and can't reproduce it, but it looks like the test artifacts have not been publishLocaled as they are not by default.

According to Selecting default artifacts:

By default, the published artifacts are the main binary jar, a jar containing the main sources and resources, and a jar containing the API documentation. You can add artifacts for the test classes, sources, or API or you can disable some of the main artifacts.

To add all test artifacts:

publishArtifact in Test := true

And that's what you're supposed to do to publish the artifcts for the test configuration.

Add the following to build.sbt of the common project and publishLocal it to have the tests packaged and published to the local Ivy2 repository:

publishArtifact in Test := true

With the change you should see the following in the logs of publishLocal - mind the test-related artifacts:

> common/publishLocal
[info] Packaging /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1-sources.jar ...
[info] Packaging /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1-tests-sources.jar ...
[info] Done packaging.
[info] Done packaging.
[info] Updating {file:/Users/jacek/sandbox/multi-module-test-scope-25003683/}common...
[info] Wrote /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] :: delivering :: org#common_2.10;0.1 :: 0.1 :: release :: Mon Jul 28 23:00:41 CEST 2014
[info]  delivering ivy file to /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/ivy-0.1.xml
[info] Packaging /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1-javadoc.jar ...
[info] Done packaging.
[info] Packaging /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1.jar ...
[info] Done packaging.
[info] Test Scala API documentation to /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/test-api...
[info] Compiling 1 Scala source to /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/test-classes...
model contains 2 documentable templates
[info] Test Scala API documentation successful.
[info] Packaging /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1-tests-javadoc.jar ...
[info] Done packaging.
[info] Packaging /Users/jacek/sandbox/multi-module-test-scope-25003683/common/target/scala-2.10/common_2.10-0.1-tests.jar ...
[info] Done packaging.
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/docs/common_2.10-javadoc.jar
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/srcs/common_2.10-tests-sources.jar
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/jars/common_2.10-tests.jar
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/jars/common_2.10.jar
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/srcs/common_2.10-sources.jar
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/poms/common_2.10.pom
[info]  published common_2.10 to /Users/jacek/.ivy2/local/org/common_2.10/0.1/docs/common_2.10-tests-javadoc.jar
[info]  published ivy to /Users/jacek/.ivy2/local/org/common_2.10/0.1/ivys/ivy.xml
[success] Total time: 2 s, completed Jul 28, 2014 11:00:43 PM
like image 188
Jacek Laskowski Avatar answered Nov 12 '22 17:11

Jacek Laskowski