[Groovy] Maven Pom to Ivy Dependencies
Last night I needed a way to quickly convert a large amount of pom dependency syntax into Ivy dependency syntax. A quick google search didn't reveal much so instead of wasting time searching deeper I wrote my own. I don't claim this to be perfect in any way. I wrote it as quickly as possible. Feel free to use it, modify it, or whatever. And it doesn't try and implement a whole lot of the features like excludes, classifiers, etc. It is as simple as possible in this state. But that is all I needed.
import groovy.swing.SwingBuilder
import javax.swing.JFileChooser
import javax.swing.WindowConstants as WC
class Dependency {
String org
String name
String rev
}
swing = SwingBuilder.build {
frame(id:'f', title: "Maven To Ivy", pack: true, show: true,
defaultCloseOperation: WC.EXIT_ON_CLOSE) {
panel(id: 'p') {
tableLayout {
tr {
td {
button(text: 'Select Pom File', actionPerformed: {
fc = new JFileChooser()
if (fc.showDialog(null, 'Select Pom') == JFileChooser.APPROVE_OPTION) {
processPom(fc.getSelectedFile())
}
})
}
}
tr {
td {
scrollPane() {
textArea(id:'output', rows:10, columns:50)
}
}
}
tr {
td {
checkBox(text:'Append', id:'append')
}
}
}
}
}
}
def processPom(pomFile) {
def project = new XmlSlurper().parse(pomFile);
def list = []
project.dependencies.dependency.each {
def dep = new Dependency(org: it.groupId, name: it.artifactId, rev: it.version);
list << dep
}
def writer = new StringWriter();
def xml = new groovy.xml.MarkupBuilder(writer)
xml.dependencies {
list.each {d ->
dependency(org: d.org, name: d.name, rev: d.rev)
}
}
if (swing.append.selected) {
swing.output.append(writer.toString())
}else{
swing.output.text = writer.toString()
}
}
Re: [Groovy] Maven Pom to Ivy Dependencies
Things may have changed a bit in these years, but I think maven dependencies can be used directly. If for some reason you need them translated (to modify them or whatever, though I don't recommend it), they are being translated before use. Just grab them from your local %userhome%/.ivy2 (or similar) folder.
Anyway, I like the groovy example. It's a nice piece of code.