Reading info from existing pom.xml file using Gradle?
ant, gradle
Solution
Gradle doesn't provide native support for parsing POM files, but Groovy's XmlSlurper makes XML parsing easy and convenient. I'd probably prefer that over the Ant approach.
Problem
In Ant the Maven Ant Tasks can be used to read maven properties like this: ``` <artifact:pom id="mypom" file="pom.xml" /> <echo>The version is ${mypom.version}</echo> ``` Is there "native" support in Gradle for accessing pom elements from an existing physical pom.xml file or do I need to go through the above Ant approach in my .gradle file to make this work? This page: http://gradle.org/docs/current/userguide/maven_plugin.html has info on generating pom files but thats not what I am looking for. I have tried to create a .gradle file that does the same: ``` repositories { mavenCentral() } configurations { mavenAntTasks } dependencies { mavenAntTasks 'org.apache.maven:maven-ant-tasks:2.1.1' } task hello << { ant.taskdef(resource: 'org/apache/maven/artifact/ant/antlib.xml', uri: 'antlib:org.apache.maven.artifact.ant', classpath: configurations.mavenAntTasks.asPath) // what is the gradle syntax for this: // <artifact:pom id="mypom" file="maven-project/pom.xml" /> // its not a property or a task... def artifact = groovy.xml.NamespaceBuilder.newInstance(ant,'antlib:org.apache.maven.artifact.ant') artifact.pom(id:'mypom', file: 'pom.xml') def text = properties['mypom.version'] println "From pom file: " + text } ``` where I have a simple pom.xml file located next to the build.gradle file. But I can't find any info in the gradle docs on the corresponding ant calls for this task. I have looked at: http://www.gradle.org/docs/current/userguide/ant.html for how to read ant properties and references but this: ``` <artifact:pom id="mypom" file="maven-project/pom.xml" /> ``` seems to be neither a property or reference. I stumbled on this page: http://snipplr.com/view/4082/ where a NamespaceBuilder is used: ``` def mvn = groovy.xml.NamespaceBuilder.newInstance(ant, 'antlib:org.apache.maven.artifact.ant') ``` but when using this approach I get: ``` The AbstractTask.getDynamicObjectHelper() method has been deprecated and will be removed in the next version of Gradle. Please use the getAsDynamicObject() method instead. From pom file: null ``` after a bit of googling I found: http://issues.gradle.org/browse/GRADLE-2385 which seems related, but the value of the property is still null.