ivan
ivan

Reputation: 1

How can I pass all classes of a multimodule project to ArchUnit?

We have a gradle 4.10.2 + kotlin 1.9.0 (openjdk 11) + spring boot 2.6.1 project with many services in the repo. I want to introduce ArchUnit 1.4.0 checks - so that even the new services introduced into the repo fall under them immediately. To enforce onion architecture, forbid some annotations etc. Which means that manually listing all modules as test module's dependencies won't work.

I placed the tests in core module, package com.example.core, which most of other modules depend on. When I tried to ClassFileImporter().importPackages("com.example"), I got only classes from packages from core module.

I tried ClassFileImporter().importClasspath() and ran out of memory. Probably won't go this way.

I tried Reflections("com.example", Scanners.SubType).getSubTypesOf(Any::class.java) and got an empty result.

My next step would be, just leave these tests in core and import them into new modules manually... but if there is a way to feed all classes to ArchUnit automatically, I would try still.

Upvotes: 0

Views: 33

Answers (1)

Manfred
Manfred

Reputation: 3142

You can probably use the Société Générale's ArchUnit Gradle plugin to distribute and execute your ArchUnit rules in all modules (I however don't know whether it works with a Gradle version from 2018... 🙈) – or have some custom build logic to copy your ArchUnit tests to allprojects.

Upvotes: 0

Related Questions