concept library in category gradle

appears as: library, libraries, A library, libraries
Gradle in Action - corrected 9052019

This is an excerpt from Manning's book Gradle in Action - corrected 9052019.

Say you want to write a script that compiles your Java source code in the directory src using the Java compiler and put it into the output directory build. Your Java source code has a dependency on a class from the external library Apache Commons Lang. You tell the compiler about it by referencing the library’s JAR file in the classpath. After compiling the code, you want to assemble a JAR file. Each unit of work, source code compilation, and JAR assembly will be grouped in an individual target. You’ll also add two more targets for initializing and cleaning up the required output directories. The structure of the Ant build script you’ll create is shown in figure 1.11.

In recent years, the interest in polyglot programming and its application in real-world, mission-critical software stacks has skyrocketed. The term polyglot programming was coined to describe projects that incorporate more than one language. That’s particularly true for the Java world. For web developers, the world can no longer do without a potpourri of JavaScript, corresponding frameworks, libraries, and CSS. Backend code or desktop applications are no longer built with Java alone. Other JVM-based languages like Groovy or Scala are added to the mix. It’s all about picking the right tool for the job. In this chapter, we’ll discuss how Gradle faces the challenge of organizing and building polyglot projects by using your To Do application as an example.

On top of an insufficient JavaScript hosting infrastructure, you can’t depend on a unified descriptor format for libraries, similar to the pom.xml file for Maven repositories. This means that transitive JavaScript libraries, CSS, and even required images need to be declared explicitly.

Let’s look at how to retrieve the minified version of the library from JQuery’s download page. You’ll see a familiar pattern here. First, you define a custom configuration, and then you declare the library with the specific version in the dependencies configuration block. For downloading the library to your source code directory, create a new task of type Copy that uses your custom configuration. The following listing demonstrates how to wire this task up with other important tasks of your project to ensure that you fetch the JavaScript before running the application in Jetty or assembling the WAR file.