Interface DependencyVersionAware


public interface DependencyVersionAware
Implementing this interface allows a check to be executed - or not - during analysis, depending on the version of desired libraries among dependencies of the current module.

For example, if a rule is to be used only on modules of a project that use spring-web version at least 4.3, it should implement DependencyVersionAware with the following method:

  @Override
   public boolean isCompatibleWithDependencies(Functioninvalid input: '<'String, Optional> dependencyFinder) {
     return dependencyFinder.apply("spring-web")
       .map(v -> v.isGreaterThanOrEqualTo("4.3"))
       .orElse(false);
   }
 
  • Method Details

    • isCompatibleWithDependencies

      boolean isCompatibleWithDependencies(Function<String,Optional<Version>> dependencyFinder)
      Control whether the check is compatible with the dependencies of the project being analysed.
      Parameters:
      dependencyFinder - is a function that takes in the name of an artifact that may be found in the classpath of the project. It returns the version of that artifact that was detected, or an empty optional if it is not detected in the classpath. Note that we cannot guarantee that a dependency will always be detected in the case were the classpath doesn't come from a standard build system like maven or gradle.
      Returns:
      true if the check is compatible with the detected dependencies and should be executed on sources, false otherwise.