Created
October 9, 2015 18:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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