我的项目包含一些依赖性,这些依赖性正在拉动相同的依赖关系。
公共依赖项storm-kafka
具有新版本1.0.2和旧版本0.10.0
在构建一个带阴影的jar时,我会看到我的胖罐中的两个版本中的类,并且在执行过程中会以某种方式查看旧版本的类,因为其他与旧版本相关的依赖项不是ClassNotFoundError
。那里。
jar -xvf my_shaded_fat_jar.jar
find . -name KeyValueSchemeAsMultiScheme.class
./org/apache/storm/kafka/KeyValueSchemeAsMultiScheme.class
./storm/kafka/KeyValueSchemeAsMultiScheme.class
storm/kafka
是旧版本,org/apache/storm/kafka
是我想要的新版本。
令人惊讶的是,我在~/.m2
回购中找不到0.10.0:
ls ~/.m2/repository/org/apache/storm/storm-kafka/
1.0.2
# no 0.10.0 here !
如何调试maven以找出较旧的依赖项所在的位置?
编辑:
在运行mvn dependency:tree -Dverbose -Dincludes=storm.kafka
时,我得到:
[WARNING] The POM for org.apache.storm:flux-core:jar:1.0.2 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.apache.storm:storm-kafka:jar:1.0.2 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) ---
[WARNING] Failed to build parent project for org.apache.storm:flux-core:jar:1.0.2
[WARNING] Invalid POM for org.apache.storm:flux-core:jar:1.0.2, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Invalid POM for org.apache.storm:storm-kafka:jar:1.0.2, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] Failed to build parent project for org.apache.storm:flux-core:jar:1.0.2
[WARNING] Invalid POM for org.apache.storm:flux-core:jar:1.0.2, transitive dependencies (if any) will not be available, enable debug logging for more details
为什么poms无效?
我刚刚删除.m2
~/.m2/repository/org/apache/storm
回购
答案 0 :(得分:1)
mvn dependency:build-classpath -Dmdep.outputFile=f
列出所有依赖罐的列表。
现在对它们进行迭代,并将其内容添加到文件中
for f in `cat f | tr ';' ' '`
do
echo $f >> out
unzip -v $f >> out
done
答案 1 :(得分:0)
您可以使用Maven树目标显示所有使用的依赖项。这默认打印出完整的dep树,但你也可以找到你感兴趣的特定依赖 - 例如try:
mvn依赖:tree -Dverbose -Dincludes = storm.kafka
了解卡夫卡的情况。更多信息可以在这里找到:
答案 2 :(得分:0)
如果您喜欢炸药,这似乎可以工作:
#!/usr/bin/env amm
import $ivy.`com.lihaoyi::os-lib:0.7.0`
// Run in the root of a maven project to find which jars contain the class
// Example: all_classes.sc org.redangus.core.func.Ex
// amm, mvn and jar must be in PATH
@main
def main(fullClassName: String): Unit = {
val clazz = fullClassName.replace('.', '/') + ".class"
println("Searching for file " + clazz)
val file = os.root / "tmp" / s"all_classes_${System.getProperty("user.name")}"
if (os.exists(file)) os.remove(file)
if (os.proc("mvn", "dependency:build-classpath",
s"-Dmdep.outputFile=$file").call().exitCode != 0) {
println("Something is amiss")
sys.exit(1)
}
var found = false
os.read(file).split(":").foreach(f => {
os.proc("jar", "-tf", f).call().toString().split("\n").foreach(l => {
if (l == clazz) {
println(s"$f")
found = true
}
})
})
os.remove(file)
if (! found) println("No matches found.")
}