Re: Using relative file paths in sub module of multi module project

323 views
Skip to first unread message

Sebastian

unread,
Oct 3, 2012, 5:32:34 PM10/3/12
to simple-b...@googlegroups.com
I'm using sbt 0.12.0.

On Wednesday, October 3, 2012 9:21:53 PM UTC, Sebastian wrote:
I have setup an example multi module project with an Build.scala:
object TestProjectBuild extends Build {
lazy val master = 
Project("master", file(".")) aggregate(sub1)

lazy val sub1 = 
Project("sub1", file("sub1"))
}

The directory layout is:
./project/Build.scala
./sub1/build.sbt
./sub1/src/test/resources/META-INF/spring/testContext.xml
./sub1/src/test/scala/
...

In my sub module "sub1" I have tests that reference a file with a relative file path:

@ContextConfiguration(locations = { "file:src/test/resources/META-INF/spring/testContext.xml" })

When I run the tests from the top level directory the tests fail because the file couldn't be found. If I run them from the sub1 directory the tests pass.

Calling 'base-directory' from the sbt console returns the correct base directories:

sub1/*:base-directory
  /home/sebastian/sbt-playground/sub1
master/*:base-directory
 /home/sebastian/sbt-playground

Note that I can't use getClass.getResources in an annotation.

How can I configure sbt to make the tests work?

ericdr...@gmail.com

unread,
May 20, 2013, 9:53:16 PM5/20/13
to simple-b...@googlegroups.com
Sebastian:

Did you figure this out?  I'm having the same problem.

Josh Suereth

unread,
May 21, 2013, 7:32:47 AM5/21/13
to simple-b...@googlegroups.com

So.  I believe using relative paths is always a danger, as I don't think you can change current working directory in java.

Sbt is not forking to run your tests, although you could do so and it would most likely fix your immediate issue.

Another possibility is to try to use the classsloader to pull in resources instead of file paths.

Hope that helps!

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
To post to this group, send email to simple-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ericdr...@gmail.com

unread,
May 21, 2013, 8:46:23 PM5/21/13
to simple-b...@googlegroups.com
[Sbt is not forking to run your tests, although you could do so and it would most likely fix your immediate issue.]  

I've tried this using 

fork in Test := true,
baseDirectory in Test := file("correct subdirectory")  //This shouldn't even be needed because my subproject defines the base directory

At the console I check test:base-directory and get the correct value and test:fork and get the correct value.  

However, when I run my tests, which specify test configuration files using relative paths (e.g. "./conf/config.file), the files are not found.  

Further, I've added 

println(new File(".").getCanonicalPath())

to one of test fixtures just to see what's up and it returns the (incorrect) parent folder instead of the subdirectory which holds my subproject.

Any help would be appreciated.
Reply all
Reply to author
Forward
0 new messages