Analyzing Code Dependencies (part II)
When you have cleaned up unnecessary dependencies, you certainly don’t want them to appear again. But if you work in a team, this is very probable to happen. So, how to avoid illegal dependencies?
Of course, you can periodically analyze and clean up the code as it is described in Analyzing Code Dependencies (part I). But there is a simpler way.
For example, you need to separate UI and business layers of your application. Consider that you have the following simple project.
In our example, the dependencies from the com.sample.businesslogic package to com.sample.ui are illegal. To specify this rule, you need to take several steps.
First, analyze dependencies for the package, and click Edit Rules in the Dependency Viewer tool window.
Then add a new rule to the dependency validator.
Here ui and business are custom scopes. In this example, ui is defined by the following pattern:
The business scope simply includes the corresponding package:
When this rule is applied all illegal dependencies in the dependency viewer become red.
From the viewer you can navigate to the location of the illegal dependencies. But of course it would be much better to be notified that the dependency is illegal right when you create it.
For this purpose, IntelliJ IDEA provides the “Illegal package dependencies” code inspection. When switched on, it highlights illegal dependencies in the editor.
Now you can easily avoid illegal dependencies by sharing project settings between the members of your team.
Note This tip&trick was originally posted at www.javalobby.org.
Subscribe to Blog updates
Thanks, we've got you!
Profile on the Fly With the IntelliJ Profiler
At JetBrains, we believe that profiling should be simple and accessible to all developers, regardless of their level of expertise. That’s why the IntelliJ Profiler puts ease of use and seamless integration at the forefront of its mission. In previous releases, we introduced a range of features to s…
History of Gradle Delegation Process in IntelliJ IDEA
Nowadays, a build tool is an essential part of any project, and IntelliJ IDEA integrates with the majority of them. Among the most popular build tools is Gradle. We’d like to give a brief historical overview of its integration with IntelliJ IDEA and the delegation process implemented inside the I…
How to Work With Protobuf-Maven Projects in IntelliJ IDEA
Protobuf, short for Protocol Buffers, is a language-agnostic data serialization format developed by Google. It is designed to efficiently and reliably serialize structured data to communicate between different systems and programming languages. Protobuf offers a compact binary representation of data…
Turbocharge Lombok annotations with IntelliJ IDEA
If you’re a professional Java developer, you probably use IntelliJ IDEA as your IDE and Lombok as the framework that handles the Java boilerplate. What you probably didn’t know is that not only do these 2 technologies work well on their own, but when combined, they’re even more efficient than when u…