Grails default package name
Asked Answered
M

1

6

I am new to Grails and I like it very much. I want to place my classes in packages like org.company.project.module.model. Its quite painful for to me to repeat create-domain-class <package>.<class_name>. Is there something like "package templates" or can I somehow "enter" (like grails cd org.comopany...) and then just write Class names (grails Person will be generated in ./ location)? Is that possible or should I use copy paste design pattern? Thanks in advance for any help.

Menagerie answered 21/11, 2013 at 2:58 Comment(0)
K
20

If I understood your question, you are looking for default package name for your domain classes. In your config.groovy file there is a line saying:

grails.project.groupId = appName

if you give it an appName, Grails will use that as the default package name when it generates the artifacts.

grails.project.groupId = 'com.example.yourpackagename'

If you now create a domain class by default it will locate it under com/example/yourpackagename.

UPDATE

It is not required to use Grails commands like create-domain-class or other commands to create artifacts. These are all just classes that you can manually create. Just create a file and duplicate it in the same package.

UPDATE

Grails interactive mode (when you type grails) for some of the commands by pressing tab it will type ahead the unique portion of the package name.

UPDATE for Grails 3.0

The setting has moved into conf/application.yml:

grails:
   profile: web
   codegen:
      defaultPackage: com.example.yourpackagename
Kuehnel answered 21/11, 2013 at 3:11 Comment(2)
Thanks for answer anyway when I want to put my controller into 'com.example.mypackagename.controllers' I have to write whole package. The command will place it in the groupId location, won't it?Menagerie
That is correct, there will be some work, things might be easier with a IDE though.Kuehnel

© 2022 - 2024 — McMap. All rights reserved.