Last year we added the ability to create Dependency Checks - rules about what parts of your code can depend on other parts. Now those checks can be automatically run as part of the Background CodeChecks. Instantly discover if you are inadvertently violating your team's architectures. This article shows an example of automating those Checks.


Our team recently decided that none of our API code should rely on our User Interface code (UI). So to set this up, first, we need to create our dependency rules.  I access the options from Checks->Configure Dependency Checks.  Then select the api architecture/folder and check the "can't depend on" box and select the ui architecture/directory.


Notice that two checks show at the bottom for each rule that is created, this is because references go both ways. For details on creating more complicated Dependency Checks refer to the help documentation.


Saving and running these checks shows that we currently have a whole bunch of violations of this rule. Understand identified 124 references in the code that would need to be modified to remove all of those dependencies.



We can use the graph and dependency browser to easily find all of these violations, but that's going to take a little while to clean up. What we want to do in the meantime is ensure that no new violations get added. Stop the problem from getting worse!


From the top-level menu click Checks->Select Checks. This lets you create CodeCheck Configurations to run against your code. You can add this rule to an existing configuration if your team uses one, or hit the + button to make a new configuration. First, select Run Automatically in the background from the top of the list. You will see the new Dependency Rule we created down at the bottom of the list of checks. Select it as well.


Now whenever someone on the team accidentally adds something to API that depends on the UI, they will get a warning in the editor!


We've also added this rule to our company coding standard and set up DevOps with Understand to email the violations if they commit the code like this. Now we can start fixing the existing dependencies without worrying that new ones are getting added.