Building Java Play framework applications with Gradle

Source: Internet
Author: User

At LinkedIn, we've been evaluating the best development frameworks and tools to develop great products. In the 11 's history, we used many front-end web frameworks-such as Grails, Frontier (web framework within LinkedIn), and recently: play! We love play and are passionate about pushing it inside the company. So we used play to integrate and expand. Now we're evaluating which build system, the same one, is better.

This article describes the evolution of using Gradle in play to support development, and the current state of Gradle and its preliminary features. We want the play community to provide more feedback to help with the development of Gradle-class software. The ability to develop play apps for SBT and Gradle will provide more freedom and versatility.

Background: Organization of code

At LinkedIn, we manage public APIs and services in a code warehouse, each of which we have named Multiproduct, each multiproduct through an independent ivy, the default name is Com.linedin. Some of LinkedIn's code is open source, such as Databus.

The result of organizing the code with Multiproducts is that they are all multi-engineered structures with 10 or 100 projects per multiproduct, and each project has multiple components (artifacts, hereinafter).

At LinkedIn, our play app has more than 500 jar packages under the classpath path, which means that you need to process at least 500 nodes for full dependency resolution. But reliance on analytic heavy depends on the rules of conflict resolution (resulting in inefficiency). We do not parse a version of a component (such as a jar) layer, but instead work on the multiproduct (or Ivy Organization) layer, which guarantees that all component versions within the same multiproduct are consistent.

For example, the tool class Util multiproduct, we have 3 different modules, Com.linkedin.util:foo, Com.linkedin.util:bar, Com.linkedin.util:baz. Each module may have one or more components, and a general conflict resolution ensures that all modules have only one version, but the version between the different modules ("Com.linkedin.tuil:foo", "Com.linkedin.util:bar", and "in this case") Com.linkedin.util, Baz ") may still be different. Our custom dependent processors will ensure that all artifacts in the same multiproduct are the same version.

The extensibility challenge of using SBT

The Play default build tool is Sbt,play and SBT are technically decoupled, but there are still a lot of non-detached layers. When we started developing the play app, we quickly ran into the challenges of SBT extensibility and relied on Apache Ivy Library, which required 5-10 minutes of dependency resolution for an application, and a framework project that would take more than 30 minutes.

Over the past year, LinkedIn has been working with typesafe to improve the extensibility of SBT, and it's still going on, but at the same time, we feel it's worthwhile to evaluate other building tools.

Integration of play with Gradle

LinkedIn has been using gradle for more than 3.5 years, with gradle shadows everywhere, from small projects to a single multi-product building nearly 4,000 projects, and 2015 years of Gradle with many exciting new features.


In addition to the above, we believe that the integration of both is very valuable to both sides, together with Gradleware we began to study if it becomes a reality. In the first half of 2015, we will focus on integration implementation and testing, has completed 3 milestones.

Milestone 1: Use Gradle to develop a play app.

With Gradle and play plugged in, developers can use Gradle to build an app with all the play features.

Features include:

    • Compiling Java and Scala source code

    • Compiling routes

    • Compiling templates

    • Compiling resources/configuration files

    • Support Coffeescript, Less/css, JavaScript

Using this build pipeline, the play app can be launched with Gradle run or gradle start, or with gradle stage or Gradle Dist.

With this capability we can fully test the performance and scalability of the play's build system.

Hint: This milestone is not supported by the persistent mode (continuous mode) and unloading (hot reload).

Milestone 2: Continuous mode and hot load

The ability to heat load when developing an application will be the most enjoyable play feature.

Manual packaging before automation is a great idea and we are eager to add it to the Gradle. Milestone 2 will introduce Gradle's "observer" mode, which is the same as the SBT persistence mode (continuous mode): Gradle--watch run.

Play can also be rebuilt automatically when the browser is refreshed, which is done via the play's Buildlink interface, which will include this feature.

Milestone 3: Becoming a reality

If you're familiar with play you may have noticed a serious feature missing: Scala's interactive features repl! Don't worry .... This is part of Milestone 3 and will allow you to interact with the class (classes) in the console.

There are documents, integrated with SPECS2, and Scala's code is elegantly integrated. To get these started together, you need an appropriate Gradle base platform, just like you used activator before.

Want to know more? can refer to here.

Preliminary milestone 1

The features of the milestone have been completed and you can download the latest version to try it out. There are binaries, source code files, and example projects in the download package. Add the "bin" path to your environment variable after decompression.

The play example is in the "Samples/play" directory.

of basic

The basic example Build.gradle file demonstrates the play plugin declaration and the warehouse requirements configuration, and the dependency block shows that if the 3rd party class library is defined, the ' play ' configuration provides a system and runtime dependency, and ' playtest ' provides a dependency definition for testing.

High-level

The advanced example Build.gradle shows if configured as Play/scala version.

Multiproduct:

This is the standard Gradle multiproject build configuration, the root directory contains the play main application, 3 sub-modules in the modules directory, the admin and user Submodule in the respective folder, Utile is a Java class library. The Settings.gradle file is connected to 3 sub-projects, and the main project Build.gradle describes the dependencies of 3 sub-modules.

You can try to perform the following tasks:

    • gradle :assemble: Building jars and assets

    • gradle :runPlayBinary: Build and run apps in developer mode

    • gradle :check: Executing test Cases

    • gradle :stage: Build and publish an image, along with the startup script

performance of the preview version

We compared the build time of Gradle and Activator (SBT) in two ways.

The project used for comparison

    • Basic-A simple play project with the Play-scala template set to Activator.

    • Multiproject-Build the play example project in Gradle Multiproject, a Multiproject build based on the Gradle ' s, Example 3 is also a sub-project of util.

Test method

    • All dependent libraries have been downloaded to the local gradle and Ivy caches.

    • The test task "dist" will generate the final release tar package, which will test the entire build and release process, while surrounding dependency parsing, compiling, and packaging execution.

    • The Gradle is serial execution and is enabled Configure-on-demand and daemon when vanilla SBT is used.

    • Clean-build: Shows the complete packaging process from a clean state.

    • No change: No task changes returned "dist". Used to test how fast build configurations and updates are.

    • Incremental: Changed the line so that the root play project relies on Java or scale sub-engineering to simulate a typical process.

Test results

From the above can be seen, gradle construction, in addition to 1 of the difference is winning, whether it is not or small changes are very good, this is what we expect. Http://app.csq.im

Basic Dependency Analysis Performance evaluation

We are more interested in the performance of dependent parsing, so we just want to compare how long it takes to resolve all dependencies on ACTIVATOR/SBT

Note
The 1.Gradle dependency resolution task is not just about solving dependencies, it actually prints a dependency tree of 4 sub-projects
2.Gradle of dependency resolution processing time is reported through built-in analysis tools

From the above results it is easy to conclude that Gradle's native dependent parsing engine is more than 10 times times faster than the Ivy engine used by ACTIVATOR/SBT. That's why we built the Java project on top of Gradle.


We are still trying to reconstruct the ACTIVATOR/SBT project that takes 5-10 minutes before it is gradle, and we expect better results!


Building Java Play framework applications with Gradle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.