How to add a comment to Gradle's eclipse task's classpath



Since the Gradle eclipse plugin creates a .classpath file with absolute paths to $HOME, I don't want people to commit it to the VCS. I already have a hook in place that will reject commits that have the text "dontCommit". I'd like to add a comment to the generated .classpath XML file.


I've tried these with no success in my eclipse.classpath.withXml closure:



def root = it.asNode()
root.children()[0].appendNode(org.w3c.dom.Node.COMMENT_NODE, "dontCommit")


This uses the COMMENT_NODE's position in the enum as the element name, e.g., <8>dontCommit</8>.



it.asString() =~ "/(<classpath>)/<classpath> <!-- dontCommit -->/"


This is ugly (working with a regex on XML) and does not work; probably the string is not mapped back to XML. (Can't blame it for that...)



root.children()[0].appendNode("<!--", "dontCommit")


This creates <<!-->dontCommit</<!-->, i.e., invalid XML.


http://ift.tt/1sDc31l says that I can use a Closure and builder style notation, but when I use the mkp prefix, I get a compiler error.



root.children()[0].plus {
mkp.comment("dontCommit")
}


gets No such property: mkp for class: org.gradle.api.internal.xml.XmlTransformer$XmlProviderImpl



root.classpathentry.add(0, {
mkp.comment("dontCommit)
})


compiles but does not seem to do anything.


How do I add that comment?


No comments:

Post a Comment