// This is the main Gradle build script. // Gradle build scripts are written in the JVM language *Apache Groovy*. // It runs on the JVM, but it isn't Java, same as eg. Kotlin, Scala, Clojure... // Groovy clones a lot of Java, but adds a bunch of syntax sugar. // For example, Groovy does not require toplevel package of class definitions. // Additionally, Groovy has *closures*, which are like lambdas in Java 8. // They are essentially blocks of code, which can be passed to functions. // Groovy lets any omit the semicolon and parentheses when calling a function. // Gradle first initializes itself, then runs the build script. // The build script eval starts with settings.gradle, then runs the sub-projects. // In this case we just have a toplevel build.gradle, which it runs next. // The build script exposes a bunch of _tasks_, which might depend on other tasks, // building a _task graph_. A _task_ is a unit of execution. // A task is manually invoked on the command line. Gradle builds the task graph, // and invokes all the dependencies of tasks, in the right order (dependency before dependent). // The following calls the function plugins with the closure {id 'applications'} // This is syntactically equivalent to plugins({id('application');}); // Now, the Gradle build script consists of a bunch of function calls like this // that declaratively configure the build system with imperative function calls. // Gradle has the core, and then a bunch of various plugins. // Repositories to pull plugins from can be added in the settings.gradle file. // This block lists which plugins to enable, by their id in this case. // Here, we enable the application plugin, which provides support for runnable applications. // It adds the `run` task, and the `application` function at the bottom that configures it. // This is because Gradle can be used for all kinds of stuff, such as Java libraries, C++ projects... // It defaults to Java, though. plugins { id 'application' } // This defines the repositories that Gradle can pull Java _libraries_ from. // It _cannot_ pull plugins from here. repositories { // There is a builtin for https://repo.maven.apache.org/maven2/ mavenCentral() } // Declares the actual Java libraries to pull. // Right now, we don't pull any. dependencies { } // Configures Java. java { } // Configures the `application` plugin. application { // We have to tell the plugin which class to run, since there's no standard. // In finished jars, this will be written into the Main-Class attribute of the jar manifest. mainClass = 'org.example.App' }