How Do You Install Grails on Any Type of Linux server?

Problem scenario
You want to install Grails on a Linux server. What do you do?

Solution
Prerequisite
Your server has access to the internet.

Procedures
Run these commands:

sudo curl -s https://get.sdkman.io | sudo bash
sudo su –
sdk install grails

# We know this isn’t a best practice to install things as root,

 » Read more..

How Do You Assign a Variable in Groovy to Be an Integer Value?

Problem scenario
A Groovy program is returning an incorrect value for an integer variable. What is wrong?

Possible solution #1
Check the logic of your program. Use the println command to see the earliest point when this variable is assigned an incorrect value. This helps you pinpoint the problem.

Possible solution #2
Is the variable being assigned a number in quotes like this?

 » Read more..

How Do You Invoke the main Section of a Groovy Program?

Problem scenario
Your Groovy code has a section like this:

class Example {
static void main(String[] args) {

But this section above is not executing when you run your Groovy program. There are no errors however. How do you get it to execute?

Possible Solution #1
Remove lines of code (or statements) that are outside the “class Example {…”

Possible Solution #2
See this posting: How Do You Invoke a Class in a Groovy Program?

 » Read more..

How Do You Troubleshoot an Error like This in Groovy “groovy.lang.MissingMethodException”?

Problem scenario
You run a Groovy program like this: groovy foobar.groovy

You see this message:

Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (foobar$_run_closure5$_closure6) values: [foobar$_run_closure5$_closure6@6150c3ec]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (foobar$_run_closure5$_closure6) values: [foobar$_run_closure5$_closure6@6150c3ec]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
at foobar$_run_closure5.doCall(foobar.groovy:56)

What should you do?

 » Read more..

How Write a Custom Method inside of a Class in Groovy?

Problem scenario
You are familiar with Groovy scripts. Now you want to use a class and a method in the class. How do you do this?

Solution
Prerequisites
Install Groovy. See these directions for Ubuntu/Debian if you need assistance; see these directions for CentOS.

Procedures

  1. Create a file called test.groovy with the content below:

class Example {
def static Display(nifty) {
nifty.call(“Red”);  » Read more..

How Do You Invoke a Function in Groovy?

Problem scenario
You want to call a function and have it return a value. How do you do this?

Solution
Overview
(If you need assistance installing Groovy, see this posting for CentOS. or see this posting for Debian/Ubuntu Linux.)

Groovy has something called “Closures.” These act like functions in other programming languages.

 » Read more..

How Do You Troubleshoot the Groovy Error “JAVA_HOME is not defined correctly”?

Problem scenario
You try to run a Groovy command (e.g., groovy foobar.groovy), but you get this error:
“groovy: JAVA_HOME is not defined correctly, can not execute: /usr/lib/jvm/java-9-openjdk/bin/java”

What should you do?

Solution

  1. Set the JAVA_HOME variable. Run this command: which java
  2. Mentally eliminate the trailing “/bin/java” from the above command. If Java was not found,

 » Read more..

What is a Multi-branch Jenkins Job?

Question
With a newer version of Jenkins, you want to know what a multi-branch job is. What is a multi-branch Jenkins job?

Answer
With a given repository of Git code, you may have different branches. These branches may be for new features of a compiled program, slight changes in code (e.g., to fix a bug or make a procedure run more quickly),

 » Read more..

How Do You Write a Tic-Tac-Toe Program in Groovy?

Problem scenario
You want to code a Groovy 2.x program.  You want a program that reads user input, prints out processed output, uses closures (similar to functions in other languages) with and without return statements, handles some exceptions (non-standard input or input that is no longer valid based on what was previously entered), and uses classes.  How do you write a Tic-Tac-Toe (aka naughts and crosses) program in Groovy that has the above things?

 » Read more..

How Do You Invoke a class in a Groovy Program?

Problem scenario
You have a Groovy with these lines of code:

class Contint {
   static void main(String[] args) {
      def apple = {println “This is a basic test.”};
      apple.call();
   }
}
println “This is the second print statement in the code.”

The “Contint” class is never invoked.  What should you do?

Solution
Overview

You need to use the “new” reserved word. 

 » Read more..