scala提供的依赖项无法提供

jc3wubiy  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(376)

我得到了一个烫手的(scala中的hadoop抽象层)项目,我正试图用gradle构建它。
看起来hadoop成为了最新版本中提供的依赖项,它需要一些解决方法。
所以我修改了build.gradle脚本如下:

apply plugin: 'scala'
apply plugin: 'idea'
configurations {
    provided
}
sourceSets {
    main { compileClasspath += configurations.provided }
}
repositories {
  mavenLocal()
  mavenCentral()
  maven{
    url 'http://conjars.org/repo/'
    }
}
ext.cascadingVersion = '2.1.6'
ext.hadoopVersion = '1.1.2'
dependencies {
  compile 'org.scala-lang:scala-compiler:2.9.2'
  compile 'org.scala-lang:scala-library:2.9.2'
  compile 'bixo:bixo-core:0.9.1'
  compile 'org.testng:testng:6.8.7'
  testCompile  'org.scala-tools.testing:specs:1.6.2.2_1.5.0'
  compile( 'com.twitter:scalding_2.9.2:0.8.1' )
  compile( group: 'cascading', name: 'cascading-core', version: cascadingVersion )
  compile( group: 'cascading', name: 'cascading-hadoop', version: cascadingVersion )
  provided "org.apache.hadoop:hadoop-client:${hadoopVersion}"
}
jar {
  description = "Assembles a Hadoop-ready JAR file"
  doFirst {
    into( 'lib' ) {
      from configurations.compile
    }
  }
  manifest {
    attributes( "Main-Class": "com.Crawler" )
  }
}

我认为这能解决问题。但在尝试构建时,我经常遇到以下错误:

[ant:scalac] Element '/Users/tkmafj4/Projects/AIT/Crawler/build/resources/main' does not exist.
[ant:scalac] scala.tools.nsc.symtab.Types$TypeError: class file needed by Source is missing.
[ant:scalac] reference value hadoop of package org.apache refers to nonexisting symbol.

我的配置好像少了点什么。
如何检查是否正在获取源?
什么是正确的解决方法来编译它?

tpxzln5u

tpxzln5u1#

hadoop 成为一个“提供”的依赖 cascading 意味着取决于 cascading 不会再进站了 hadoop ,因为 hadoop 是由目标环境或创建最终可部署存档的任何人提供的。如果 hadoop 依赖需要进入你的肥罐,你需要使它(至少)成为一个 runtime 附属国。但由于编译似乎有一些问题,我会尽量使它成为一个 compile 附属国。
如果 hadoop 依赖项应该在编译类路径上,而不是在胖jar中,您需要添加如下内容 sourceSets.main.compileClasspath += configurations.provided .
你的胖jar任务需要打包 configurations.runtime 而不是 configurations.compile ,和 doFirst { 应拆下管路(以及相应的闭合撑杆)。

相关问题