Grails 3.2.0 Bootstrap.groovy script doesn't execute - grails

After i updated my project from Grails 3.1.11 to 3.2.0 the project has stopped working.
When i start proj from IDE, it works fine. But when i pack it to jar and try to run in terminal, BootStrap.groovy does not execute.
What is the problem?

I just found an issue on GitHub. Now BootStrap.groovy and UrlMappings.groovy should be in the default package
Default package is indicated in application.yml
grails:
codegen:
defaultPackage: com.example.app
Migration docs has no information about this issue yet..

sergey Linnik's answer is correct the Bootstrap.groovy file should be in a default package, but lookout when using a IDE (in my case Intellij 2016.2.4) for refactoring the Bootstrap.groovy class from the init folder to a default package that it adds
package default //ensure the package folder is added
class BootStrap {///}
Otherwise when building the grails application it moves the Bootstrap.groovy file out of the default package again because the refactoring didn't update it. Not sure if it's an intellij bug or not..

Related

Grails 3.0 and Spring Security

I'm using Grails 3.0.1 with IntelliJ Idea and I'm trying to use Spring Security plugin on my project.
I know that old spring-seurity-core plugin is not compatible with Grails 3.0 version. Thus I've tried to follow this tutorial: http://spiesdavid.blogspot.fi/2015/03/grails-3-app-with-security-part-1.html
I've added the compile line in build.gradle file in dependencies. I've also added the logger line in logback.groovy file.
Problems start after that. There is no such file as SecurityConfiguration.groovy and there is no org.springframework.security package so I can't import them and it gives an error. So I can't create the file either.
So I am assuming that your question is: «How do I get this to work?»
spring security plugin 3.0.0 (for grails 3.x) was released just a few days ago. Documentation is quite good. Start here: https://grails-plugins.github.io/grails-spring-security-core/
There are some problems with Intellij. I tried to add spring security to a slightly older grails project (started with intellij 15.0.1 and grails 3.0.9). Adding the dependencies was successful and rebuilding it made the plugin available, also in the grails console. But when I launched a debug instance of the application directly from the IDE, it would not show spring security among the loaded/installed plugins. I made a pristine project with IntelliJ 15.02, grails 3.0.10 and just copied my code over to the new project. Now it works.
Note there are some issue with IntelliJ not major. do the following it will work:
on your build.gradle add compile 'org.grails.plugins:spring-security-core:3.0.0.M2'
run command compile
run comand s2-quickstart yourAppName User Role
now you should see "application.groovy" file under conf folder
as usual use #Secured annotation in your controller

Grails create-app name with dot

It's a little strange question, but why when I'm running next command:
grails create-app project.api
Grails 2.5.0 creates folder project.api with main package project.api, but Grails 3.0.1 creates folder api with package project and ignores provided project full name?
Try it like this:
grails create-app "project.api"
Because the dot has special meaning, used to show package hierarchy(my guess).

how to find your project current versions in grails

I want to know the versions of the software used while developing the project, Suppose If there is an existing project In grails ,so I want to know the version of grails as well as version of Groovy for that project
Metadata regarding a project in Grails is kept in application.properties.
Within this file you will find the version of Grails used for the project under the key app.grails.version.
The version of Groovy used however is not kept in this file and is determined by the version of Grails being used. To determine the version of Groovy used by a specific version of Grails visit the introduction section of the Grails documentation.
edit
As pointed out in another answer, if you have target version of Grails already downloaded you can search for the version of Groovy being used by that version of Grails.
*nix
$ cd grails-X.X.X
$ find . -name "groovy*jar"
win32
> cd grails-x.x.x
> dir /s "groovy*.jar"
From controllers/services:
def appVersion=Metadata.current.'app.grails.version'
def appName=Metadata.current.'app.name'
From gsp:
App Version <g:meta name="app.version"/>
Built with Grails <g:meta name="app.grails.version"/>
Added extra information to figure out a grails application version from raw text files :
If you have a grails 3 application, you should find a build.gradle in the main root of your application folder:
version "0.1" According to this grails 3 project the version of this application is 0.1
Grails version is 3.1.1 according to gradle.properties
On a grails 2 project you will find application.properties in the main project root:
According to this grails 2 project
grails version is 2.4.4
App version is 0.1
If you already have a project and want to learn which grails version it uses. You can find it in gradle.properties file.
The content of the file is like the following
grailsVersion=4.0.1
gorm.version=7.0.2.RELEASE
As of Grails 3, this is:
Version <g:meta name="info.app.version"/>
Notice the info.
http://docs.grails.org/3.0.17/ref/Tags/meta.html
use application.properties in the root of the grails application
To find out which version of groovy is used with particular version of grails I always use simple find:
$ cd grails-X.X.X
$ find . -name "groovy*jar"
Maybe I'm just too lazy to dig into websites... ;-)
You can see application name,grails version,application version from application.properties file of grails project
I face the same issue, I found simplest way to find version by simple command.
run
grails clean
then it prints
Welcome to Grails 1.3.7 - http://grails.org/

Unable to resolve Class for burningimage plugin in grails app

I'm running grails 2.0.4 on a mac, and installed the burningimage plugin to handle image uploads.
I have this at in my domain object:
import pl.burningice.plugins.image.ast.FileImageContainer
however, netbeans says it's unable to resolve the class, and when I call imageUploadService in my controller, I get this error
No such property: imageUploadService for class: wine.WineController
Netbeans believes the plugin is installed, and I can see the plugin source files under the project in the .grails folder. Any idea how to resolve the import?
A grails clean and recompile might help it see the class. However I get these type of import 'errors' in Netbeans but everything compiles and runs fine.
Try injecting the service in your controller:
class WineController {
def imageUploadService
...
}

How do I upgrade the Grails version for an existing application?

I have an example Grails application (from Grails in Action) that was created a while ago under version 1.1.1 on a different PC.
I am now loading Grails 1.2.0 and want to revisit the app. However, when I try to run it I get this message:
Application expects grails version [1.1.1], but GRAILS_HOME is version [1.2.0] - use the correct Grails version or run 'grails upgrade' if this Grails version is newer than the version your application expects.
After reading around a bit I cleared out the 1.2.0 folder under .grails in my home directory (from previous attempts while exploring the issue), ran "grails clean" and "grails upgrade" (answering "y" where prompted).
However, I consistently get "Invalid duplicate class definition" conflicts between classes in \grails\qotd\src\java and \grails\qotd\grails-app{controllers,services,conf}.
Are there any additional manual steps that I need to perform?
I understood your problem.
The solution is just modify the grails vesion to 1.2.0 in application.properties file in your application
If, as you pointed out in the comments, your /src/java contains .groovy files - that could definitely cause unexpected behavior. I haven't hit your particular issue, but any time I had a .groovy file mismatched with the class name inside it, I'd get strange compilation issues - so I guess you could be having a similar issue.
If you have files / classes with the same names in two locations, that's the likely culprit. If you have .groovy files in /src/java, that's another potential source.
Also, putting BootStrap, Config, DataSource and URLMappings into /src/java, that's another potential source of issues. I'd clear out your /src/java by making sure all the files are in their appropriate places under grails-app.
You can upgrade grails version with 5 steps
Project -> Clean
application.properties -> Change app.grails.version
Your project -> Properties -> Grails -> Change grails installation
to new grails version.
Your project -> Grails tools -> Refresh Dependencies
I think this may be help you

Resources