What is Gradle?
Gradle is a build tool used by OPENRNDR components like the core, extensions, template, and guide.
What is a build tool?
A core task a build tool performs is telling the compiler to compile programs. Compiling involves reading your source code files (human-readable text files describing algorithms) and converting each line into instructions the machine can execute. A compiler program usually takes several source code files and outputs one executable program. Compilers often have complex command-line arguments, and build tools take care of such details so we don’t need to.
Other essential steps built tools perform include downloading dependencies (third-party libraries used by our source code) and packing those dependencies into our executable program.
Gradle is a complex tool that supports multiple programming languages. It has many plugins providing all kinds of functionality needed by people building and distributing applications.
To configure Gradle, one uses Tasks which are text files describing the steps required to complete something.
Do we always need to use a build tool?
Theoretically, one could write Kotlin or Java programs without using any build tool, but that would involve manually downloading all the dependencies and writing long instructions in the command line to build your programs. Using Gradle makes our life easier.
Do I need to know Gradle to use OPENRNDR?
In most cases, one can happily write OPENRNDR programs without knowing that Gradle exists, although we may need to edit Gradle configuration files in some cases.
Enable or disable extensions
Suppose a program requires access to a MIDI hardware controller. In that case we are lucky, because someone already wrote an OPENRNDR extension for this specific use case. OPENRNDR extensions are called ORX. The only thing we need to do is to edit the build.gradle.kts file and add a dependency to the MIDI ORX.
- Explore the list of available extensions. We can see one called
orx-midi. - Open
build.gradle.ktsin youropenrndr-templatebased project. - Inside the
dependencies { ... }block, addimplementation(orx.midi)(converting any-characters in the name into.). - Click “Sync All Gradle Projects” in the IDE to trigger the downloading of the MIDI libraries.
- Now the extension can be used in your code.
Add or remove dependencies
In some cases we want to use algorithms or services not implemented by an ORX. Luckily there are thousands of JAVA libraries available to us, just one line away.
Three such dependencies (JSON, CSV, and XML) are predefined and can be easily added as explained under fileIO.
Other dependencies (for instance a 2D physics library) can be easily added in this format: implementation("org.jbox2d:jbox2d-library:2.2.1.1").
- Find such dependencies in maven central.
- Choose the
Gradlesnippet and copy it to the clipboard. - Paste it into
build.gradle.ktsinside thedependencies { ... }block. - Click “Sync All Gradle Projects” in the IDE to trigger the downloading of the dependency.
- Now the library can be imported in your code.
What else does Gradle do for OPENRNDR?
- It converts the OPENRNDR source code into multiple distributable libraries.
- It helps publish those libraries to an online database, making them accessible to everyone.
- Similarly, it builds all the ORX extensions (called add-ons or plugins in other frameworks) and helps publish them to the same database.
- It runs your OPENRNDR programs and builds executables you can share with others.
- It builds the OPENRNDR Guide, creates images and video files, embeds them in the documentation, and then publishes the guide online.
- Gradle runs tests to ensure code changes did not break any functionality.
- Gradle updates readme.md files, for example, to list all the ORX extensions in the root readme file.
Thanks to Gradle and the automation it enables, the whole OPENRNDR project can be maintained by a small team of developers.
Are there alternatives to Gradle?
Other build tools often used are Maven, Ant, and cmake.
Gradle is an excellent fit for Kotlin-based projects because Kotlin itself can be used to write Gradle tasks, avoiding the need to work with additional languages.