How to access Ivy directly, i.e. access dependency reports or execute Ivy commands?

元气小坏坏 提交于 2019-12-23 05:39:06

问题


SBT uses Ivy under the hood for dependencies. Ivy can generate lots of dependency reports. How can I get access to that via SBT?

In general, if I want to use an Ivy command via SBT, how can I do it? Can I generate a POM from the SBT dependencies?

UPDATE: My goal is to debug and manually fine tune problems, not to be part of any automated tasks

UPDATE 2: To debug, I'd like to see the whole transitive dependency chain, not just the top level dependencies.


回答1:


There are several options when debugging dependencies.

Using sbt-dependency-graph

You can use whatDependsOn <organization> <module> <revision> command to see where the dependency is used.

For example I have a transitive dependency to org.apache.httpcomponents:httpcore:4.0.1. To see what includes it I can use whatDependsOn.

[play-slick-advanced] $ whatDependsOn org.apache.httpcomponents httpcore 4.0.1
[info] org.apache.httpcomponents:httpcore:4.0.1
[info]   +-oauth.signpost:signpost-commonshttp4:1.2.1.2
[info]   | +-com.typesafe.play:play_2.10:2.2.0
[info]   |   +-com.typesafe.play:play-java_2.10:2.2.0
[info]   |   | +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]   |   | 
[info]   |   +-com.typesafe.play:play-jdbc_2.10:2.2.0
[info]   |   | +-com.typesafe.play:play-slick_2.10:0.5.0.8 [S]
[info]   |   |   +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]   |   |   +-org.virtuslab:unicorn_2.10:0.4 [S]
[info]   |   |     +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]   |   |     
[info]   |   +-com.typesafe.play:play-slick_2.10:0.5.0.8 [S]
[info]   |   | +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]   |   | +-org.virtuslab:unicorn_2.10:0.4 [S]
[info]   |   |   +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]   |   |   
[info]   |   +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]   |   
[info]   +-org.apache.httpcomponents:httpclient:4.0.1
[info]     +-oauth.signpost:signpost-commonshttp4:1.2.1.2
[info]       +-com.typesafe.play:play_2.10:2.2.0
[info]         +-com.typesafe.play:play-java_2.10:2.2.0
[info]         | +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]         | 
[info]         +-com.typesafe.play:play-jdbc_2.10:2.2.0
[info]         | +-com.typesafe.play:play-slick_2.10:0.5.0.8 [S]
[info]         |   +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]         |   +-org.virtuslab:unicorn_2.10:0.4 [S]
[info]         |     +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]         |     
[info]         +-com.typesafe.play:play-slick_2.10:0.5.0.8 [S]
[info]         | +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]         | +-org.virtuslab:unicorn_2.10:0.4 [S]
[info]         |   +-default:play-slick-advanced_2.10:1.0.1 [S]
[info]         |   
[info]         +-default:play-slick-advanced_2.10:1.0.1 [S]

Just using sbt

I think the fact that the reports are produced is a cool and underestimated feature. They are generated in the target/resolution-cache/reports directory, after the update task.

This is step by step guide on how to use them.

Clean project

Run update and go to target/resolution-cache/reports

Open any of the XML files with Firefox

This part is a bit tricky, for some reason some browsers will render the correct report, and some will read the file as an XML file. Not sure why it is like that, but for sure Firefox works well. Doesn't really matter which file you'll open as you can switch between them using tabs in the rendered page.




回答2:


Run the package task, and it will produce the POM in the target\scala* directory.



来源:https://stackoverflow.com/questions/24435336/how-to-access-ivy-directly-i-e-access-dependency-reports-or-execute-ivy-comman

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!