简体   繁体   English

如何在Maven项目中检查项目边界访问

[英]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.

相关问题 Maven:如何将现有的 Maven 项目拆分为不同的项目? - Maven: How to split an existing maven project into different projects? Maven项目无法与其他项目一起使用 - Maven project not working with other projects 如何在Maven中的多个项目之间共享项目依赖项? - How to share project dependencies among multiple projects in Maven? 如何将 maven 父子项目设置为单独的项目? - How to setup maven parent and child project as separate projects? Maven项目与另一个Maven项目的依赖关系 - Maven project to another maven projects dependencies 如何切换maven项目? - How switch maven projects? 应该如何从Maven项目中引用非Maven项目 - How is one supposed to reference non-Maven projects from a Maven project 如何设置Jenkins从其他具有应用程序依赖关系的maven项目构建maven项目 - How to setup Jenkins to build an maven project from other maven projects with dependencies within the application 我的公司如何将罐子放入Maven回购中,以便Maven项目可以从内部访问它 - How does my firm get a jar into a maven repo so maven projects can access it from inhouse 在 Maven 中,在构建主项目时,如何构建作为依赖项添加到主项目中的依赖项目? - In Maven How to build the dependent projects that are added as the dependencies in the main project when building the main project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM