In Groovy, a constant is a variable whose value cannot be changed once it has been defined. To declare a constant, you should use the final keyword before the data type of the variable. Here's an example:
final int myAge = 25
In the above code, myAge is a constant that has been assigned a value of 25. Once this value has been assigned, it cannot be changed.
Another example of a constant in Groovy is shown below:
final double PI_VALUE = 3.14
In this example, PI_VALUE is a constant that has been assigned the value of 3.14. This constant can be used throughout the code wherever the value of Pi is required, without the risk of its value being accidentally changed.
Constants are usually declared using uppercase letters for all variable names, with underscores separating words. This makes it easier to distinguish constants from regular variables in the code.