我正在学习Gradle如何工作,我无法理解它如何解决项目传递依赖.
目前,我有两个项目:
无论我如何尝试,当我构建projectB时,gradle不包含projectB的编译或运行时类路径中的任何projectA依赖项(X和Y).我只是通过在projectB的构建脚本中包含projectA的依赖项来设法使它工作,在我看来这没有任何意义.这些依赖项应自动附加到projectB.我很确定我错过了什么,但我无法弄清楚是什么.
我已经读过"lib dependencies",但它似乎只适用于此处描述的本地项目,而不适用于外部依赖项.
这是我在根项目中使用的build.gradle(包含projectA和projectB的那个):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.3'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'idea'
group = 'com.company'
repositories {
mavenCentral()
add(new org.apache.ivy.plugins.resolver.SshResolver()) {
name = 'customRepo'
addIvyPattern "ssh://.../repository/[organization]/[module]/[revision]/[module].xml"
addArtifactPattern "ssh://.../[organization]/[module]/[revision]/[module](-[classifier]).[ext]"
}
}
sourceSets {
main {
java {
srcDir 'src/'
}
}
}
idea.module { downloadSources = true }
// task that create sources jar
task sourceJar(type: Jar) {
from sourceSets.main.java
classifier 'sources'
} …Run Code Online (Sandbox Code Playgroud) 最近,我已经了解了可堆叠的特征模式,并按照此处描述的示例进行了操作.一切正常,但有一个案例我无法理解:
trait A {
def test : String
}
trait B extends A {
// 'abstract override' modifier required as
// the test() method is not yet implemented
abstract override def test = {
s"B${super.test}"
}
}
class C extends A with B {
// test method concrete implementation
override def test = { "C" }
}
<console>:10: error: overriding method test in trait B of type => String;
method test needs `abstract override' modifiers
class …Run Code Online (Sandbox Code Playgroud) 我刚刚遇到一种非常奇怪的行为.这是代码:
// So far everything's fine
val x: Try[Try[Unit]] = Try(Try{})
x: scala.util.Try[scala.util.Try[Unit]] = Success(Success(()))
// Compilation error should happen here
val x: Try[Unit] = Try(Try{})
// Wuut ?
x: scala.util.Try[Unit] = Success(())
Run Code Online (Sandbox Code Playgroud)
我在这里期待编译错误,因为(据我所知)a Try[Try[Unit]]不应该分配给a Try[Unit],但是在这种情况下似乎a Try{}自动转换为a Unit(()).怎么可能?
我正在尝试使用正则表达式和模式匹配从String中提取值:
val reg = """((?<=a)b)""".r
"ab" match { case reg(x) => x }
Run Code Online (Sandbox Code Playgroud)
无论我如何尝试,它仍然会引发MatchError.但是,如果我尝试以下方法:
reg.findAllIn("ab").mkString
Run Code Online (Sandbox Code Playgroud)
正则表达式按预期运行: res28: String = b
当然,我可以简单地更改正则表达式并添加另一个组:
val reg = """(a)(b)""".r
"ab" match { case reg(_,x) => x }
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有可能使用模式匹配的前瞻/后方运算符.
先感谢您.
我正在尝试通过比较给定的属性来实现一个负责返回两个RDD的交集的函数.
def intersect[T](left: RDD[Article], right: RDD[Article])(by: Article => (T,Article)) = {
val a: RDD[(T, Article)] = left.map(by)
val b: RDD[(T, Article)] = right.map(by)
a.join(b).map { case (attr, (leftItem, rightItem)) => leftItem }
}
Run Code Online (Sandbox Code Playgroud)
但是,在编译期间,sbt会抛出以下错误:
Error:(128, 7) value join is not a member of org.apache.spark.rdd.RDD[(T, org.example.Article)]
a.join(b).map { case (attr, (leftItem, rightItem)) => leftItem }
^
Run Code Online (Sandbox Code Playgroud)
如果我硬编码类型,一切都很顺利.知道为什么我有这个错误吗?
UPDATE
scala似乎无法从RDD [(T,Article)]到PairRDDFunctions [K,V]进行隐式转换,但我不知道为什么.
UPDATE
如果我像这样修改代码:
def intersect[T](left: RDD[Article], right: RDD[Article])(by: Article => (T,Article)) = {
val a: PairRDDFunctions[T, Article] = left.map(by)
val b: …Run Code Online (Sandbox Code Playgroud) 我玩了一些占位符,发现了一个奇怪的案例:
val integers = Seq(1, 2)
val f = (x:Int) => x + 1
integers.map((_, f(_)))
Run Code Online (Sandbox Code Playgroud)
返回
Seq[(Int, Int => Int)] = List((1,<function1>), (2,<function1>))
Run Code Online (Sandbox Code Playgroud)
我在期待
Seq[(Int, Int)] = List((1, 2), (2, 3))
Run Code Online (Sandbox Code Playgroud)
如果我进行以下更改,一切都按预期工作:
integers.map(i => (i, f(i)))
Run Code Online (Sandbox Code Playgroud)
知道为什么f在映射期间不应用该函数吗?
我正在阅读Haskell书(http://haskellbook.com/),并陷入以下练习中:
f :: Float
f = 1.0
-- Question: Can you replace `f`'s signature by `f :: Num a => a`
Run Code Online (Sandbox Code Playgroud)
起初,我认为答案是肯定的。浮动提供了一个实例民,所以代以Num a => a一个Float值应该罚款(我想协方差这里)。
但是,这不会编译:
Could not deduce (Fractional a) arising from the literal ‘1.0’
from the context: Num a
bound by the type signature for:
f :: forall a. Num a => a
at ...
Possible fix:
add (Fractional a) to the context of
the type signature for:
f :: forall a. …Run Code Online (Sandbox Code Playgroud)