Skip to content

Commit dc6b618

Browse files
gselzerctrueden
authored andcommitted
Write a new README
1 parent d132cc5 commit dc6b618

File tree

1 file changed

+64
-31
lines changed

1 file changed

+64
-31
lines changed

README.md

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,62 @@
1-
# no-package-cycles-enforcer-rule
1+
[![](https://github.com/scijava/scijava-packages-plugin/actions/workflows/build-main.yml/badge.svg)](https://github.com/scijava/scijava-packages-plugin/actions/workflows/build-main.yml)
22

3-
[![Build Status](https://travis-ci.org/andrena/no-package-cycles-enforcer-rule.svg)](https://travis-ci.org/andrena/no-package-cycles-enforcer-rule)
3+
[![](https://img.shields.io/maven-central/v/org.scijava/scijava-packages-plugin.svg)](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.scijava%22%20AND%20a%3A%22scijava-packages-plugin%22)
44

5-
## About
5+
SciJava Packages Plugin
6+
====================
67

7-
This Maven Enforcer Rule checks your project for package cycles. It fails the build if any package cycle is found, showing you the packages and classes involved in the cycle.
8+
scijava-packages-plugin provides a set of [Maven Enforcer Plugin](https://maven.apache.org/enforcer/maven-enforcer-plugin/) rules for policing the package hierarchy at build time.
89

910
## Usage
1011

11-
Add the following plugin to your POM:
12+
Currently, the only way to utilize these rules is by explicitly declaring it in the life cycle
1213

1314
```xml
1415
<plugin>
15-
<artifactId>maven-enforcer-plugin</artifactId>
16-
<version>3.0.0-M2</version>
17-
<dependencies>
18-
<dependency>
19-
<groupId>de.andrena.tools.nopackagecycles</groupId>
20-
<artifactId>no-package-cycles-enforcer-rule</artifactId>
21-
<version>1.0.9</version>
22-
</dependency>
23-
</dependencies>
24-
<executions>
25-
<execution>
26-
<id>enforce-no-package-cycles</id>
27-
<goals>
28-
<goal>enforce</goal>
29-
</goals>
30-
<phase>test</phase>
31-
<configuration>
32-
<rules>
33-
<NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule" />
34-
</rules>
35-
</configuration>
36-
</execution>
37-
</executions>
16+
<artifactId>maven-enforcer-plugin</artifactId>
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.scijava</groupId>
20+
<artifactId>scijava-packages-plugin</artifactId>
21+
<version>0-SNAPSHOT</version>
22+
</dependency>
23+
</dependencies>
24+
<executions>
25+
...
26+
</executions>
3827
</plugin>
3928
```
4029

30+
Rules
31+
====================
32+
33+
# No Package Cycles
34+
[Circular dependencies](https://en.wikipedia.org/wiki/Circular_dependency) are usually considered poor practice. To prevent circular dependencies, add the following `execution`:
35+
36+
```xml
37+
<execution>
38+
<id>enforce-no-package-cycles</id>
39+
<goals>
40+
<goal>enforce</goal>
41+
</goals>
42+
<phase>test</phase>
43+
<configuration>
44+
<rules>
45+
<NoPackageCyclesRule
46+
implementation="org.scijava.packages.plugin.NoPackageCyclesRule" />
47+
</rules>
48+
</configuration>
49+
</execution>
50+
```
51+
4152
### Including test classes
4253

4354
If you want to exclude tests from cycle checking, you can use the parameter `includeTests` which is set to true by default:
55+
4456
```xml
4557
...
4658
<rules>
47-
<NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule">
59+
<NoPackageCyclesRule implementation="org.scijava.packages.plugin.NoPackageCyclesRule">
4860
<includeTests>false</includeTests>
4961
</NoPackageCyclesRule>
5062
</rules>
@@ -61,7 +73,7 @@ If you want to exclude packages or restrict check to certain packages only, you
6173
```xml
6274
...
6375
<rules>
64-
<NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule">
76+
<NoPackageCyclesRule implementation="org.scijava.packages.plugin.NoPackageCyclesRule">
6577
<includedPackages>
6678
<includedPackage>myapp.code.good</includedPackage>
6779
</includedPackages>
@@ -82,9 +94,30 @@ If you want to exclude packages or restrict check to certain packages only, you
8294
...
8395
```
8496

97+
98+
# No Subpackage Dependence
99+
Subpackage Dependence can throw a wrench into libraries wishing to follow the [Dependency Inversion principle](https://en.wikipedia.org/wiki/Dependency_inversion_principle). To prevent subpackage dependence, add the following `execution`:
100+
101+
```xml
102+
<execution>
103+
<id>enforce-no-subpackage-dependence</id>
104+
<goals>
105+
<goal>enforce</goal>
106+
</goals>
107+
<phase>test</phase>
108+
<configuration>
109+
<rules>
110+
<NoSubpackageDependenceRule
111+
implementation="org.scijava.packages.plugin.NoSubpackageDependenceRule" />
112+
</rules>
113+
</configuration>
114+
</execution>
115+
```
116+
117+
85118
## See also
86119

87-
* The original version by Daniel Seidewitz on [Stackoverflow](http://stackoverflow.com/questions/3416547/maven-jdepend-fail-build-with-cycles). Improved by showing all packages afflicted with cycles and the corresponding classes importing the conflicting packages.
120+
* The original version by Daniel Seidewitz on [Stackoverflow](http://stackoverflow.com/questions/3416547/maven-jdepend-fail-build-with-cycles). Improved by showing all packages afflicted with cycles and the corresponding classes importing the conflicting packages; this version was written [here](https://github.com/andrena/no-package-cycles-enforcer-rule). From there, the SciJava team made the behavior more extensible, making it easier to write and use more package-based rules.
88121
* [JDepend](https://github.com/clarkware/jdepend), the library being used to detect package cycles.
89122
* For more information about package cycles, see ["The Acyclic Dependencies Principle" by Robert C. Martin (Page 6)](http://www.objectmentor.com/resources/articles/granularity.pdf).
90123
* The [Maven Enforcer Plugin](https://maven.apache.org/enforcer/maven-enforcer-plugin/)

0 commit comments

Comments
 (0)