Kiwi is a utility library. It contains a variety of utilities that we have built over time and find useful. In general, we look first to either Google Guava or Apache Commons for utilities, but if they don't have something we need, or if what they have isn't exactly what we want, then we'll (probably) add it here.
Almost all the dependencies in the POM have provided scope, so that we don't bring in a ton of required dependencies. This downside to this is that you must specifically add any required dependencies to your own POM in order to use a specific feature in Kiwi.
The only required dependencies are guava, commons-lang3, and slf4j-api. If you use the Maven Enforcer plugin, you could therefore run into dependency convergence errors if the kiwi versions are different from the ones you're using.
As of kiwi 3.4.0, the validation annotations in the org.kiwiproject.kiwi.validation
package use Java's
ServiceLoader mechanism.
The constraint implementations are defined in META-INF/services/jakarta.validation.ConstraintValidator
and
the validation message bundle is located in ContributorValidationMessages.properties
. This allows kiwi to
provide its custom constraints without interfering with an application that defines its own constraints and
message bundle in its own ValidationMessages.properties
.
The Hibernate Validator reference guide describes this in Constraint definitions via ServiceLoader. Another good resource is Adding custom constraint definitions via the Java service loader.
If you are using kiwi's custom constraints in addition to custom constraints provided by another library, then
this requires some additional configuration, otherwise only one of the ContributorValidationMessages.properties
provided by each library will be found, and therefore the custom messages for some constraints won't be found
during validation. To fix this, all ContributorValidationMessages.properties
files must be combined into a
single file, for example, using the Maven Shade plugin and an
AppendingTransformer:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>ContributorValidationMessages.properties</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
With this additional build step, multiple libraries can each provide custom constraints.