I was trying
Ant.echo("hello gant")
but I am getting this error message:
No such property: Ant for class: build
Any help would be highly appreciated.
In groovy you first need to create an instance of the AntBuilder class. The following code works:
def ant = new AntBuilder()
ant.echo("Hello world")
gant is also having "ant" injected itself
Actually in grails ant is avaiale by default.
ant.echo("hello gant")
You just need to use lower-case "a" in "ant" and run it. This should work fine.
The short answer to this question is just change Ant.echo to ant.echo or just omit "ant." and "echo" directly. It will call the ant.echo.
Another case will often cause this issue is when we define the property. Do not use property name like "ant.lib.path", "xx.xx.xx", it's not working in gant, gant will treat "lib" is the property of "ant" and "path" is property of "lib" , which is not correct, use "antLibPath" form instead.
Related
I have an ant build which contains tasks of format
build
build.foo.bar
So to add dependencies in gradle the first one is easy
build.dependsOn(...)
But the second one is interpreted as method nesting. I suspect there's a standard groovy way to do this but I haven't cracked it.
How do I reference an ant task containing periods in an build.gradle file?
project.tasks['build.foo.bar'].dependsOn(...)
should do the trick.
See Project.tasks, which returns a TaskContainer (extending TaskCollection), and TaskCollection.getAt() which, as its doc says, can be called using the [] operator.
I'd like to pass properties(-Dname=val) down to junit&java tasks from the Ant command line. The problem is the -3rd party- build file doesn't pass those properties down.
I was thinking ant.build.clonevm could help, but the manual says
Note that this has to be a system property, so it cannot be specified
on the Ant command line.
So, can I use this for the above purpose, and how? If not, any other alternatives?
Thanks for any hints.
Use the ANT_OPTS environment variable instead.
set ANT_OPTS=-Dxxx=value
xxx is your property
I am reading a file in ant and loading the properties through loadproperties. I am interested in using the value of a specific property, whose name is not known. I know that it follows a pattern because that is how I load the property.
I can echoproperties and see that it is being loaded.
But I dont know how to access its value, given that its name is actually a pattern rather that hardcoded.
How can I access this property's value to do some processing.
I hope this is clear. Please ask if I need to clarify some more.
Take a look at ant-contrib package. Its propertycopy task will do what you need. If you need to resolve an arbitrary number of properties following an established pattern, you would use ant-contrib's propertycopy in conjunction with ant-contribs "for" task.
http://ant-contrib.sourceforge.net/tasks/tasks/index.html
You should use Ant's script task.
I suggest using the beanshell script since it is pure java.
For example, to print all properties for your project, use the following:
<target name="echoprops">
<script language="beanshell">
System.out.println("All Properties: " + project.getProperties().keySet());
</script>
</target>
It should be easy to modify the above script to get the property you want.
To use this task, you will need to run the following in $ANT_HOME first:
ant -f fetch.xml script -Ddest=user
That will download all required optional jars to ~/.ant/lib .
I'm trying to use GroovyShell to evaluate some snippets of code from within a Grails application, but I don't seem to be able to access our Grails domain classes. For example when I try to evaluate something like this:
Eval.me("my.package.MyDomainClass.get(1)")
I see an error like this:
groovy.lang.MissingPropertyException: No such property: my for class: Script1
Any thoughts on how I can get this to work?
Thanks.
I figured out how to get this working. By default a GroovyShell instance clearly evaluates the script in its own classloader, so none of your Grails artefacts are available. There's an alternative constructor where you can pass in another classloader, so this does what I need within the context of a Grails application (when running inside a grails console, for example):
def shell = new GroovyShell(this.class.classLoader)
shell.evaluate("my.package.MyDomainClass.get(1)")
What's the difference between #{property} and ${property} in accessing Ant properties?
Didn't see any obvious note about it in the Ant manual.
${property} is the normal way to access properties. #{property} is used inside macro definitions to access arguments passed to this macro. See the Ant manual on macrodef.
${property} is used to reference Properties.
#{attribute} is used to reference Attributes in <macrodef> Tasks.