DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Transactional Outbox Patterns Step by Step With Spring and Kotlin
  • Operator Overloading in Java
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • What Is Envoy Proxy?

Trending

  • Transactional Outbox Patterns Step by Step With Spring and Kotlin
  • Operator Overloading in Java
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • What Is Envoy Proxy?
  1. DZone
  2. Coding
  3. Java
  4. Moving from Maven to Gradle in Java

Moving from Maven to Gradle in Java

Apache Maven has become the de-facto build tool for Java EE projects, but Gradle has been steadily gaining more and more users. Learn how to use Gradle for Java EE projects.

Alex Soto user avatar by
Alex Soto
·
Oct. 12, 15 · Tutorial
Like (7)
Save
Tweet
Share
12.87K Views

Join the DZone community and get the full member experience.

Join For Free

In the last few years Apache Maven has become the de-facto build tool for Java and Java EE projects. But for the last two years, Gradle is gaining more and more users. In this post you are going to see how to use Gradle for Java EE projects.

Gradle is a build automation tool like Ant or Maven but introducing a Groovy-based DSL language instead of XML. So as you might expect the build file is a Groovy file.

There are different ways to install Gradle, but for me the best way is using sdkman tool. To install sdkman tool simply run: $ curl -s get.sdkman.io | bash

After that you can init sdkman by running: $ source "$HOME/.sdkman/bin/sdkman-init.sh"

With sdkman installed, installing Gradle is as easier as running: $ sdk install gradle

Now you can start creating the build script. The first thing to do is creating a settings.gradle where in this case we are going to set the name of the project.

rootProject.name = 'my-javaee'


This file is also used in case of multiple module projects.

Last file you might need is one called build.gradle which manages all the build process.

apply plugin: 'war'

group = 'org.superbiz'
version = '1.0-SNAPSHOT'
description = "My JavaEE project"

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()        
}

dependencies {
    providedCompile group: 'javax', name: 'javaee-api', version:'7.0'
}


Notice that the first line indicates that what you are going to build is a war project.  Then project properties are set like the group, version, description or Java compilation options. Finally only one dependency is required and with provided scope since the implementation is provided by the application server.

Note that providedCompile scope is only available if you are using the war plugin. If you are using another plugin like java, then you will need to implement this function by yourself (at least at the time of writing this post with Gradle  2.7).

And that's all, pretty compact, only 16 lines and no verbose information. Of course, now you will need to add more dependencies like JUnit or Arquillian with testCompile scope or any other extra library required in your code like the well known apache-commons dependency; but this is a story for another post.

Apache Maven Gradle Java (programming language)

Published at DZone with permission of Alex Soto, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Transactional Outbox Patterns Step by Step With Spring and Kotlin
  • Operator Overloading in Java
  • Avoiding Pitfalls With Java Optional: Common Mistakes and How To Fix Them [Video]
  • What Is Envoy Proxy?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: