Skip to content

Commit 8f5fa90

Browse files
committed
Merge branch 'scijava-packages-rules'
This introduces an adapted version of the no-package-cycles-enforcer-rule project, plus a new NoSubpackageDependenceRule to foster healthy package dependencies. There are still some loose ends, but it's a functional starting point. Please note: this is a rather evil merge; sorry about that. But it was the easiest way forward while abiding by SciJava's release-ready integration branch rule (compiles with passing tests).
2 parents 537f6b1 + f8ca193 commit 8f5fa90

File tree

1,746 files changed

+24812
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,746 files changed

+24812
-49
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/.classpath
2+
/.idea/
23
/.project
34
/.settings/
45
/target/
5-
*.swp

NOTICE.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
========================================================================
2+
Portions of this project were adapted from no-package-cycles-enforcer-rule:
3+
https://github.com/andrena/no-package-cycles-enforcer-rule
4+
5+
Copyright 2013 - 2018 David Burkhart, Ben Romberg, Daniel Galan y Martins,
6+
Bastian Feigl, Marc Philipp, and Carsten Otto.
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
========================================================================
20+
121
This project contains files under the Apache 2.0 license, as follows:
222

323

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,123 @@ Alternatively, you can include the plugin explicitly in the life cycle:
111111
</plugin>
112112
</plugins>
113113
```
114+
115+
SciJava Packages Rules
116+
====================
117+
118+
scijava-packages-rules provides a set of [Maven Enforcer Plugin](https://maven.apache.org/enforcer/maven-enforcer-plugin/) rules for policing the package hierarchy at build time.
119+
120+
## Usage
121+
122+
Currently, the only way to utilize these rules is by explicitly declaring it in the life cycle
123+
124+
```xml
125+
<plugin>
126+
<artifactId>maven-enforcer-plugin</artifactId>
127+
<dependencies>
128+
<dependency>
129+
<groupId>org.scijava</groupId>
130+
<artifactId>scijava-packages-rules</artifactId>
131+
<version>0-SNAPSHOT</version>
132+
</dependency>
133+
</dependencies>
134+
<executions>
135+
...
136+
</executions>
137+
</plugin>
138+
```
139+
140+
Rules
141+
====================
142+
143+
# No Package Cycles
144+
[Circular dependencies](https://en.wikipedia.org/wiki/Circular_dependency) are usually considered poor practice. To prevent circular dependencies, add the following `execution`:
145+
146+
```xml
147+
<execution>
148+
<id>enforce-no-package-cycles</id>
149+
<goals>
150+
<goal>enforce</goal>
151+
</goals>
152+
<phase>test</phase>
153+
<configuration>
154+
<rules>
155+
<NoPackageCyclesRule
156+
implementation="org.scijava.packages.rules.NoPackageCyclesRule" />
157+
</rules>
158+
</configuration>
159+
</execution>
160+
```
161+
162+
### Including test classes
163+
164+
If you want to exclude tests from cycle checking, you can use the parameter `includeTests` which is set to true by default:
165+
166+
```xml
167+
...
168+
<rules>
169+
<NoPackageCyclesRule implementation="org.scijava.packages.rules.NoPackageCyclesRule">
170+
<includeTests>false</includeTests>
171+
</NoPackageCyclesRule>
172+
</rules>
173+
...
174+
```
175+
176+
### Restricting scope
177+
178+
**:warning: Only use this, if there is no other way! Once there are exceptions, the connection between those excluded packages
179+
will grow stronger and stronger, without notice!**
180+
181+
If you want to exclude packages or restrict check to certain packages only, you can use `includedPackages` or `excludedPackages` (although you really should not!):
182+
183+
```xml
184+
...
185+
<rules>
186+
<NoPackageCyclesRule implementation="org.scijava.packages.rules.NoPackageCyclesRule">
187+
<includedPackages>
188+
<includedPackage>myapp.code.good</includedPackage>
189+
</includedPackages>
190+
</NoPackageCyclesRule>
191+
</rules>
192+
...
193+
```
194+
195+
```xml
196+
...
197+
<rules>
198+
<NoPackageCyclesRule implementation="de.andrena.tools.nopackagecycles.NoPackageCyclesRule">
199+
<excludedPackages>
200+
<excludedPackage>myapp.code.bad</excludedPackage>
201+
</excludedPackages>
202+
</NoPackageCyclesRule>
203+
</rules>
204+
...
205+
```
206+
207+
208+
# No Subpackage Dependence
209+
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`:
210+
211+
```xml
212+
<execution>
213+
<id>enforce-no-subpackage-dependence</id>
214+
<goals>
215+
<goal>enforce</goal>
216+
</goals>
217+
<phase>test</phase>
218+
<configuration>
219+
<rules>
220+
<NoSubpackageDependenceRule
221+
implementation="org.scijava.packages.rules.NoSubpackageDependenceRule" />
222+
</rules>
223+
</configuration>
224+
</execution>
225+
```
226+
227+
228+
## See also
229+
230+
* 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.
231+
* [JDepend](https://github.com/clarkware/jdepend), the library being used to detect package cycles.
232+
* 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).
233+
* The [Maven Enforcer Plugin](https://maven.apache.org/enforcer/maven-enforcer-plugin/)

0 commit comments

Comments
 (0)