我一直试图将一个maven项目转换成一个grade build。POM.xml中的一个依赖项是avro-tools,如下所示:
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro-tools</artifactId>
<version>1.10.2</version>
</dependency>
在项目中运行 gradle init 时,gradle 从 pom 生成一个 build.gradle 文件.xml其中包含以下内容作为依赖项: 实现组: 'org.apache.avro', 名称: 'avro-tools', 版本: '1.10.0'
但是,在运行构建时,我得到以下错误:
Could not find avro-mapred-1.10.2-hadoop2.jar (org.apache.avro:avro-mapred:1.10.2).
Searched in the following locations:
https://repo.maven.apache.org/maven2/org/apache/avro/avro-mapred/1.10.2/avro-mapred-1.10.2-hadoop2.jar
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
如果相同的构建在maven中运行,那么这个构建工作得很好。
编辑:
完整的build.gradle文件:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.scala-lang', name: 'scala-library', version:'2.12.6'
implementation group: 'org.apache.spark', name: 'spark-core_2.12', version:'2.4.1'
implementation group: 'org.apache.spark', name: 'spark-yarn_2.12', version:'2.4.1'
implementation group: 'org.apache.spark', name: 'spark-sql_2.12', version:'2.4.1'
implementation group: 'org.apache.spark', name: 'spark-hive_2.12', version:'2.4.1'
implementation group: 'org.apache.spark', name: 'spark-avro_2.12', version:'2.4.1'
implementation group: 'com.typesafe', name: 'config', version:'1.4.1'
implementation group: 'com.sun.mail', name: 'javax.mail', version:'1.5.6'
implementation group: 'org.apache.avro', name: 'avro-tools', version:'1.10.2'
implementation group: 'com.typesafe.play', name: 'play-json_2.12', version:'2.9.2'
testImplementation group: 'junit', name: 'junit', version:'4.12'
testImplementation group: 'org.scalatest', name: 'scalatest_2.12', version:'3.0.5'
testImplementation group: 'org.specs2', name: 'specs2-core_2.12', version:'4.2.0'
testImplementation group: 'org.specs2', name: 'specs2-junit_2.12', version:'4.2.0'
testImplementation group: 'org.scalatestplus', name: 'mockito-3-4_2.12', version:'3.2.4.0'
testImplementation group: 'org.mockito', name: 'mockito-core', version:'3.4.2'
testImplementation group: 'org.mockito', name: 'mockito-inline', version:'4.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
}
test {
useJUnitPlatform()
}
编辑:解决了问题,不是avro-tools一个人的问题,而是avro tools的问题
尽管我在不同的图书馆遇到了问题,但IMO的根本原因可能是相同的。
从Spark_*_2.12中排除可传递的avro-mapred依赖项对我来说很神奇。现在我要执行之前失败的Gradle构建:
找不到avro-mapred-1.11.0-hadoop2. jar(org.apache.avro:avro-mapred:1.11.0)。
但是仍然不清楚为什么Gradle会以一种奇怪的方式寻找一个完全不同的版本,将-hadoop2附加到版本中。