Beginner's Guide: Java Automation Tools

Discover some practices that will make your daily life easier with Java automation tools

Bruno Lellis

💻 Software Developer at iFood

At part 1 of the guide We made an introduction to the Java language, covering the first steps in this environment.

Follow me in this second part of the guide, in which we will talk about practices that will make your daily life easier.

Grab another cup of good coffee and enjoy this read!

👷‍♀️ Construction Tool

After the first steps in the language, you will need a project compilation automation tool. These tools help not only with construction, but also with managing dependencies (third-party libraries that you will use), executing and validating automated tests, assembling artifacts (files .jar), among others. There are very interesting plugins that analyze your code , validating bugs and indicating better ways to write the same logic. An important observation is worth making here: learning from examples is also a relevant way of absorbing knowledge and has already helped me a lot.

The most popular tools include Apache Maven , gradle It is Bazel .

My recommendation is to choose Maven. It is a most used tool (from simple to complex projects) and is relatively simple to understand. To install, simply sdk install mavenuse SDKMan. The structure of a Maven project must follow some assumptions, which also means that you don't need to think about many specific details, which is good when you're starting out.

Maven supports archetypes, as if templates were ready to be used. For example:

				
					mvn archetype: generate -B \ -DarchetypeGroupId=org.moditect.ossquickstart \ -DarchetypeArtifactId=oss-quickstart-simple-archetype \ -DarchetypeVersion=1.0.0.Alpha1 \ -DgroupId=com.example.demos \ -DartifactId=fancy- project \ -Dversion=1.0.0-SNAPSHOT \ -DmoduleName=com.example.fancy
				
			

An IDE (we'll cover it in the next topic) will make it easier to create a project, whether with Maven or Gradle. In other words, don't get too attached to the above command.

A lesser known and useful feature is the Maven Daemon , which helps financially with the speed of executions, keeping a process running in the background and avoiding the cost of repeatedly starting the necessary environment. To install, just one sdk install mvnd.

The Gradle tool is also popular and powerful, it has a lot of flexibility and interesting features like incremental compilation (or compilation avoidance , which intelligently compiles only the parts that have been modified). These are interesting features, but more advanced.

📝Editor/IDE

Many developers (not just in the Java world) love to fight for the best build tool, the best Linux distribution… and with an editor it couldn't be any different. In other words, many different opinions will easily arise at this point. In addition to editors, there are also Integrated Development Environments or IDEs.

My suggestion is to use the IntelliJ IDEA . It is a relatively heavy IDE, but you will have valuable support at all stages of development: from project creation, to versioning (git), to automated testing, to Maven/Gradle executions, to suggestions for simplifying and/or or improve your code, with refactorings, debugging support, in other words, it's worth it. It is worth mentioning that there is a Community version (free) and also an Ultimate version (paid). Take the time to learn and get used to the shortcut keys, as they will save you a lot of time in your everyday life.

There are other equally famous IDEs: Eclipse IDE It is NetBeans .

As expected, there are very light options, such as the VSCode with the help of plugins to support the Java language . This would be my second option after IntelliJ.

🧱 Libraries

The ecosystem of available third-party libraries is what makes the Java language so strong: you will certainly find an option (library or framework) ready to be used for every task you can imagine, and it is usually an open source option.

However, be careful! Be thoughtful about choosing which libraries you really need to import into your project. Many options also exist in the language itself, without the need to import a new dependency.

Adding a dependency to your project should always be a conscious decision. Without controlling this, you will encounter conflicts between transitive versions (i.e. dependencies on dependencies), increased complexity of your project (keeping everything up to date, which is always recommended), you will be more subject to vulnerabilities, etc. It's better to code something in the project itself, or even copy a part of a library that you need — as long as the license allows it.

Some famous libraries you find in many Java projects:

The list awesome-java It is a starting point for discovering many other famous library options.

The vast majority of libraries are available in the Maven Central . All build tools are integrated with this repository. The website MVN Repository facilitates the search and details of libraries, with their versions and dependencies. You may also reach the point where you need to publish articles (libraries) internal to your organization. This is quite common and possible with the use of servers such as Nexus or Artifactory . There are also cloud options, such as AWS CodeArtifact .

🐢 Application Frameworks

Many enterprise systems are built on top of a framework that provides support for structuring your code via dependency injection, perfectly assists in managing the versions of third-party dependencies (in Maven, BOM or Bill of Materials ), helps with testing by facilitating the creation of mocks of APIs and clients, among others.

As you might expect, there are several options here, all of which are well-known and none of which is the best in all aspects.

The main options are Spring Boot , Quarkus , Micronaut , Helidon , Jakarta EE . My recommendation here is to choose Spring Boot , for the broad support and maturity. Quarkus and Micronaut are newer names on the market and certainly deserve a chance with you: they were created with the aim of taking Java to the cloud (cloud computing), that is, they value simplicity, avoiding as much as possible — or even prohibitions — reflection, all with the aim of supporting GraalVM (basically, natively compiled Java code).

The simplest way to start a project using Spring Boot is to Spring Initializr . Just select the desired options, the dependencies you would like to use and that's it: a zip file will be downloaded immediately to be imported into your IDE.

🐳 Container base image

When you are working in an enterprise environment, the project will likely be published in container image format, making it easier to deploy to a runtime environment like Docker or Kubernetes.

Here I suggest following the same version of Java that I recommend for installing locally: following the image of Eclipse Temurin , that is, eclipse-temurin:17for Java 17. Always be careful to keep your image up to date, as recommended with your dependencies.

Avoid using the image OpenJDK , as it is officially deprecated and no longer recommended for production.

🤓 How to stay up to date

This ecosystem will not stop bringing new things and you will need to stay up to date with everything that revolves around Java.

Some sources I use to stay up to date and learn from what has been happening in the community:

🔭 Next Steps

I hope this guide has been useful in helping you in some way and that it serves for a successful journey in the Java world. Either way, this guide is just the beginning. Depending on your needs and requirements, there are a huge amount of options to evaluate.

  • Build native binaries using GraalVM , which allows fast startup (a few milliseconds) and low memory consumption; very useful for cases where your application needs to initialize (scale) quickly, such as in AWS Lambda functions, command lines, etc.;

  • Study ways of integrating with other systems, especially at this microservices stage: sometimes you need to create an API (REST, synchronous), sometimes you need something asynchronous (message). Check the recommendation of the chosen framework, as it will certainly have some type of support for an API, be it REST or GRPC. The same goes for messages: Kafka, SQS/SNS, JMS, etc.;

  • Analyze the performance and runtime characteristics of your application using JDK Flight Recorder It is JDK Mission Control ;

  • Delve deeper into the world of automated testing, be unitary with the use of mocks ( Mockito will be a great ally), or integration with fewer mocks (which is great and can avoid many bugs, with testcontainers being the greatest ally). Automated testing should always be prioritized during the implementation of the functionality, nothing to leave for later (famous I'm done, just need to test it ). The time saved and the security that tests bring — as long as they are well written — is extremely important.

  • CI/CD: continuous integration (CI or continuous integration ) It is continuous deployment (CD or continuous delivery ) are terms that you also need to understand at least how they work. And nothing better than having your automated tests integrated into these pipelines to deliver versions as quickly as possible.
Was this content useful to you?
YesNo

Related posts