Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7676041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:06:27+00:00 2026-05-31T17:06:27+00:00

As I am trying to write a Grails Plugin, I stumbled upon two problems:

  • 0

As I am trying to write a Grails Plugin, I stumbled upon two problems:

  • how do I modify one of the configuration files like Config.groovy or DataSource.groovy from witin the _install.groovy script? It is easy to append something to those files, but how do I modify it in a clean way? text.replaceAll()? Or should I create a new config file?
  • how do I get the name of the current application into which the plugin will be installed? I tried to use app.name and appName but both do not work.

Is there maybe somewhere a good tutorial on creating plugins which I haven’t found yet?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:06:28+00:00Added an answer on May 31, 2026 at 5:06 pm

    Here is an example of editing configuration files from scripts/_Install.groovy.
    My plugin copies three files to the target directory.

    • .hgignore is used for version control,
    • DataSource.groovy replaces the default version, and
    • SecurityConfig.groovy contains extra settings.

    I prefer to edit the application’s files as little as possible, especially because I expect to change the security setup a few years down the road. I also need to use properties from a jcc-server-config.properties file which is customized for each application server in our system.

    Copying the files is easy.

    println ('* copying .hgignore ')
    ant.copy(file: "${pluginBasedir}/src/samples/.hgignore",
             todir: "${basedir}")
    println ('* copying SecurityConfig.groovy')
    ant.copy(file: "${pluginBasedir}/src/samples/SecurityConfig.groovy",
             todir: "${basedir}/grails-app/conf")
    println ('* copying DataSource.groovy')
    ant.copy(file: "${pluginBasedir}/src/samples/DataSource.groovy",
             todir: "${basedir}/grails-app/conf")
    

    The hard part is getting Grails to pick up the new configuration file. To do this, I have to edit the application’s grails-app/conf/Config.groovy. I will add two configuration files to be found on the classpath.

    println ('* Adding configuration files to grails.config.locations');
    // Add configuration files to grails.config.locations.
    def newConfigFiles = ["classpath:jcc-server-config.properties", 
                          "classpath:SecurityConfig.groovy"]
    // Get the application's Config.groovy file
    def cfg = new File("${basedir}/grails-app/conf/Config.groovy");
    def cfgText = cfg.text
    def appendedText = new StringWriter()
    appendedText.println ""
    appendedText.println ("// Added by edu-sunyjcc-addons plugin");
    // Slurp the configuration so we can look at grails.config.locations.
    def config = new ConfigSlurper().parse(cfg.toURL());
    // If it isn't defined, create it as a list.
    if (config.grails.config.locations.getClass() == groovy.util.ConfigObject) {
        appendedText.println('grails.config.locations = []');
    } else {
        // Don't add configuration files that are already on the list.
        newConfigFiles = newConfigFiles.grep {
          !config.grails.config.locations.contains(it)
        };
    }
    // Add each surviving location to the list.
    newConfigFiles.each {
        // The name will have quotes around it...
        appendedText.println "grails.config.locations << \"$it\"";
    }
    // Write the new configuration code to the end of Config.groovy.
    cfg.append(appendedText.toString());
    

    The only problem is adding SecurityConfig.groovy to the classpath. I found that you can do that by creating the following event in the plugin’s /scripts/Events.groovy.

    eventCompileEnd = {
        ant.copy(todir:classesDirPath) {
          fileset(file:"${basedir}/grails-app/conf/SecurityConfig.groovy")
        }
    }
    

    Ed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to write a chat, like on facebook, I wondered if two clients can
I am trying to send mail through grails mail plugin. I configured according to
I'm new to Grails (but not to Groovy or web development). I'm trying to
Trying to write a simple C# script to copy file to directory one level
I'm trying to expose a webservice via grails & cxf grails plugin. this is
Trying to write a trivial application, But I have stuck into one of the
I'm new to grails and trying to write unit tests for Service class has
Trying to write a piece of code to compare two strings. If either are
I'd like to write a service in my grails web app to apply an
I'm trying write a query to find records which don't have a matching record

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.