[英]How to check project boundaries access in Maven projects
I have a set of Maven projects and I'd like to define access rules. 我有一组Maven项目,我想定义访问规则。
For example, projects Database and Cache may only be accessed by project DataLayer, but not from project UiLayer. 例如,项目数据库和缓存只能由项目DataLayer访问,而不能从项目UiLayer访问。 I'm speaking in terms of maven projects, but a package level access verification may also work, as long as it's easy to integrate into maven projects.
我说的是maven项目,但是包级访问验证也可以工作,只要它很容易集成到maven项目中。
I've looked at Macker , which has a nice set of features such as access control b/w java packages, style checking etc, but have been having hard time tying that into a set of maven projects. 我看过Macker ,它有一套很好的功能,比如访问控制b / w java包,样式检查等,但是很难将它们绑定到一组maven项目中。
There's the macker-maven-plugin , which is still under development, and I've been able to make it work for me, but I'm afraid it's not going to serve me well. 还有macker-maven-plugin ,它仍在开发中,我已经能够让它为我工作,但我担心它不会很好地为我服务。
This plugin runs verifications on all project's classes. 该插件对所有项目的类进行验证。
This means that I'll have to have macker-rules.xml defining access rules in each and every maven project from now on in order to make sure rules are not broken. 这意味着我必须从现在开始在每个maven项目中定义macker-rules.xml来定义访问规则,以确保规则不被破坏。 This looks like a maintenance nightmare.
这看起来像是一场维护噩梦。
So - did I miss something with usage of macker-maven-plugin? 那么 - 我是否错过了使用macker-maven-plugin的东西? Perhaps I'm not using it correctly.
也许我没有正确使用它。
I have no experience with JDepend, but from short reading it looks like the thin version of macker. 我没有使用JDepend的经验,但从简短的阅读看起来它看起来像是macker的瘦版本。 There is a jDepend maven plugin , but it's functionality is merely generating reports about usage and statistics, but what I really need is something else, an access check which fails the build if it fails.
有一个jDepend maven插件 ,但它的功能只是生成有关使用情况和统计数据的报告,但我真正需要的是其他东西,如果失败则访问检查失败。
Can someone suggest a better alternative for project access checks or package access checks for maven projects? 有人可以为项目访问检查或maven项目的包访问检查提出更好的替代方案吗?
Thanks 谢谢
I think you are looking for banned dependencies from maven-enforcer-plugin . 我认为你正在寻找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>
如果将Maven项目拆分为子项目并正确构建API,则可能将访问约束实现为子项目依赖项的副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.