How to check access to project boundaries in Maven projects

I have a set of Maven projects and I would like to define access rules.
For example, Database and Cache projects can only be accessed by Project DataLayer, but not from a UiLayer project. I speak from the point of view of maven projects, but access at the package level can also work if it is easily integrated into maven projects.

I looked at Macker , which has a nice set of features like access control b / w java packages, style checking, etc., but it was difficult for them to associate this with a set of maven projects.

There is a macker-maven-plugin , which is still under development, and I was able to get it to work for me, but I am afraid that this will not serve me well.
This plugin runs checks for all classes of projects.
This means that I will have to have macker-rules.xml defining the access rules in every maven project from now on to make sure that the rules are not violated. This seems like a nightmare to service.

So - am I missing something using macker-maven-plugin? Perhaps I am not using it correctly.

I have no experience with JDepend, but from a short reading it looks like a thin version of macker. There is a jDepend maven plugin , but its functionality is just generating usage and statistics reports, but I really need something else, access check if the assembly fails to build if it does not work.

Can anyone suggest a better alternative for checking access to a project or checking access to packages for maven projects?

thank

+3
source share
2 answers

I think you are looking for forbidden dependencies from maven-enforcer-plugin .

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.0</version>
    <executions>
      <execution>
        <id>enforce-banned-dependencies</id>
        <goals>
          <goal>enforce</goal>
        </goals>
        <configuration>
          <rules>
            <bannedDependencies>
              <excludes>
                <exclude>org.apache.maven</exclude>
                <exclude>org.apache.maven:badArtifact</exclude>
                <exclude>*:badArtifact</exclude>
              </excludes>
              <includes>
                <!--only 1.0 of badArtifact is allowed-->
                <include>org.apache.maven:badArtifact:1.0</include>
              </includes>
            </bannedDependencies>
          </rules>
          <fail>true</fail>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
+1
source

Maven API, , .

0

Source: https://habr.com/ru/post/1727346/


All Articles