views:

86

answers:

2

I have a set of Maven projects and I'd like to define access rules.
For example, projects Database and Cache may only be accessed by project DataLayer, but not from project 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.

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.

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.
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. This looks like a maintenance nightmare.

So - did I miss something with usage of 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. 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.

Can someone suggest a better alternative for project access checks or package access checks for maven projects?

Thanks

A: 

If you split your Maven project into subprojects and structure the APIs right, it might be possible to implement your access constraints as a side-effect of the subproject dependencies.

Stephen C
+1  A: 

I think you are looking for banned 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>
cetnar
The enforcer plugin is nice. It's still a bit cumbersome in its definitions, but it's more or less what I was looking for, so thanks.It's cumbersome when I want to say "Allow DataLayer project access the Cache project, but disallow any other project accessing the Cache". So I can do that by a combination of excludes at the top pom and includes in the DataLayer pom, but it's not the most user friendly approach.
Ran
@Ran You're right. What I can suggest is place most common configuration in pluginManagment section. For other cases override it in individual poms.
cetnar