2016-06-07 48 views
3

因为某种原因,我想打一个子项目a编制要求的b编译没有b出现在a的类路径。相反,a类将通过动态加载它们来访问(是的,这通常是一个坏主意,但它是一个要求)。以前SBT版本已经询问过这个问题,例如, How to depend on other tasks and do your code in SBT 0.10?。 我试过制作编译作用依赖于其他子项目的编制,而不把它们添加到classpath中

(compile in (a, Compile)) <<= (compile in (b, Compile), compile in (a, Compile)) { 
    (_, out) => out 
} 

(基于上面的回答)和

(compile in (a, Compile)) := { 
    (compile in (b, Compile)).value 
    (compile in (a, Compile)).value 
} 

无论出现在SBT 0.13.9工作。

+0

你贴应该只是罚款两种方式 – pfn

+0

试试这个:'懒VAL A =项目(...)设置(编译编译<< =在编译dependsOn编译(编译编译B))。 .aggregate(b)中;'。我不确定你需要'聚合'在这里,尝试两个。 – yahor

+0

@yahor是的,这个工程(没有聚合)。请让这个答案,我可以接受它。 –

回答

1

您可以使用dependsOn运算符来覆盖模块a设置中的默认compile行为。

lazy val a = Project(...) 
    .settings(compile in Compile <<= compile in Compile dependsOn (compile in Compile in b)) 
+1

此解决方案依赖于不推荐使用的代码,并将导致以下消息:警告:不推荐使用'<< ='运算符。使用'key:= {x.value}'或'key〜=(old => {newValue})''。 –

相关问题