Agenda

This tutorial describes how a Griffon 2 application can be created and run. IDE configurations are discussed too.

1. Getting the ToolChain

The first step is to get the tools needed to create an application. While it’s possible to create a Griffon 2 application from scratch it’s also true that the power of conventions allows you to get faster development cycles. We need the following tools:

  1. SDKMAN: tool manager.

  2. Maven or Gradle: build tool.

  3. IntelliJ IDEA or NetBeans or Eclipse: IDE.

SDKMAN

SDKMAN is a tool for managing parallel Versions of multiple Software Development Kits on most Unix based systems. It provides a convenient command line interface for installing, switching, removing and listing Candidates. The candidates we’re interested in are Lazybones and Gradle.

You can run SDKMAN on Windows as long as you have a POSIX environment. We recommend you to give Babun Shell a try first.

Installing SDKMAN is as easy as executing the following command

$ curl -s https://get.sdkman.io | bash

This will download the required files and configure your environment. After this the sdk command should be available. You can verify your setup by executing this command

$ sdk help
Gradle

Gradle is an open source build automation system. Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else.

You can download and install Gradle manually, however we recommend using SDKMAN for this task too, as it greatly simplifies handling different versions and keeping binary distributions up to date. You can install Gradle via SDKMAN by executing this command

$ sdk install gradle

Once installed you can verify that’s working by invoking this command

$ gradle --version
------------------------------------------------------------
Gradle 6.9
------------------------------------------------------------

Build time:   2021-05-07 07:28:53 UTC
Revision:     afe2e24ababc7b0213ccffff44970aa18035fc0e

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_312 (Azul Systems, Inc. 25.312-b07)
OS:           Mac OS X 10.16 x86_64

Gradle 6.0 is the minimum supported version.

Maven

Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.

You can download and install Maven manually, however we recommend using SDKMAN for this task too, as it greatly simplifies handling different versions and keeping binary distributions up to date. You can install Maven via SDKMAN by executing this command

$ sdk install maven

You can verify this tool by executing this command

$ mvn -v
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /Users/duke/.sdkman/candidates/maven/current
Java version: 1.8.0_312, vendor: Azul Systems, Inc., runtime: /Users/duke/.sdkman/candidates/java/8.0.312.fx-zulu/zulu-8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

Maven 3 is the minimum supported version.

IDE

All major IDEs can be used to build Griffon applications. Considering that the Griffon tool chain is comprised of tools that can be invoked from the command line you may want to use a text editor (such as VIM) instead.

Top

2. Creating an Application

With the tool chain ready we can now create an application. The Griffon templates provide a starting point depending on a particular UI toolkit / programming language combination. Currently supported UI toolkits are

  • Swing

  • JavaFX

  • Pivot

  • Lanterna

While the currently supported programming languages are

  • Java

  • Groovy

  • Kotlin

In this tutorial we’ll go for the most basic combination: Swing and Java. Execute the archetype:generate Maven goal using the griffon-swing-java-archetype archetype as the starting point. Note that the archetype uses sensible defaults for most of its options, however ou can change them to suit your needs. Here’s how a creation session looks

$ mvn archetype:generate \
      -DarchetypeGroupId=org.codehaus.griffon.maven \
      -DarchetypeArtifactId=griffon-swing-java-archetype \
      -DarchetypeVersion=2.16.0 \
      -DgroupId=org.example \
      -DartifactId=sample\
      -Dversion=1.0.0-SNAPSHOT \
      -Dgradle=true

Change into the sample directory and inspect its contents. You’ll see it contains a build.gradle file that can be used to build the project with Gradle. The standard structure of a Griffon application looks like this

.
├── build.gradle
├── griffon-app
│   ├── conf
│   ├── controllers
│   ├── i18n
│   ├── lifecycle
│   ├── models
│   ├── resources
│   ├── services
│   └── views
└── src
    ├── main
    │   ├── java
    │   └── resources
    └── test
        ├── java
        └── resources

Top

3. Running the Application

The application is fully functional at this point. You just have to select your build tool of choice and invoke the right command for it. In the case of Gradle this is a simple as executing

$ ./gradlew run

Project dependencies get downloaded, classes are compiled and a small window pops up after a few seconds. Maven has a similar workflow, the Griffon master application pom has simplified building tasks by providing a lot of plugins and profiles that follow the conventions. Running the application with Maven is as easy as executing

$ ./mvnw -Prun

The master pom uses a profile to make sure that classes and resources are properly handled before the application’s main class is run inside a JVM process.

Top

4. Setting up the IDE

Configuring IDEs is not that difficult considering that Griffon 2 projects can be imported either as Gradle or Maven projects, in other words, there’s no need for a special IDE plugin to build and run a Griffon 2 application.

Both IntelliJ IDEA and NetBeans have a Griffon plugin (IDEA has it installed by default). These plugins were designed to work with Griffon 1 and are incompatible with Griffon 2. Do not use these plugins to work with Griffon 2 projects!
IntelliJ IDEA

You can import a project either using the Gradle or Maven import. Once you do you’ll be able to invoke build goals using the respective build tool view.

You must also have Annotation Processing enabled for compile time annotations such as @ArtifactProviderFor to be picked up automatically. Open up Preferences and navigate to Build, Execution Deployment > Compiler > Annotation Processors

intellij apt processor
Figure 1. Annotation Processing in IntelliJ

Finally, check that all *-compile JARs are added in the PROVIDED scope, also jipsy-0.4.1.jar (for Java and Groovy projects) and gipsy-0.4.1.jar (for Groovy projects).

NetBeans

NetBeans can import Maven projects without additional plugins. You must install the Gradle plugin first if you want to build Gradle based projects. The Gradle plugin is directly accessible from the default plugin location as configured in the Plugins preference panel.

NetBeans is able to pick up Annotation Processors automatically from the classpath, there’s no extra step needed.

Eclipse

Unfortunately Eclipse is the odd member of the three IDEs. You must locate and install the m2e (Maven) and gradle plugins that are compatible with your current Eclipse installation. Once you do, you will be able to import the project directly into your workspace.

You must also install the Gradle Buildship and Groovy plugins from the marketplace

eclipse plugins
Figure 2. Required Eclipse Plugins

Finally, Annotation Processing must be manually enabled. You must do this in a per project basis. Search for Annotation Processing in the project’s properties and tick the checkbox to activate this option.

eclipse apt processing.1
Figure 3. Annotation Processing in Eclipse (1)

You must also define every single JAR file that provides APT processors. The most basic ones ar jipsy and griffon-core-compile. These JARs are found in your build tools' cache and/or local repository.

eclipse apt processing.2
Figure 4. Annotation Processing in Eclipse (2)

As a rule, all griffon-*-compile JARs provide APT processors and AST transformations.

Top