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,
Alex.

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


16 comentarios:

  1. 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? ;)

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

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

    ResponderEliminar
  4. 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.

    ResponderEliminar
  5. 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.

    ResponderEliminar
  6. If you are worried about the thesis statement you want to put in your thesis, then you can take help from online thesis help websites. As you know the introduction is the main part of the thesis. People will first read this part. Once they are satisfied with this part, they will go ahead. So you need to go for thesis writing help to make your intro interesting. The thesis statement holds the gist of your thesis. You have to include all the key points of your thesis in this part. You always need to keep this portion clean. Do not use tough words here. Keep this part readable and understandable. Your thesis helper must have ideas of what you need to put here. Remember, if you cannot attract everyone to the thesis introduction, your thesis won’t be a successful one. So, write it accordingly and take the necessary tips and help from the writing company you have hired.

    ResponderEliminar
  7. The information you are providing that is really good. Thank for making and spending your precious time for this useful information. Thanks again and keep it up.
    Top CA firm in India

    ResponderEliminar
  8. Este comentario ha sido eliminado por el autor.

    ResponderEliminar
  9. Nice Blog. Thanks for sharing with us. Such amazing information.

    Reasons why people stop following you on Instagram

    ResponderEliminar
  10. Read Newspaper Online list sorted by Countries and by languages. A huge collection of newspaper or epapers online from all over the world in various languages. Epaper hub contains Print edition epaper that you read Online and grab your news through internet. Here you can find any number of epaper in different language, from different cities, different countries and cities. So don’t wait and search you daily newspaper and enjoy news from all over the world online.

    ResponderEliminar
  11. It’s an amazing, very talented and highly skilled blogger, very satisfied with your excellent post, and looking forward to more of your useful thought, thanks for sharing. when will gombe state poly post utme form be out

    ResponderEliminar
  12. It is neatly blog article! I really admire your effort; keep up the excellent quality writing, it’s rare to see a great blog like this one nowadays. Thanks so much for sharing. mcpherson university cut off mark for Statistics

    ResponderEliminar