Breaking Changes
- As mentioned in Enhancements/Core
ArchRules
will now by default reject evaluating if the set passed to theshould
-clause is empty. This will break existing rules that don't check any elements in theirshould
-clause. You can restore the old behavior by setting the ArchUnit propertyarchRule.failOnEmptyShould=false
Bug Fixes
- Fix wrong origins of
JavaCall
in case of bridge methods. If a class had two methods with the exact same name and parameter types theorigin
of aJavaCall
was picked randomly from them. It now always picks the non-synthetic method (see #513) - Fix non-deterministic return value of
JavaCodeUnit.getMethod()
. In case of bridge methods there might be more than one method matching the exact same name and parameters. In these cases the result ofgetMethod()
was random. It now always picks the non-synthetic method (see #256) layeredArchitecture()
will now allow to combinemayOnlyBeAccessedBy...
andmayOnlyAccess...
. PreviouslymayOnlyAccess...
would forbid all incoming dependencies (see #739; thanks a lot to @hankem)
Enhancements
Core
- Members targeted by
AccessTarget
are now resolved like the Java Reflection API would do it. PreviouslyAccessTarget.resolve()
would return a set of matching members, the new replacementAccessTarget.resolveMember()
returns an optional member making it a lot easier to handle (see #722) JavaClass
now knows itsmethodReferencesFromSelf
(e.g.Object::toString
) andconstructorReferencesFromSelf
(e.g.Object::new
) (see #215; thanks a lot to @KorSin)ArchRules
will now by default reject evaluating if the set passed to theshould
-clause is empty. This prevents implementation errors like picking a package inthat()...
that doesn't even exist and thus composing a rule that doesn't check anything (compare the user guide; see #774; thanks a lot @oberprah)- The automatic import dependency resolution now resolves classes missing from the import that are only referenced
- as class object (e.g. Foo.class)
- in a throws clause (e.g.
someMethod() throws FooException
) - in an instanceof check (e.g.
obj instanceof Foo
) - as an array component type (e.g.
Foo[] array;
) - as an annotation parameter (e.g.
@SomeAnnotation(type = Foo.class)
) - as part of a generic type signature (e.g.
List<? extends Foo>
) - Furthermore, the resolution behavior can now be tweaked to resolve deeper or not resolve at all. Thus, users can decide between resolving additional types and performance (compare the user guide; see #728)
- New predefined
ImportOption
to excludepackage-info.class
files (see #793; thanks a lot to @TomerFi)
Lang
- Analogously to
classes()
, there now exists a methodmembers()...should().containNumberOfElements(predicate)
(see #179; thanks a lot to @oberprah)
Library
PlantUmlArchCondition
now rejects files that don't specify any components at all or are of an invalid format (see #735; thanks a lot to @pfichtner)
JUnit
- Tests can now be run if their classes are loaded by the context
ClassLoader
instead of the ArchUnitClassLoader
(see #781; thanks a lot to @stuartwdouglas) - New method
Class<?> FieldSource.getJavaClass()
to retrieve the declaring class of the respective field (see #800; thanks a lot to @famod)
Further Acknowledgement
- thanks a lot to @marknp for improving the Javadoc on
ArchConditions
(see #725) - thanks a lot to @timtebeek for making the ArchUnit build work with JDK 17 (see #779)