简体   繁体   中英

Play framework/ SBT : compile/build project with two sets of dependencies respectively

Currently I am building a Play project(v2.2.3) that connects to hadoop jobtracker, which means I need to build it with hadoop lib jars

It works fine when I work with hadoop 1.x

Now my project wants to support both hadoop1.x and hadoop2.x. But as h1 and h2 gives different lib jars, I want to build my Play project with two sets of dependencies (hadoop1.x and hadoop 2.x) respectively, and produce two deployable zips which can run on h1 and h2, respectively.

As I am exploring various ways, I found one closest: In build.sbt, I create two sub projects with the same root directory(which is the root dir of the project), like:

lazy val h2 = Project("h2",file(".")).settings(
    version := "h2",
    libraryDependencies += "some hadoop2 dependency"
)

lazy val h1 = Project("h1",file(".")).settings(
    version := "h1",
    libraryDependencies += "some hadoop1 dependency"
)

But this gives an error when exec "play compile" :

overlapping output directories :  proj_root/target

I tried to solve it by changing output directory, doing things like :

lazy val h1 = Project("h1",file(".")).settings(
    version := "h1",
    libraryDependencies += "some hadoop1 dependency"
    target in Compile := file("some_my_own_dir"),
)

But it doesn't work. I can't change the output dir of my project, and the error message remains the same.

So any suggestions on building a project with two different sets of dependencies at the same time (or choose one set to build with as I/user instructs), so that I/user don't have manually edit the build.sbt? Or any suggestions on my tentative solution to change the output dir of a play project?

I have been stuck in this problem for several days and is going crazy about it. Thanks for help!

libraryDependencies ++= if (sys.props.get("hadoop.version").exists(_ == "1")) Seq(
  // hadoop 1 dependencies
) else Seq(
  // hadoop 2 dependencies
)

Then:

$ activator -Dhadoop.version=1 dist
$ activator -Dhadoop.version=2 dist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM