How to create a CLI script for code generation, like what "grails create-controller" does - grails

I would like to create a command line tool to generate some java source code...e.g., a controller class, service class, and a DTO class. I've been trying to find the scripts for CreateController.groovy (from grails), but I've had no luck finding that script. Any help would be much appreciated. I think it might be done with Gant?

I've been trying to find the scripts for CreateController.groovy
(from grails), but I've had no luck finding that script.
You haven't indicated what version of Grails you want to use and that may be relevant. For recent versions of Grails there is not a CreateController.groovy but the create-controller command is defined at https://github.com/grails/grails-profile-repository/blob/master/profiles/web/commands/create-controller.yml.
I think it might be done with Gant?
Not since Grails 2. If you are using Grails 1 or 2, then a Gant script might be what you are looking for. For Grails 2.5.6, the command is defined at https://github.com/grails/grails-core/blob/bd7cc10e17d34f20cedce979724f0e3bacd4cdb4/grails-scripts/src/main/scripts/CreateController.groovy.

Related

Junit5 with ant

I am new in ant and junit5. I went through several examples ant/junit4. But I did not find a normal example with a pair of ant with junit5. With a pair of ant with junit4 everything works fine. I downloaded the files from the official site of the junit5 https://junit.org/junit5/docs/current/user-guide/ (For Ant, check out the junit5-jupiter-starter-ant project.), but even they give an error at the very beginning(screen attached) I will try to fix them one by one, but I don't think that official repo committed with errors. Maybe I'm doing something wrong. Or maybe gurus suggest some other simple sample with ant/junit5.
Thank you in advance.
I try to run the original sources from https://github.com/junit-team/junit5-samples and expected to at least compile them. But I get plenty of errors.
So this post has 2 questions:
errors on the screenshot
ant+juni5 integration in general
To reproduce the exact issues one should have the same environment, which is at least the OS, Java version & Ant version. The example itself seems to be using the Junit5 ConsoleLauncher, which is one of the way to run the tests. Looking at the errors it looks like the issue is in the project itself, because if it cannot find the 'symbol' #Test then the Junit(5?) is simply not present on the classpath. Maybe this can be a hint to the author to trty to dig a bit more into the issue, particularly looking into the dependencies (jars) included.
Now going back to how to run Junit5 test with Ant, I can recall the "JUnitLauncher" that apache suggests: https://ant.apache.org/manual/Tasks/junitlauncher.html . Note that you should be attentive on the dependencies here as well, there are number of Jars to be included (opentest4j, junit-platform-xyz). Note that this also depends on the installation of Ant in the environment, so for example if you get a NoClassDefFound for JUnitLauncher, this can be solved by using the 'up-to-date' version of Ant: https://ant.apache.org/bindownload.cgi . In case of Linux you can place these Jars in home/your_username/.ant/lib directory, where it will be automatically picked up.

Intellij does not show autocompletion for groovy methods

So, i have intllij 2016.1.3 (professional)
I imported an existing grails 2.5 project, created a grails 2.5 library by pointing to grails installation. Every thing seem to work, other then the suggestions for groovy methods (eg default groovy methods collect, find, sort, eachWithIndex etc). Intellij does not show suggestions for this groovy methods, and does not even recognize it, even if i manually write the method name. Surprizingly it shows suggestions for collectParallel, eachParallel.
Tried setting up a groovy library, used groovy-eclipse compiler, but not luck.
What could be going wrong?
The solution was to remove dslActivationStatus.xml from ~/Library/Preferences/<IntellijVersion>/options/ (OSX El capitan)
This was suggested by intellij support team after investigating it for few days.

Is it possible to user One-Jar without IDE?

I'm trying to find a tutorial on how to use One-Jar without eclipse, with no success. Is it possible? I have my classes and commons-io.24.jar that needs to be inside, and I am compiling in command line.
Thanks!
If you use Maven, this plugin can be used to invoke one-JAR during the build lifecycle.

Create Debian package using Apache Ant

Is there anywhere that can give you a tutorial or anything on creating a Debian package using Ant?
I'm being told its already a part of Ant but I've never seen any functions even remotely associated with it.
I don't want to use ant-deb-task either seeing as its not actually part of Ant.
There is no task for this in the core Ant distribution.
There are examples for ant-deb-task available in the examples file on the download page.
Another option is jdeb which also provides documentation.

Command to change package name in Grails

I have created my application under package music. Now I want to change my package to com.mp3.songs.music.
One way is I can manually create the package for grails-app. Is there anything else that I need to take care while changing the package name.
Alternatively, is there a command in grails which can be used to change the package.
I found a way out in the below link. But this works only when you create new files. What if you want to change the package of the older files.
http://www.goto20.nl/tech/groovy/configuring-the-default-package-name-for-a-grails-project/
Thanks!
IntelliJ IDEA has very good support for rename refactoring. I believe it is currently the best (9.0.3 stable) chance you'll have of any major refactoring jobs in Grails. They have a 30 day trial, so it is worth a try.
Why not use Spring Source Tool Suite. Its a great IDE with solid support for Groovy n Grails.

Resources