This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

What do Maven and Gradle actually do?

 
Ranch Hand
Posts: 289
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im reading about Maven and Gradle and cant place where and what they are/do.

I know they are for build automation for Java
but what does that mean?
Dont Java projects just get compiled? can somebody please explain these two and which is better or mostly used.
Im guessing like everything they have their strengths and weaknesses and are applied depending on what you doing.
Is it strictly for building mobile projects?
 
Ranch Hand
Posts: 226
1
jQuery Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Wayne

I'm with you, I haven't been involved in anything big and complex to use them. When I was using Netbeans it automatically did the build and compile etc, including creating a WAR file from a click. However I understand Netbeans generates a large ANT xml file (similar to Maven and Gradle I believe) to do this.  So for Netbean projects, these processes are in the background and you don't necessarily see them.

In larger projects, when deploying a new app, or updating one, there things that need to get done such as folders created and copied, resources copied into folders etc, there are dependencies that need to be managed with databases etc. This is all done using build tools.

This is not a complete answer, but others might be able to add.



 
Sheriff
Posts: 15913
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Builds are not just about compiling and packaging a program's source into binary executables, although those are the most basic tasks preformed as part of a build. It can also mean running tests, making sure dependencies are available (jar files of libraries and other projects your project uses), generating documentation, copying build artifacts to repositories, deploying build artifacts, and many other tasks. This entire process can get complex and complicated and you don't want to be typing commands to perform each task every time you do a build. With build automation, all you'd do is run one relatively simple command and the build tool will do the rest for you.

Dependency management is the second biggest problem with builds. Some projects will depend on many other different projects/libraries like Spring, JUnit, Hibernate or some other ORM framework, etc. These might have their own dependencies, and those dependencies their own. Given that, the number of direct and indirect dependencies your code may have on other JAR files can get quite large and the task of determining what those are and what the actual command is to build and run your project is can be very volatile. Manually tracking all that can become very cumbersome and error-prone so having a tool that does it all for you relieves you of most of the nitty-gritty work that needs to be done. All you have to do is specify what the direct dependencies are and the tool will do the rest of the work for you.
 
Saloon Keeper
Posts: 22634
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For any reasonably complex application, you don't "just compile" the Java files. You have to organize the classes produced by the compiling process, you'll generally package the results into a deployable component such as a JAR, WAR, or EAR file. And you'll probably be depending on some third-party libraries which would need to be fetched from some global repository and included into the build. For example, the log4j logging library.

Maven is a magic wizard that, given a properly-organized project, can handle all those tasks and more. I use the term "magic" deliberately, since unlike the Ant build tool, you don't have explicit build rules in a Maven project, but rather built-in goal processors that use plug-in components called "mojos" to do their work. Much of the magic is accomplished automatically just buy putting the right files in the right directories.

Every Maven project has a pom.xml file that describes the parts of the project that Maven cannot deduce automatically. The POM specifies the name and version of the component to be produced, what special plugins it might need to do so, and the component dependencies that must be fetched from external sources.

This dependency fetching is one of Maven's most powerful features. I can take almost any Maven project, run a "mvn clean" command to delete its working files, zip up the cleaned project, email it to the other side of the Earth, and be assured that anyone anywhere can re-build everything armed with only an unzip program, a Java compiler and Maven.

Maven also supports secondary goals such as automatically running unit tests and building documentation (like JavaDocs). I even use it to build OS installer packages for my projects so that a system administrator can deploy and maintain my Java apps just like any other system application.

Gradle is what you get when you start looking beyond Java. Maven is designed specifically for Java-based projects. Gradle understands that there are other languages used in modern IT shops as well.
 
Marshal
Posts: 70604
287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a “beginning” topic. Moving discussion to different fora.

[edit]Somebody said I shouldn't have moved this discussion, so I shall add it back to its original location
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic