Skip to content

Instantly share code, notes, and snippets.

@mattnelson
Created October 9, 2015 18:45
Show Gist options
  • Save mattnelson/3225aac8ec3be4db7194 to your computer and use it in GitHub Desktop.
Save mattnelson/3225aac8ec3be4db7194 to your computer and use it in GitHub Desktop.
Ruby script to create an explicit dependency management section for all maven dependencies.
require 'nokogiri'
dependencies = {}
`mvn dependency:tree | grep [INFO]`.split("\n").each do | dependency |
/^\[INFO\]\s[\+\-|\s\\]+(?<key>(?<group>.+):(?<artifact>.+):jar:(?<version>.+)):/ =~ dependency
next if key.nil?
dependencies[key] = {group: group, artifact: artifact, version: version}
end
builder = Nokogiri::XML::Builder.new do |xml|
xml.dependencyManagement {
xml.dependencies {
dependencies.sort.to_h.each do |key, value|
xml.dependency {
xml.groupId_ value[:group]
xml.artifactId_ value[:artifact]
xml.version_ value[:version]
}
end
}
}
end
puts builder.to_xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment