F E A R

Many lives are rooted in fear due to Governments, Societal Manipulations and most of all, evil. Our enemies are not flesh and blood; not man. Satan and the demons(evil spirits) coerce minds by…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Do I really need this dependence on my pom?

After Maven coming up to our projects, managing dependencies or controlling versions of the libraries is very easy. Just add the library to the project pom.xml and you’re done: you can use everything that’s made available. It’s been a long time I’ve noticed that several developers add dependencies to Maven projects in order to suppress lines of code or get features without even thinking about whether they really are needed. For example, in some cases I have seen the StringUtils class of the apache commons-lang3 project be used only to check if a String is null or empty with the isEmpty() method.

Analyzing the code, we have: “cs == null || cs.length () == 0”. That is, to perform a simple check, which could be done without using any external dependencies, we added 470KB (library size) to our application.

Now imagine that we are developing a JavaEE application on Wildfly, for example. We added the dependency to the pom.xml of our project and generated the .war.

Without dependency, we have WAR with 4 KB:

With dependency with compile scope, we have a WAR with 282 KB:

We added approximately 278 KB to our application just by using the StringUtils class to check if the specified String is null or empty.

Do we really need this?

Oh, but we can add the library in Wildfly as a module, change the scope in pom.xml to provided and it’s alright! Is that really all right ?!

Imagine a coworker taking the project to perform some bug fix. It downloads Wildfly from the official website, and when running the application, an error message is posted saying that the commons-lang3 dependency was not found:

Now your coworker will have to dedicate time to configuring dependency on the server to run the application. Thus, the primary task of fixing a bug in the application becomes secondary to the need to configure the dependency on the server.

Alternatively, he may choose to change the scope of the library to compile and fix the bug. However, if, for any reason, this change is not undone after the bug has been corrected, the pom.xml commit can be executed and there goes an application with unnecessary 278 KB

Even before we think about adding some external dependency in our project, let’s think about the Java API itself. Does not it provide the functionality we need?

I do not mean that we should never use external dependencies in design, even though there are many encapsulate complexities that give us productivity gains; but I suggest we could think: do I really need this dependence on my pom?

Add a comment

Related posts:

Pride Can Pressure LGBTQ Kids Who Need Support to Thrive

It absolutely is for me and most of my queer family. But did you know many closeted LGBTQ folks feel left out, dejected, and pressured when June rolls around? For many, Pride season is a reminder of…

How to find speakers for your meetup?

As a Tech Evangelist, one of my strategy of choice to make Stylight known in the local tech ecosystem is to organize meetups. A lot of them. During the last 2 years, I created around 15+ meetups…

Not Me

This is how I show appreciation.