Grails 3.3, which transactional library to import? - grails

If you create a new service groovy class, and add "#Transactional" at the top, eclipse offers 3 imports:
grails.transaction.Transactional
org.springframework.transaction.annotation.Transactional
grails.gorm.transactions.Transactional
The first one is what gets created in 3.3 when you generate the static controllers, so one might assume this is the official and correct version. however, it is deprecated.
The middle one is used in some online examples.
The last one is used in this document page for grails 2.5, so may or may not still be correct.
Does anyone know which is the correct one?

grails.gorm.transactions.Transactional is GORM 6.1 I think this is Grails 3.2 + (possibly later releases of 3.2)
grails.transaction.Transactional is what i use at the moment and came out in later versions of grails 2
org.springframework.transaction.annotation.Transactional is the eldest of the lot probably not a good idea to use
In regards to the order that is all down to your IDE, meaning if you select one over another it will in the future remember that and show that to you first

With Grails 3.3 and Gorm 6.x onwards, you should use grails.gorm.transactions.Transactional -- this is replacement for the previous transactional annotations, the old annotations will eventually be removed

Related

custom codec not found in plugin

I have a grails application with multiple internally developed plugins. Since upgrading from 4.x to 5.2.3, codecs are not found in one plugin, but are found in others. Specifically, I can place the same file (UsernameListCodec.groovy, package name changed from one plugin to the next but otherwise no changes) in grails-app/utils in one plugin and it works; when placed in grails-app/utils in another plugin it fails with MissingMethodException.
What could cause this? The plugins are fairly different in terms of what they provide, but very similar in terms of how they're built, published, etc. Clearly this is something I'm doing wrong (since the codec works in another plugin) but I don't even know where to begin looking. Does a plugin need to do something in particular to be able to provide custom codecs as of grails 5?

Will there be any performance improvement if I upgrade the grails version

I have a grails app built on grails 1.3.7.
My app is pretty slow and I'm trying to figure out the hungry blocks in my code.
On the other side I'm thinking whether upgrading to latest grails version will add to the performance of my app. will that do any good for my app?
Will upgrading just the plugins keeping the grails as it is will help?
And if you know any plugins or tweaks I can add to improve its performance, please suggest.
Thank you.
Well in general you need to remember a few things.
Grails app runs over groovy, and groovy returns a java code at the end that runs on the jvm. So it will always be slower than the pure java code.
There is a vast difference between the runtime required for a java code and a groovy code. eg for loop is much efficient than each method of groovy.
Dynamic finders and the meta programming slows down a grails app even more, since all the methods and finders are created at runtime.
Grails vs Java comparision
In order to speed by your app try using #CompileStatic annotation that can speed up your app to a good extent. This will disable your dynamic finders and meta programming. So use it wisely and in classes where you do not require then. You can use it both at method level and class level. BUt to use this you need to upgrade to grails 2.0 version
Other measures you can take is to avoid using groovy functions like each etc and use java counterparts like while, for etc

grails backward compatibility

I recently get to know grails and start to using it, I know that grails is a great language and it is very helpful for rapid development, but I cant understand why grails dont have a good backward compatibility, I use grails 2.3.8 and grails 2.4 for my projects but many of sample codes in the internet are 2.2 or less, and it isn't time efficient to convert them to 2.3.8 or 2.4 because there are many changes from one version to another. And some times although I do any things right and every thing must work like it works with grails 2.1 or 2.2 but some things still remains.
Am I wrong? I skipped some things that make converting version so hard?
And above all this, what are the guaranties that projects I'm developing right now will be compatible with higher versions of grails that comes in the future?
Joshua Moore is right with his answer, but I do not see it as passimistic as he does.
The grails development team is brave enough to make changes which break with the past. I consider this as a great feature - Grails does not ride dead horses.
For me, most of the changes don't seem to bee too radical. Most of the time, I skip 2-3 version and then upgrade my apps to the current stable version in less than a day. This also helps me to get to know the new features.
If you don't know how to upgrade, the safest way is to use the grails upgrade command. Just increase you version number step by step and do an upgrade and re-run your test (yes, tests help you in your upgrade process :-). If tests fail, take a look at the great changelogs and the "What new in Grails x.y?" sections of the documentation.
Often it is also helpful to compare your old grails version app with a new and empty target version project with a good comparison tool like BeyondCompare. This way you easily spot changed configurations.
Hope that helps
Update: When you are new to "all those webconcepts" you should first decide on the platform you want to work on. If it is the java ecosystem, Grails is the best webframework on the market :-) Otherwise PHP, Rails, DJango etc. could also be a match.
So if you want to learn Grails (and with Grails all those webconcepts), I would suggest to start reading the Guide which will tell you how Grails works. If you need more examples, I can suggest the "The Definitive Guide to Grails 2" published by Apress. It covers basically the same content as the guide, but it does so by walking you through a process of building a sample application.
When it comes to the samples you find on the net... as soon as you get to know the framework better, you will probaply know ho to handle the examples - but there is no silver bullet...
Nothing guaranties that your projects will be compatible with future versions of Grails. In fact, from my own experience, they won't. Often things change, and sometimes radically too, as Grails matures into higher versions.
The same holds true of backwards compatibility as well.
All you need do is take a look at the introduction section of the Grails documentation to see how often things change significantly between versions. A lot of times these changes require significant refactoring of older projects to upgrade them. I still have several large projects running on the 1.3.x branch of Grails because we don't have the resources (time) to go through and upgrade them.
Often this upgrade process involves creating a new empty project then slowly moving the code from the old project into the new project, updating code to reflect newer means of doing the same thing and testing. It's not easy for projects where you have 100+ Domain classes, 1000+ GSPs, 50+ Services and several hundred thousand lines of tests.

Changing Grails SDK in IntelliJ IDEA Doesn't Work on Plugin Modules

IDEA 11.1.2
I have a Grails app I need to upgrade. The application consists of several modules. One being the application and a few others being plugins. I right clicked on the application and went to Grails -> Change SDK Version. I chose the version I wanted, then IDEA asked me if I wanted to upgrade the application. Clicked yes and all was good.
I've been trying to do the same thing on the plugin modules. IDEA never asks if I want to upgrade and it doesn't appear to change the SDK. If I upgrade the modules from the command line, when I come back to IDEA, it thinks there is a version mismatch and automatically downgrades me without even asking.
Is there a workaround for this?
It worked for me in this IDEA version. Make sure that you change Grails version in application.properties of all plugins:
app.grails.version=2.1.0
Then right-click on every module (plugin), Grails, Change SDK version. It should be changed already.
Have exactly same problem - app + plugins wich requires different SDK (for testing).
After some investigation found that it's an IntelliJ IDEA bug IDEA-114418. So, I think, it will be good if you'll vote for this bug there too.
I also had the same bug. I took extreme measures to rectify it.
I deleted the old grails from the Global Libraries. Go to file>Project Structure > Global Libraries . It should complain that this is used by a module.
Then I had to add grails framework support, but added the new one.

Create Grails documentation - gdoc

When I take a look at the great looking Grails Reference Documentation (http://grails.org/doc/latest/) and compare it with my lousy gdoc documentation, I wonder what makes the difference?
is it just a different style sheet?
or do they use another tool?
How do I get these great looks for my own project without having too much to do?
The easy way to get the new look is to upgrade to 2.0M1 which uses the new look and feel. Peter Ledbrook created the current 1.3.7 docs with the new approach but I'm not sure how easy it'd be to do for a regular Grails application. And there are obviously many reasons to upgrade to 2.0.
You might want to wait a day or so - we're planning on releasing M2 this week. But upgrading from M1 to M2 will be trivial. The real work will be upgrading from 1.3 to 2.0, which isn't that bad.
They use the same exact documentation building tool. It's clearly customized CSS but nothing else. You can read more about it in the reference documentation itself.
Since Grails 1.2, the documentation engine that powers the creation of this documentation is available to your Grails projects.
From the documentation itself.

Resources