Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multiple archunit.properties files #389

Closed
JCook21 opened this issue Jun 29, 2020 · 3 comments
Closed

Using multiple archunit.properties files #389

JCook21 opened this issue Jun 29, 2020 · 3 comments

Comments

@JCook21
Copy link

JCook21 commented Jun 29, 2020

Firstly, thank you for the fantastic library. ArchUnit is great tool and I'm really enjoying using it.

I'm currently introducing and championing ArchUnit in a very large (e.g. multi million lines of code, many modules) app. A colleague of mine asked me this morning about out of memory problems he's getting with ArchUnit. My suspicion is that this is due to the library resolving all of the dependencies of the code he is testing. For some tests we want to use ArchUnit to enforce conventions on large amounts of code, such as my colleague is doing, and for these we will not want to resolve all dependencies to keep memory usage under control. For other tests we want to test the architecture of smaller sections of the codebase and for these we will want to resolve all of the dependencies. It seems that we would need different configuration for each of these different types of tests.

What would be the best way to achieve the above use cases? Is it possible to use multiple archunit.properties files in different modules? Would you consider adding that as a feature if not? Is a better solution to subclass the ClassFileImporter() and make the customizations there? Would using an import option work here also or would that not reduce the memory usage? Thanks in advance for any advice you have on this.

@codecholeric
Copy link
Collaborator

I have used ArchUnit in very large code bases, so I can try to give you some pointers of how I went for it. I still configured sth. like 8GB heap to import around 50000 classes with dependencies 😉
One important thing also when considering the heap is the size of error messages. I.e. really test that the pure import of classes ( classFileImporter.import... ) causes the out of memory error. Because in large code bases it is also easy to have a vast amount of violations for a single ArchRule and I had OOM errors just because the error message to report busted the heap.
If you say you don't need the dependencies in some cases, also compare https://www.archunit.org/userguide/html/000_Index.html#_configuring_the_resolution_behavior. This describes how to configure whether ArchUnit tries to load further dependencies from the classpath (and also control which classes to analyse you import via import options / packages).

As for your second question about different configurations: First of all, ArchUnit will always use the archunit.properties that is first within the classpath (for the respective ContextClassLoader or the current ClassLoader if not set).
However, there are ways to override whatever is read from the actual archunit.properties file. One is via system property, compare https://www.archunit.org/userguide/html/000_Index.html#_overriding_configuration
The other is, that you can also at any time access the configuration programmatically and override properties, e.g.

ArchConfiguration.get().setResolveMissingDependenciesFromClassPath(false);

Note that this is one central configuration though, so if you use JUnit, it might make sense to add a JUnit 4 Rule / JUnit 5 extension to set the property before the test runs and reset it afterwards to avoid influencing other tests.
Does this help you?

@JCook21
Copy link
Author

JCook21 commented Jul 2, 2020

@codecholeric awesome, thanks so much for your reply and suggestions. I'm off for a few days right now but I'll try out these suggestions when I'm back at work.

@codecholeric
Copy link
Collaborator

I'll close this issue for now, feel free to reopen it if you have follow up questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants