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
Java Best Practices
Good code follows certain rules, and knowing them increases your chances of success. We’d like to share some Java best practices that will help you on your way. We'll cover the must-know tips and tricks, from broad advice on software development to Java- and project-specific know-how. Let's get star…
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Profile Java and Kotlin Code with the IntelliJ Profiler
At JetBrains, we believe that profiling Java and Kotlin code 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 r…
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…