### Start MongoDB Server Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-mongodb/docs/src/docs/asciidoc/gettingStarted.adoc This command starts a MongoDB instance. Ensure MongoDB is installed and its bin directory is in your PATH. ```groovy MONGO_HOME/bin/mongod ``` -------------------------------- ### JUnit Setup and Test Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/testing/junit.adoc Demonstrates how to set up HibernateDatastore for testing using JUnit's @BeforeClass and @AfterClass annotations, and includes a basic @Test method. Remember to manually close the HibernateDatastore as JUnit lacks automatic cleanup. ```groovy import org.junit.* import grails.gorm.transactions.* import org.grails.orm.hibernate.HibernateDatastore import org.springframework.transaction.PlatformTransactionManager class ExampleTest { static HibernateDatastore hibernateDatastore PlatformTransactionManager transactionManager @BeforeClass void setupGorm() { hibernateDatastore = new HibernateDatastore(Person) } @AfterClass void shutdownGorm() { hibernateDatastore.close() } @Before void setup() { transactionManager = hibernateDatastore.getTransactionManager() } @Rollback @Test void testSomething() { // your logic here } } ``` -------------------------------- ### Generic GORM Enhancer Setup Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-developer/src/main/docs/understandingApi/gormEnhancer.adoc Example of using the standard GormEnhancer when no datastore-specific extensions are needed. ```groovy def enhancer = new GormEnhancer(mongoDatastore, new DatastoreTransactionManager(datastore: mongoDatastore)) enhancer.enhance() ``` -------------------------------- ### Help Output Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/commandLine.adoc Example of the output from the 'grails help' command, showing command syntax and available commands. ```bash grails <>* <> <>* | Examples: $ grails dev run-app $ grails create-app books | Available Commands (type grails help 'command-name' for more info): | Command Name Command Description ---------------------------------------------------------------------------------------------------- clean Cleans a Grails application's compiled sources compile Compiles a Grails application ... ``` -------------------------------- ### Example Controller for createLink Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/createLink.adoc This is an example controller for an application named 'shop' that demonstrates actions like 'list' and 'show'. ```groovy class BookController { static defaultAction = "list" def list() { [books: Book.list(params)] } def show() { [book: Book.get(params.id)] } } ``` -------------------------------- ### Complete MongoDB Configuration Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-mongodb/docs/src/docs/asciidoc/gettingStarted/advancedConfig.adoc An example demonstrating all available MongoDB configuration options, including connection details, options, and connection URL. ```groovy grails { mongodb { databaseName = "myDb" // the default database name host = "localhost" // the host to connect to port = 27017 // the port to connect to username = ".." // the username to connect with password = ".." // the password to connect with stateless = false // whether to use stateless sessions by default // Alternatively, using 'url' // url = "mongodb://localhost/mydb" options { connectionsPerHost = 10 // The maximum number of connections allowed per host threadsAllowedToBlockForConnectionMultiplier = 5 maxWaitTime = 120000 // Max wait time of a blocking thread for a connection. connectTimeout = 0 // The connect timeout in milliseconds. 0 == infinite socketTimeout = 0 // The socket timeout. 0 == infinite socketKeepAlive = false // Whether or not to have socket keep alive turned on writeConcern = new com.mongodb.WriteConcern(0, 0, false) // Specifies the number of servers to wait for on the write operation, and exception raising behavior sslEnabled = false // Specifies if the driver should use an SSL connection to Mongo socketFactory = ... // Specifies the SocketFactory to use for creating connections } } } ``` -------------------------------- ### Example Controller for Shop Application Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/form.adoc This is an example Groovy controller for a 'shop' application, demonstrating methods for listing and showing books. ```groovy class Book { def list() { [books: Book.list(params)] } def show() { [book: Book.get(params.id)] } } ``` -------------------------------- ### Initialize Schema and Get DataBinderManager (Standalone) Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-graphql/docs/src/main/docs/guide/dataBinders.adoc In a standalone setup, initialize the schema first to set the default binder manager. Then, retrieve the manager instance. ```groovy import org.grails.gorm.graphql.Schema Schema schema = ... schema.initialize() GraphQLDataBinderManager dataBinderManager = schema.dataBinderManager ... schema.generate() ``` -------------------------------- ### Running Spring Security Quickstart with Gradle Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/gettingStarted/downloadingAndInstalling.adoc This command runs the Spring Security quickstart script via Gradle, generating necessary files for user and role management. ```bash ./gradlew runCommand -Pargs="s2-quickstart com.yourapp User Role" ``` -------------------------------- ### Initialize Schema and Get Manager (Standalone) Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-graphql/docs/src/main/docs/guide/dataFetchers.adoc In a standalone setup, initialize the schema first to set the default fetcher manager. Access the manager via the schema object after initialization. ```groovy import org.grails.gorm.graphql.Schema Schema schema = ... schema.initialize() GraphQLDataFetcherManager dataFetcherManager = schema.dataFetcherManager ... schema.generate() ``` -------------------------------- ### Example of Setting Application Context Path with Gradle Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/gettingStarted/aHelloWorldExample.adoc An example demonstrating how to set the context path to '/myapp' when running a Grails application with Gradle. ```console $ ./gradlew bootRun -Dgrails.server.servlet.context-path=/myapp ``` -------------------------------- ### Install Grails Version with SDKMAN! Source: https://github.com/apache/grails-core/blob/7.0.x/README.md Installs a specific version of Grails using SDKMAN!. Assumes SDKMAN! is already installed. ```bash sdk install grails 7.0.0-M4 ``` -------------------------------- ### Configure TCK Test Setup Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-developer/src/main/docs/stepByStep.adoc Implement the `Setup` class in `src/test/groovy` to configure the Test Compatibility Kit (TCK) for your GORM implementation. ```groovy class Setup { static xyz static destroy() { xyz.disconnect() } static Session setup(classes) { def ctx = new GenericApplicationContext() ctx.refresh() xyz = new XyzDatastore(ctx) for (cls in classes) { xyz.mappingContext.addPersistentEntity(cls) } def enhancer = new GormEnhancer(xyz, new DatastoreTransactionManager(datastore: xyz)) enhancer.enhance() xyz.mappingContext.addMappingContextListener({ e -> enhancer.enhance e } as MappingContext.Listener) xyz.applicationContext.addApplicationListener new DomainEventListener(xyz) xyz.applicationContext.addApplicationListener new AutoTimestampEventListener(xyz) xyz.connect() } } ``` -------------------------------- ### Integration Test with Setup Method (Data Persistence) Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/testing/integrationTesting.adoc Demonstrates how data saved in the `setup()` method persists because it runs in a separate transaction that is not rolled back. This requires manual cleanup if data is not intended to persist across tests. ```groovy import grails.testing.mixin.integration.Integration import grails.gorm.transactions.* import spock.lang.* @Integration @Rollback class BookSpec extends Specification { void setup() { // Below line would persist and not roll back new Book(name: 'Grails in Action').save(flush: true) } void "test something"() { expect: Book.count() == 1 } } ``` -------------------------------- ### Custom Display Template Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/theWebLayer/fields/fieldsUsage.adoc Example of a _display.gsp template for rendering values in a definition list. ```groovy
${label}
${value}
``` -------------------------------- ### Setup for UrlMappingsUnitTest Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/testing/unitTesting/unitTestingUrlMappings.adoc Implement UrlMappingsUnitTest and mock controllers for testing URL mappings. ```groovy package demo import grails.testing.web.UrlMappingsUnitTest class UrlMappingsSpec extends UrlMappingsUnitTest { def setup() { mockController(HelloController) } void "test basic url mappings"() { expect: withRequest(uri: "/hello") { controllerName == 'hello' actionName == 'index' } } } ``` -------------------------------- ### Example profile.yml Configuration Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/profiles/creatingProfiles.adoc Customize profile dependencies, plugins, and features by editing the `profile.yml` file. This example shows how to include default features, specify build plugins, exclude certain plugins, and add custom dependencies. ```yaml features: defaults: - hibernate - asset-pipeline build: plugins: - org.apache.grails.gradle.grails-web excludes: - org.grails.grails-core dependencies: - scope: compile coords: "org.mycompany:myplugin:1.0.1" - scope: testCompile coords: org.spockframework:spock-core excludes: - group: org.codehaus.groovy module: groovy-all ``` -------------------------------- ### Project Documentation Directory Structure Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/conf/docengine.adoc Example of the directory structure for documentation source files. ```groovy + src/docs/guide/introduction.gdoc + src/docs/guide/introduction/changes.gdoc + src/docs/guide/gettingStarted.gdoc + src/docs/guide/configuration.gdoc + src/docs/guide/configuration/build.gdoc + src/docs/guide/configuration/build/controllers.gdoc ``` -------------------------------- ### Codec Configuration Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/security/xssPrevention.adoc Example of configuring codecs in `application.groovy`. This sets expression and scriptlet codecs to 'html' and taglib to 'none'. ```groovy codecs { expression = 'html' // escapes values inside ${} scriptlet = 'html' // escapes output from scriptlets in GSPs taglib = 'none' // escapes output from taglibs ``` -------------------------------- ### Start Grails Application with Gradle Wrapper Source: https://github.com/apache/grails-core/blob/7.0.x/README.md Starts your Apache Grails application using the Gradle Wrapper. ```bash ./gradlew bootRun ``` -------------------------------- ### findAllBy* Examples with Pagination and Sorting Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/findAllBy.adoc Demonstrates using findAllBy* with pagination and sorting parameters. ```groovy def results = Book.findAllByTitle("The Shining", [max: 10, sort: "title", order: "desc", offset: 100]) ``` -------------------------------- ### MongoDB Server Output Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-mongodb/docs/src/docs/asciidoc/gettingStarted.adoc Example output indicating a MongoDB server is running and listening on port 27017. ```groovy 2015-11-18T19:38:50.073+0100 I JOURNAL <> journal dir=/data/db/journal 2015-11-18T19:38:50.073+0100 I JOURNAL <> recover : no journal files present, no recovery needed 2015-11-18T19:38:50.090+0100 I JOURNAL <> Durability thread started 2015-11-18T19:38:50.090+0100 I JOURNAL <> Journal writer thread started 2015-11-18T19:38:50.090+0100 I CONTROL <> MongoDB starting : pid=52540 port=27017 dbpath=/data/db 64-bit host=Graemes-iMac.local 2015-11-18T19:38:50.090+0100 I CONTROL <> ** WARNING: You are running this process as the root user, which is not recommended. 2015-11-18T19:38:50.090+0100 I CONTROL <> 2015-11-18T19:38:50.090+0100 I CONTROL <> 2015-11-18T19:38:50.090+0100 I CONTROL <> ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 2015-11-18T19:38:50.090+0100 I CONTROL <> db version v3.0.4 2015-11-18T19:38:50.090+0100 I CONTROL <> git version: 0481c958daeb2969800511e7475dc66986fa9ed5 2015-11-18T19:38:50.090+0100 I CONTROL <> build info: Darwin mci-osx108-11.build.10gen.cc 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49 2015-11-18T19:38:50.090+0100 I CONTROL <> allocator: system 2015-11-18T19:38:50.090+0100 I CONTROL <> options: {} 2015-11-18T19:38:50.176+0100 I NETWORK <> waiting for connections on port 27017 ``` -------------------------------- ### Grails Build Command: Install Docker/Podman Source: https://github.com/apache/grails-core/blob/7.0.x/CLAUDE.md Instruction to install Docker or Podman if a container is missing, often required for certain build or test environments. ```bash Use -PskipTests or install Docker/Podman ``` -------------------------------- ### Getting Help Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/commandLine.adoc Displays usage instructions and a list of available Grails commands. ```bash grails help ``` -------------------------------- ### Example JSON Output Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/theWebLayer/controllers/jsonResponses.adoc This is an example of the JSON output generated by the `respond Book.list()` call when the client requests JSON. ```json [ {id:1,"title":"The Stand"}, {id:2,"title":"Shining"} ] ``` -------------------------------- ### Groovy Configuration Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/spring/propertyPlaceholderConfiguration.adoc Define database connection properties in `application.groovy` for use as placeholders. ```groovy database.driver="com.mysql.jdbc.Driver" database.dbname="mysql:mydb" ``` -------------------------------- ### Example of a generated ApplicationCommand Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/create-command.adoc This is an example of the Groovy class generated by `create-command`. It implements `ApplicationCommand` and can access application beans like `DataSource`. ```groovy import grails.dev.commands.* class MyExampleCommand implements ApplicationCommand { boolean handle(ExecutionContext ctx) { def dataSource = applicationContext.getBean(DataSource) return true } } ``` -------------------------------- ### Install Profile Locally Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/profiles/creatingProfiles.adoc After configuring `profile.yml`, publish the profile to your local Maven repository using the `gradle install` command. This makes the profile available for use in new applications. ```bash $ gradle install ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/spring/propertyPlaceholderConfiguration.adoc Define database connection properties in `application.yml` for use as placeholders. ```yaml database: driver: "com.mysql.jdbc.Driver" dbname: "mysql:mydb" ``` -------------------------------- ### Create Project Source Directories Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-developer/src/main/docs/stepByStep.adoc Set up the main and test source directories for your GORM implementation. ```bash mkdir grails-datastore-gorm-xyz/src/main/groovy mkdir grails-datastore-gorm-xyz/src/test/groovy ``` -------------------------------- ### Basic Spock Unit Test Setup with HibernateDatastore Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/testing/spock.adoc This snippet shows the fundamental setup for a Spock unit test using HibernateDatastore. It includes necessary imports and the basic structure for initializing the datastore and defining a test method. ```groovy import spock.lang.* import grails.gorm.annotation.Entity import org.grails.orm.hibernate.HibernateDatastore class ExampleSpec extends Specification { @Shared @AutoCleanup HibernateDatastore hibernateDatastore void setupSpec() { hibernateDatastore = new HibernateDatastore(Person) } void "test something"() { // your logic here } } @Entity class Person { ... } ``` -------------------------------- ### Basic GET Request with HttpClientSupport Source: https://github.com/apache/grails-core/blob/7.0.x/grails-testing-support-http-client/README.md In Grails integration tests, implement the `HttpClientSupport` trait to make HTTP requests. This example shows a basic GET request to a '/health' endpoint and asserts that the response contains a 200 status code and 'UP' text. ```groovy import grails.testing.mixin.integration.Integration import org.springframework.beans.factory.annotation.Autowired import spock.lang.Specification import org.apache.grails.testing.http.client.HttpClientSupport @Integration class HealthSpec extends Specification implements HttpClientSupport { void 'health endpoint responds OK'() { expect: http('/health').expectContains(200, 'UP') } } ``` -------------------------------- ### Example Migration Callbacks Class Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/databaseMigration/generalUsage.adoc An example Groovy class demonstrating how to implement callback methods for database migration events. These methods can be used to perform actions before, during, or after migrations. ```groovy package com.mycompany.myapp import liquibase.Liquibase import liquibase.database.Database class MigrationCallbacks { void beforeStartMigration(Database Database) { ... } void onStartMigration(Database database, Liquibase liquibase, String changelogName) { ... } void afterMigrations(Database Database) { ... } } ``` -------------------------------- ### Custom Datastore Setup Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-developer/src/main/docs/testing.adoc Implement a Setup.groovy file to initialize your custom datastore and enhance GORM entities. This is essential for running TCK tests against your implementation. ```groovy class Setup { static destroy() { // noop } static Session setup(classes) { def ctx = new GenericApplicationContext() ctx.refresh() def simple = new SimpleMapDatastore(ctx) ... for (cls in classes) { simple.mappingContext.addPersistentEntity(cls) } ... def enhancer = new GormEnhancer(simple, new DatastoreTransactionManager(datastore: simple)) enhancer.enhance() simple.mappingContext.addMappingContextListener({ e -> enhancer.enhance e } as MappingContext.Listener) simple.applicationContext.addApplicationListener new DomainEventListener(simple) simple.applicationContext.addApplicationListener new AutoTimestampEventListener(simple) return simple.connect() } } ``` -------------------------------- ### Get Help for 'create-app' Command using --help Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/help.adoc Retrieves detailed help information for the 'create-app' command. ```shell grails create-app --help ``` -------------------------------- ### Start Grails Console with Environment Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/console.adoc Starts the Grails console, allowing specification of the Grails environment (e.g., 'prod', 'dev'). The console provides access to 'ctx' (ApplicationContext) and 'grailsApplication' variables. ```bash grails <>* console ``` -------------------------------- ### Grails MongoDB Domain Class Setup for Geospatial Queries Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-mongodb/docs/src/docs/asciidoc/ref/Domain Classes/findByGeoIntersects.adoc Defines a Grails domain class with a 'shape' property indexed for 2dsphere geospatial queries. Includes examples of creating and saving different shape types (Polygon, LineString, Point). ```groovy import grails.mongodb.geo.* import org.bson.types.ObjectId class Entry { ObjectId id Shape shape static mapping = { shape geoIndex:'2dsphere' } } new Entry(shape: Polygon.valueOf([[[3, 1], [1, 2], [5, 6], [9, 2], [4, 3], [3, 1]]]) ).save() new Entry(shape: LineString.valueOf([[5, 2], [7, 3], [7, 5], [9, 4]]) ).save() new Entry(shape: Point.valueOf([5, 2])).save() ``` -------------------------------- ### Per Environment Bootstrapping Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/conf/environments.adoc Illustrates how to execute specific code during application startup based on the current environment within BootStrap.groovy. ```groovy ServletContext servletContext def init = { environments { production { servletContext.setAttribute("env", "prod") } development { servletContext.setAttribute("env", "dev") } } servletContext.setAttribute("foo", "bar") } ``` -------------------------------- ### Basic Merge Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/merge.adoc Demonstrates the basic usage of the `merge` method on a domain class instance. ```groovy def b = new Book(title: "The Shining") b = b.merge() ``` -------------------------------- ### Find All by Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/findAll.adoc Finds instances that match the properties of a given domain class instance. ```groovy def example = new Book(author: "Dan Brown") Book.findAll(example) ``` -------------------------------- ### Install Latest Grails with SDKMAN Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/gettingStarted/downloadingAndInstalling.adoc Use the `sdk install grails` command to install the latest version of Grails via SDKMAN. ```console $ sdk install grails ``` -------------------------------- ### Run Custom Gradle Task Source: https://github.com/apache/grails-core/blob/7.0.x/DEVELOPMENT.md Custom Gradle tasks like 'publishGuide' can be executed directly from the command line. ```bash ./gradlew publishGuide ``` -------------------------------- ### Decorated Page Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/pageProperty.adoc An example of a GSP page that defines layout and script information. ```html Page to be decorated ``` -------------------------------- ### HTML and URL Encoding/Decoding Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Plug-ins/codecs.adoc Demonstrates how to encode and decode HTML and URL data using the registered codecs. This example shows the usage of encodeAsHTML and decodeHTML methods. ```groovy class HTMLCodec { static encode = { theTarget -> HtmlUtils.htmlEscape(theTarget.toString()) } static decode = { theTarget -> HtmlUtils.htmlUnescape(theTarget.toString()) } } assert "<p>Hello World!</p>" == "

Hello World!

".encodeAsHTML() assert "

Hello World!

" == "<p>Hello World!</p>".decodeHTML() ``` -------------------------------- ### Example XML Output Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/theWebLayer/controllers/xmlAndJSON.adoc This is an example of the XML output generated by the preceding Groovy code. ```xml ``` -------------------------------- ### Example Usage of Script with Arguments and Flags Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/commandLine/creatingCustomScripts.adoc Demonstrates how a script with defined arguments and flags can be invoked from the command line. ```bash grails generate-all MyClass --force ``` -------------------------------- ### Example of Malicious Input Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/security/xssPrevention.adoc This is an example of script code that could be used in an XSS attack. ```groovy ``` -------------------------------- ### Verify Grails Installation Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/gettingStarted/downloadingAndInstalling.adoc After installation, verify that Grails is working correctly by checking its version in the terminal. ```console Grails Version: {version} ``` -------------------------------- ### Groovy ConfigSlurper Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/conf/config.adoc Example of using ConfigSlurper with environment variables in a Groovy configuration file. ```groovy my.tmp.dir = "${userHome}/.grails/tmp" ``` -------------------------------- ### XML Request Body Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/REST/binding.adoc This is an example of an XML request body that can be bound to a Grails object. ```xml The Stand Stephen King ``` -------------------------------- ### Grails CLI Help Output Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/help.adoc Example output when requesting general help for the Grails CLI. ```console grails> --help Usage: grails [-hvVx] [COMMAND] Grails CLI command line interface for generating projects and services. Application generation commands are: * create-app NAME * create-webapp NAME * create-restapi NAME * create-plugin NAME * create-web-plugin NAME Options: -h, --help Show this help message and exit. -v, --verbose Create verbose output. -V, --version Print version information and exit. -x, --stacktrace Show full stack trace when exceptions occur. Commands: create-app Creates an application create-webapp Creates an application create-plugin Creates an Grails Plugin create-web-plugin Creates an Grails Web Plugin create-restapi Creates an REST API ``` -------------------------------- ### Start Grails Shell Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/shell.adoc Starts an instance of the Groovy terminal shell with an initialized Grails runtime. ```bash grails shell ``` -------------------------------- ### Setting up Test Data in setupSpec with withTransaction Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/testing/spock.adoc Illustrates how to initialize shared test data within the setupSpec method using the withTransaction block for atomic operations. ```groovy void setupSpec() { hibernateDatastore = new HibernateDatastore(Person) ... Person.withTransaction { new Person(firstName:"Fred").save() } } ``` -------------------------------- ### Configure HA Neo4j Setup Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-neo4j/docs/src/docs/asciidoc/gettingStarted/advancedConfiguration.adoc Configure a High Availability (HA) Neo4j setup. Requires specifying server ID and coordinator addresses. Note: HA setup may require a commercial Neo4j license or AGPL. ```groovy grails { neo4j { type = "ha" location = "/var/neo4j" options = [ 'ha.server_id': 1, 'ha.coordinators': 'localhost:2181,localhost:2182,localhost:2183' ] } } ``` -------------------------------- ### Domain Classes for Fetching Examples Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/advancedGORMFeatures/ormdsl/fetchingDSL.adoc Defines simple domain classes used in fetching strategy examples. ```java class Address { String street String postCode } ``` ```java class Pet { String name } ``` ```java class Person { String firstName } ``` ```java class Pet { String name } ``` ```java class Dog extends Pet { } ``` ```java class Person { String name Pet pet } ``` -------------------------------- ### Help for 'create-app' Command with Forge Options Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/help.adoc Shows detailed help for the 'create-app' command, including Forge-specific options. ```shell grails> create-app --help Usage: grails create-app [-hivVx] [--list-features] [-g=GORM Implementation] [--jdk=] [-s=Servlet Implementation] [-t=TEST] [-f=FEATURE[,FEATURE...]]... [NAME] Creates an application [NAME] The name of the application to create. -f, --features=FEATURE[,FEATURE...] The features to use. Possible values: h2, scaffolding, gorm-hibernate5, spring-boot-starter-jetty, spring-boot-starter-tomcat, micronaut-http-client, cache-ehcache, hibernate-validator, postgres, mysql, cache, database-migration, grails-gsp, hamcrest, gorm-mongodb, assertj, mockito, spring-boot-starter-undertow, github-workflow-java-ci, jrebel, testcontainers, sqlserver, grails-console, views-markup, asset-pipeline-grails, views-json, gorm-neo4j, asciidoctor, grails-web-console, logbackGroovy, mongo-sync, shade, geb, properties -g, --gorm=GORM Implementation Which GORM Implementation to configure. Possible values: hibernate, mongodb, neo4j. -h, --help Show this help message and exit. ``` -------------------------------- ### Create and Find Restaurant by Point Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-mongodb/docs/src/docs/asciidoc/querying/geoSpatial/2dsphere.adoc Demonstrates creating a `Restaurant` instance with a `Point` location and performing a basic find operation. ```groovy Restaurant r = new Restaurant(location: new Point(50, 50)) r.id = "Dan's Burgers" r.save(flush:true) Restaurant.findByLocation(new Point(50,50)) ``` -------------------------------- ### RxGORM Dynamic Finder Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-rx/src/main/docs/querying/dynamicFinders.adoc Demonstrates a basic dynamic finder for Books by a specific author. The result is an Observable that emits a single Book instance. ```groovy Book.findByAuthor("Stephen King") .subscribe { Book book -> println "Title = ${book.title}" } ``` -------------------------------- ### Create a controller with a package and name Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/create-controller.adoc Generates a controller named 'Book' within the 'org.bookstore.book' package, creating necessary directories. ```bash grails create-controller org.bookstore.book ``` -------------------------------- ### MongoEntityPersister Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-developer/src/main/docs/understandingApi/implementingCrud.adoc Example of a MongoDB implementation extending NativeEntryEntityPersister, specifying DBObject for native entries and Object for keys. ```java public class MongoEntityPersister extends NativeEntryEntityPersister ``` -------------------------------- ### Linking: Internal Section Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/conf/docengine.adoc Link to other sections within the user guide using the 'guide:' prefix and the section name. ```groovy <> ``` -------------------------------- ### Install Local Grails Development Version with SDKMAN Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/contributing/build.adoc Use SDKMAN to install a custom Grails version from a local build. ```bash sdk install grails dev /path/to/extracted/files ``` -------------------------------- ### Example Grails Service Class Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Plug-ins/services.adoc An example of a service class located in the grails-app/services directory. This service retrieves a list of books. ```groovy class BookService { Book[] getBooks() { Book.list() as Book[] } } ``` -------------------------------- ### Set Up Grails Environment with SDKMAN! Source: https://github.com/apache/grails-core/blob/7.0.x/CONTRIBUTING.md Use SDKMAN! to set up the correct JDK version for the Grails project. Navigate to the project directory and run 'sdk env .'. ```bash sdk env . ``` -------------------------------- ### Eq Criterion Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/createCriteria.adoc Example of using the 'eq' criterion to filter results where a property exactly matches a given value. ```groovy eq("branch", "London") ``` -------------------------------- ### Initialize RxMongoDatastoreClient Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-docs/guide-rx/src/main/docs/gettingStarted/firstSteps.adoc This code snippet shows how to initialize the RxMongoDatastoreClient in your application's bootstrap path. It requires a MongoClient instance, a database name, and RxEntity classes. ```groovy import org.grails.datastore.rx.mongodb.* import com.mongodb.rx.client.MongoClient ... MongoClient mongoClient = ... // create the MongoClient new RxMongoDatastoreClient( mongoClient, // <1> "myDatabase", // <2> MyClass // <3> ) ``` -------------------------------- ### Setup Graph Data for Path Queries Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-neo4j/docs/src/docs/asciidoc/querying/paths.adoc This snippet sets up sample data to create a friend graph, which is used for demonstrating path-finding operations. It defines relationships between 'Person' entities. ```groovy def alice = new Person(name: 'Alice') def bob = new Person(name: 'Bob') def charlie = new Person(name: 'Charlie') def david = new Person(name: 'David') alice.addToFriends(bob) alice.addToFriends(charlie) bob.addToFriends(charlie) charlie.addToFriends(david) [alice, bob, charlie, david] ``` -------------------------------- ### Navigate to Application Directory Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/gettingStarted/creatingAnApplication.adoc After creating the application, change your current directory to the newly created project folder to begin development. ```console $ cd myapp ``` -------------------------------- ### Example Atom Feed XML Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/REST/hypermedia/atom.adoc This is an example of an Atom feed in XML format, demonstrating the structure for syndicating web content. ```xml Example Feed 2003-12-13T18:30:02Z John Doe urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6 Atom-Powered Robots Run Amok urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a 2003-12-13T18:30:02Z Some text. ``` -------------------------------- ### Between Criterion Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/createCriteria.adoc Example of using the 'between' criterion to filter results where a property's value falls within a specified range. ```groovy between("balance", 500, 1000) ``` -------------------------------- ### Run Greet Command with Argument Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc Executes the 'greet' command, passing 'Alice' as an argument to personalize the greeting. ```bash ./gradlew runCommand -Pargs="greet Alice" ``` -------------------------------- ### Demo Controller for Basic Rendering Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/testing/unitTesting/unitTestingControllers.adoc A simple Grails controller that demonstrates rendering a 'Hello World' message. ```groovy package demo class DemoController { def index() { render(view: 'index') } def renderHello() { render(text: 'Hello World!') } } ``` -------------------------------- ### Example JSON Output from render Method Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/theWebLayer/controllers/jsonResponses.adoc This is an example of the JSON output generated by the `render` method when used for simple JSON responses. ```json [ {"title":"The Stand"}, {"title":"Shining"} ] ``` -------------------------------- ### Example Controller for 'shop' Application Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/include.adoc This Groovy code defines a simple controller with 'list' and 'show' actions, which can be targeted by the `g:include` tag. ```groovy class BookController { def list() { [books: Book.list(params)] } def show() { [book: Book.get(params.id)] } } ``` -------------------------------- ### DBM DB Doc Command Data Source Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/databaseMigration/ref/Documentation Scripts/dbm-db-doc.adoc Example of specifying a data source named 'reports' for the dbm-db-doc command. ```groovy --dataSource=reports ``` -------------------------------- ### Speaker Domain Class Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-graphql/docs/src/main/docs/guide/gettingStarted.adoc Example of a Speaker domain class in Groovy for a Grails application, demonstrating how to include it in the GraphQL API. ```groovy package demo class Speaker { String firstName String lastName String email static hasMany = [ talks: Talk ] String getName() { return "${firstName} ${lastName}" } static graphql = true } ``` -------------------------------- ### Immediate Query Execution with findAll and find Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/querying/whereQueries.adoc Demonstrates how to execute a where-style query immediately using `findAll` and `find` methods. ```groovy def results = Person.findAll { lastName == "Simpson" } def results = Person.findAll(sort:"firstName") { lastName == "Simpson" } Person p = Person.find { firstName == "Bart" } ``` -------------------------------- ### Start MongoDB Docker Container Source: https://github.com/apache/grails-core/blob/7.0.x/DEVELOPMENT.md A MongoDB Docker container can be started in detached mode, mapping the default MongoDB port to the host. ```bash docker run -d --name mongo-on-docker -p 27017:27017 mongo ``` -------------------------------- ### Basic Gradle Schema Export Commands Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/schema-export.adoc These examples demonstrate how to execute the schema-export command using Gradle, specifying environment and data source. ```console $ ./gradlew runCommand -Pargs="schema-export" $ ./gradlew runCommand -Pargs="schema-export --datasource=lookup" $ ./gradlew -Dgrails.env=prod runCommand -Pargs="schema-export" $ ./gradlew -Dgrails.env=dev runCommand -Pargs="schema-export" $ ./gradlew -Dgrails.env=prod runCommand -Pargs="schema-export export" $ ./gradlew -Dgrails.env=prod runCommand -Pargs="schema-export export --datasource=auditing" $ ./gradlew -Dgrails.env=prod runCommand -Pargs="schema-export stdout" ``` -------------------------------- ### Get Help for 'generate-controller' Command using --help Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/help.adoc Retrieves detailed help information for the 'generate-controller' command. ```shell grails generate-controller --help ``` -------------------------------- ### Install Specific Grails Version with SDKMAN Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/gettingStarted/downloadingAndInstalling.adoc To install a specific version of Grails using SDKMAN, provide the version number after the `grails` command. ```console $ sdk install grails {version} ``` -------------------------------- ### Groovy Precondition Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/databaseMigration/groovyPreconditions.adoc Demonstrates the general format for defining a database migration precondition using Groovy code. It shows how to use assertions and the fail method to check conditions. ```groovy databaseChangeLog = { changeSet(author: '...', id: '...') { preConditions { grailsPrecondition { check { // use an assertion assert x == x // use an assertion with an error message assert y == y : 'value cannot be 237' // call the fail method if (x != x) { fail 'x != x' } // throw an exception (the fail method is preferred) if (y != y) { throw new RuntimeException('y != y') } } } } } } ``` -------------------------------- ### Decorated Page Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/layoutTitle.adoc This HTML snippet shows an example of a page that will be decorated by a layout. It includes a title tag that the layoutTitle tag will use. ```html Hello World! Page to be decorated ``` -------------------------------- ### Find Shortest Path Using Proxies Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-neo4j/docs/src/docs/asciidoc/querying/paths.adoc This example demonstrates finding the shortest path without needing to load the entities first. It utilizes proxies to efficiently query the graph. ```groovy def path = Person.findShortestPath(Person.get(alice.id), Person.get(david.id)) assert path.length() == 3 assert path.nodes().collect { it.name } == ['Alice', 'Charlie', 'David'] ``` -------------------------------- ### Ge Criterion Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/createCriteria.adoc Example of using the 'ge' criterion to filter results where a property's value is greater than or equal to a specified value. ```groovy ge("balance", 1000) ``` -------------------------------- ### Run Grails Wrapper Help Source: https://github.com/apache/grails-core/blob/7.0.x/README.md Use this command to see the available commands for the Grails Wrapper. ```bash grailsw -t shell help ``` -------------------------------- ### Create a controller with a name Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/create-controller.adoc Generates a controller named 'Book' in the default controller package. ```bash grails create-controller Book ``` -------------------------------- ### Gt Criterion Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/createCriteria.adoc Example of using the 'gt' criterion to filter results where a property's value is strictly greater than a specified value. ```groovy gt("balance",1000) ``` -------------------------------- ### Example Grails Unit Test Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/testing/unitTesting/upgradingMixin.adoc This is an example of a unit test written for an older version of Grails using annotations like @TestFor and @Mock. ```groovy @TestFor(AuthorController) @Mock(Author) class AuthorControllerTests { @Test void testIndex() { controller.index() assert response.text == 'Hello' } } ``` -------------------------------- ### Grails Factories File Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/plugins/addingMethodsAtCompileTime.adoc This is an example of a grails.factories file that discovers trait injectors. The framework automatically generates this file, but it can be overridden if needed. ```properties #Grails Factories File grails.compiler.traits.TraitInjector= myplugin.ControllerTraitInjector,myplugin.DateTraitTraitInjector ``` -------------------------------- ### Basic Script with Description Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/commandLine/creatingCustomScripts.adoc Define a simple script that prints 'Hello World' and includes a basic description for `grails help`. ```groovy description "Example description", "grails hello-world" println "Hello World" ``` -------------------------------- ### List features for create-app command Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/list-features.adoc Use this command to list all available features for the `create-app` command. This helps in understanding the modularity and options available during application scaffolding. ```console $ grails -t forge create-app --list-features ``` -------------------------------- ### Example output of --list-features Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/list-features.adoc This is a sample output demonstrating the format and content provided by the `--list-features` flag. It categorizes features and indicates those included by default with a (+). ```shell grails> create-restapi --list-features Available Features (+) denotes the feature is included by default Name Description ---------------------------------- --------------------------------- CI/CD github-workflow-java-ci [PREVIEW] Adds a Github Actions Workflow to Build and Test Grails Application Cache cache The Grails Cache plugin provides powerful and easy to use caching functionality to Grails applications and plugins. cache-ehcache The Grails Cache Ehcache plugin extends the Cache plugin and uses Ehcache as the storage provider for cached content. Client micronaut-http-client Adds support for the Micronaut HTTP client Configuration properties Creates a properties configuration file Database database-migration Adds support for Liquibase database migrations. The Database Migration plugin helps you manage database changes while developing Grails applications. gorm-hibernate5 (+) Adds support for Hibernate5 using GORM gorm-mongodb Configures GORM for MongoDB for Groovy applications gorm-neo4j Configures GORM for Neo4j for Groovy applications h2 (+) Adds the H2 driver and default config mongo-sync Adds support for the MongoDB Synchronous Driver mysql Adds the MySQL driver and default config postgres Adds the PostgresSQL driver and default config sqlserver Adds the SQL Server driver and default config testcontainers Use Testcontainers to run a database or other software in a Docker container for tests Development Tools assertj AssertJ fluent assertions framework hamcrest Hamcrest matchers for JUnit jrebel Adds support for class reloading with JRebel (requires separate JRebel installation) Documentation asciidoctor Adds support for creating Asciidoctor documentation Logging logbackGroovy Gives you the ability to use groovy to configure logback instead of XML. Management grails-web-console A web-based Groovy console for interactive runtime application management and debugging Other grails-console (+) Starts the Grails console, which is an extended version of the regular Groovy console. Packaging shade Adds the ability to build a Fat/Shaded JAR Server spring-boot-starter-jetty spring-boot-starter-jetty spring-boot-starter-tomcat (+) spring-boot-starter-tomcat spring-boot-starter-undertow spring-boot-starter-undertow Validation hibernate-validator Adds support for the Hibernate Validator mockito Mockito test mocking framework for JUnit View Rendering grails-gsp grails-gsp views-json (+) JSON views are written in Groovy, end with the file extension gson and reside in the grails-app/views directory. They provide a DSL for producing output in the JSON format. views-markup Markup views are written in Groovy, end with the file extension gml and reside in the grails-app/views directory. They provide a DSL for producing output in the XML. ``` -------------------------------- ### Check if a plugin is installed Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/isAvailable.adoc Use the isAvailable tag to render content only if the specified plugin is installed. This is useful for integrating with other plugins without making them mandatory. ```GSP You have Spring Security installed! ``` -------------------------------- ### Create Domain Class Usage Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/create-domain-class.adoc Illustrates the command usage with a placeholder for the domain class name. ```groovy grails create-domain-class <> ``` -------------------------------- ### Example Rendered Book XML Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/REST/renderers/customRenderers.adoc Illustrates the resulting XML output for a `Book` instance after applying the custom `BookXmlRenderer`. ```xml ``` -------------------------------- ### Install Grails Development Version with SDKMan Source: https://github.com/apache/grails-core/wiki/Building-A-Local-Grails-Installation Use SDKMan to install a development version of Grails from a local source path, assigning a custom label. ```bash sdk install grails dev ~/development/grails-core ``` -------------------------------- ### Install Form Fields Templates Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/theWebLayer/fields/fieldsScaffolding.adoc Installs the scaffolding templates provided by the Fields plugin into your application. This command will overwrite existing `create.gsp` and `edit.gsp` files in `src/templates/scaffolding`. ```groovy grails install-form-fields-templates ``` -------------------------------- ### f:field Template Customization Examples Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - Fields/field.adoc Provides examples of using 'wrapper', 'widget', and 'templates' attributes to specify custom GSP templates for field rendering. ```groovy // renders _fields/bootstrap3/_wrapper.gsp: // renders _fields/maskedInput/_widget.gsp: // renders _fields/maskedInput/_wrapper.gsp and _fields/maskedInput/_widget.gsp: ``` -------------------------------- ### Create Application with Profile (Equivalent) Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/profiles/profileProfile.adoc This command is an equivalent way to create a new Grails application with a specified profile. ```bash grails create-app myprofile --profile=profile ``` -------------------------------- ### Create a Basic Custom Command Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/commandLine/creatingCustomCommands.adoc Implement GrailsApplicationCommand to define a new CLI command with a name, description, and execution logic. ```groovy // grails-app/commands/com/example/GreetCommand.groovy package com.example import grails.dev.commands.GrailsApplicationCommand class GreetCommand implements GrailsApplicationCommand { String getName() { return "greet" } String getDescription() { return "Greet the user" } boolean handle() { println("Hello, user!") return true // Return true to indicate successful execution } } ``` -------------------------------- ### EqProperty Criterion Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/createCriteria.adoc Example of using the 'eqProperty' criterion to filter results where one property's value is equal to another property's value. ```groovy eqProperty("lastTx", "firstTx") ``` -------------------------------- ### Polymorphic Query Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/docs/src/docs/asciidoc/domainClasses/inheritanceInGORM.adoc Retrieve all instances of a superclass and its subclasses using polymorphic queries. This example demonstrates listing all content and finding content by a specific author. ```groovy def content = Content.list() // list all blog entries, books and podcasts content = Content.findAllByAuthor('Joe Bloggs') // find all by author ``` -------------------------------- ### Find Book by Example Instance Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Domain Classes/find.adoc Finds the first book that matches the properties of a given Book instance. ```groovy // query by example def example = new Book(author: "Dan Brown") Book.find(example) ``` -------------------------------- ### Running a Grails Command Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Command Line/run-command.adoc Execute a Grails command named 'hello-world' using the Grails CLI or Gradle wrapper. ```bash grails run-command hello-world ``` ```bash ./gradlew runCommand -Pargs="helloWorld" ``` -------------------------------- ### Talk Domain Class Example Source: https://github.com/apache/grails-core/blob/7.0.x/grails-data-graphql/docs/src/main/docs/guide/gettingStarted.adoc Example of a Talk domain class in Groovy for a Grails application, demonstrating its relationship with the Speaker domain class and GraphQL integration. ```groovy package demo class Talk { String title String summary Speaker speaker static belongsTo = [ speaker: Speaker ] static graphql = true } ``` -------------------------------- ### Handle Single Promise Events and Get Result Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/guide/async/asyncPromises.adoc Attach `onError` and `onComplete` listeners to a single promise, and optionally block to retrieve its result using `get()`. ```groovy import static java.util.concurrent.TimeUnit.* import static grails.async.Promises.* Promise p = task { // Long running task } p.onError { println "An error occured ${err.message}" } p.onComplete { println "Promise returned $result" } // block until result is called def result = p.get() // block for the specified time def result = p.get(1,MINUTES) ``` -------------------------------- ### Check if a specific version of a plugin is not installed Source: https://github.com/apache/grails-core/blob/7.0.x/grails-doc/src/en/ref/Tags - GSP/isNotAvailable.adoc This snippet renders content if a particular version of a plugin is not installed. Note that only exact version matching is supported, not version ranges. ```GSP <%-- Do something unless version 1.2 of Resources plugin is installed --%> ```