miércoles, octubre 07, 2015

Gradle and Java EE

In the last years Apache Maven has become the de-facto build tool for Java and Java EE projects. But from two years back 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.

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.

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 an story for another post.

We keep learning,

Sun's in your eyes the heat is in your hair. They seem to hate you. Because you're there.  (Wonderful Life - Black)

10 comentarios:

Unknown dijo...

It would be great if you'd do a post on using https://spring.io/blog/2015/02/23/better-dependency-management-for-gradle with this, maybe Arquillian related? ;)

Unknown dijo...

Hehehe I had this in mind, but first I am waiting that the universe is released :)

Unknown dijo...

Do you think Maven is going into disuse?
Also not using xml, has Gradle another benefit against Maven?

Unknown dijo...

Not sure, I think that Maven has its market as well as Gradle. I would say that if you relay a lot on Maven plugins or your Jenkins pipeline contains a lot of logic for building the application and you feel comfortable and it works then Maven will continue be a solution, but on the other side if you feel that you need some extra power, and have a build script more compact, not spread between the application and the build pipeline, then Gradle might be your solution.

yanmaneee dijo...

vans shoes
curry 4
curry 6
balenciaga speed trainer
michael kors outlet
russell westbrook shoes
moncler outlet
yeezy boost 350
supreme clothing
goyard handbags

Assignment Help dijo...

Looking for some help with an assignment? We are providing a best online option where you can get online Assignment help
for your assignment at best price.

yanmaneee dijo...

kyrie spongebob
longchamp handbags
nike shoes
moncler outlet
timberland boots
westbrook shoes
michael kors purses
fila shoes
yeezy boost 350
adidas ultra

Jenifer dijo...

With an area of knowledge and skills, we are the most trusted brand in providing computer network assignment help. If you are in need of our service then you can reach us via email, live chat or over phone and discuss with us your assignment requirements.

Assignment help dijo...

Myassignmenthelp is an incomparable online assignment writing service delivering excellent Science assignment help service. Through a team of over 3000 subject experts we offer individual attention to every student making the assignment help experience completely unique and stress-free for students aiming to score high in every assignment. We even offer you free samples on our website that can be used as a quality reference to write a fresh piece of work and improve your grades.

Veronica Kate dijo...

The blog written is extremely impressive, with a great topic. However, a bit more research could have strengthened it even further. You can explore the services as offered by livewebtutors.com, a premium academic writing services platform offering the best of Plagiarism Checker Tool teamed with knowledge and experience.