我正在尝试为Apache Kafka POC建立一个简单的gradle项目。请提出解决方法的建议。
构建时的堆栈跟踪
Root cause: org.gradle.internal.resolve.ArtifactNotFoundException: Could not find jms.jar (javax.jms:jms:1.1).
Searched in the following locations:
https://repo1.maven.org/maven2/javax/jms/jms/1.1/jms-1.1.jar
这是用于项目的gradle文件
apply plugin: 'java-library'
repositories {
mavenCentral()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
compile(group: 'org.apache.kafka', name: 'kafka_2.10', version: '0.8.0')
compile 'org.apache.kafka:kafka-clients:0.10.2.0'
}
答案 0 :(得分:1)
问题来自传递库 log4j-1.2.15 ,该传递库属于 zookeeper 传递库:
+--- org.apache.kafka:kafka_2.10:0.8.0
| +--- org.apache.zookeeper:zookeeper:3.3.4
| | +--- log4j:log4j:1.2.15
| | | +--- javax.mail:mail:1.4
| | | | \--- javax.activation:activation:1.1
| | | +--- javax.jms:jms:1.1
| | | +--- com.sun.jdmk:jmxtools:1.2.1
| | | \--- com.sun.jmx:jmxri:1.2.1
| | \--- jline:jline:0.9.94
| | \--- junit:junit:3.8.1
此 log4j 版本依赖于其他不在maven中央存储库中托管的库(请参见What happened to JMS 1.1 in Maven Central?)
因此您可以添加 jcenter()存储库
repositories {
jcenter()
mavenCentral()
}
但是随后您将要排除的其他传递库还有其他问题:从传递依赖项中排除 log4j 或 jdmk 和 jmx 如下:
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
compile(group: 'org.apache.kafka', name: 'kafka_2.10', version: '0.8.0'){
exclude group : "com.sun.jdmk"
exclude group : "com.sun.jmx"
// or simply exclude all log4j:
// exclude group : "log4j"
}
compile 'org.apache.kafka:kafka-clients:0.10.2.0'
}
有关 log4j 1.2.15 的问题的模式详细信息:http://unitstep.net/blog/2009/05/18/resolving-log4j-1215-dependency-problems-in-maven-using-exclusions/