-
Notifications
You must be signed in to change notification settings - Fork 25
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
Configuration get's mixed up in multi module build #37
Comments
I am not familiar with FreezingArchRule as it's part of the ArchUnit core. I've never used it myself. @codecholeric do you have an idea about this ? is an archunit.properties file in each sub module supposed to work ? |
Hi, did you find any solution for this? I am also facing the same issue and its important for me to use FreezingArchRule feature. |
OK, so I tested this a bit, and I really think an issue should be open in https://github.com/TNG/ArchUnit because I don't think the problem is with the Maven plugin. Here's what I did in my multi-module project :
and here's what happens :
is it also what you observe in your case ? can you try to replicate without using the plugin, like I did ? |
No. I get only 1 violation in second module which belongs to that module only. So its as expected. |
Also, rule stores are created correctly if I use maven-surefire-plugin. |
OK, I think I've been able to reproduce the issue you're experiencing.. right now, I have no clue "why" though, so not sure if/when I can fix it.. |
I investigated, and found out few interesting things. As anticipated, there's not much we can do in the plugin which is mostly a wrapper around ArchUnit. By looking in ArchUnit code and in TNG/ArchUnit#389 (comment) , we find that :
Make sure filtering is enabled on test resources, and careful with the placeholder pattern (above, I use
@Override
public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection<String> excludedPaths) {
URL archUnitPropertiesUrl = getCurrentClassLoader(getClass()).getResource("archunit.properties");
if(archUnitPropertiesUrl!=null) {
Properties properties = new Properties();
try (InputStream inputStream = archUnitPropertiesUrl.openStream()) {
properties.load(inputStream);
} catch (IOException e) {
log.warn("Error reading ArchUnit properties from " + archUnitPropertiesUrl, e);
}
String pathToViolationsStore = properties.getProperty("freeze.store.default.path");
if (pathToViolationsStore != null) {
log.info("overriding violation store path to " + pathToViolationsStore);
ArchConfiguration.get().setProperty("freeze.store.default.path", pathToViolationsStore);
}
else{
log.warn("Could not find expected property, so using whatever value has been defined/overridden before");
}
}
else{
log.warn("Could not find expected property, so using whatever value has been defined/overridden before");
}
JavaClasses importedClasses = ArchUtils.importAllClassesInPackage(scopePathProvider.getMainClassesPath(),packagePath,excludedPaths);
ArchRule rule = FreezingArchRule.freeze(
// YOUR RULE HERE
)
);
rule.check(importedClasses);
} It's probably not the cleanest solution, but it should do the trick : on the multi-module project where I tested, I now get a violation store created in each module. Let me know if that fixes it for you, and/or if you have a cleaner solution. |
Summary
When using the arch-unit-maven-plugin in a multi module build together with
archunit.properties
file for each module, only thearchunit.properties
of the first module is loaded and used for all modules.Type of Issue
It is a :
Motivation
I try to use ArchUnit in a multi module build where some tests are using FreezingArchRule. On the first run they all should "freeze" the current violations to a store. One for each module as only the classes for that module are tested.
Current Behavior
When running a multi module build with the plugin activated in multiple modules, the ArchUnit tests for the first module read the
archunit.properties
for that module and create a new store for the freezed violations. The ArchUnit tests of the second module do not create their own new store but the existing one of the first module. This store is then emptied as the violations stored in it do not exist in the second module and the violations of the second module are not stored but cause the build to fail.Without setting the
freeze.store.default.path
the store is placed in the parent module of the two modules.I explicitly set the
freeze.store.default.path
to${project.basedir/archunit_store
to force the usage of a separate store for each module. But then the store is just placed n the first module but still used for every module. Apparently only the ArchUnit tests of the first module run by the plugin do read the configuration and those of the next module don't read their own configuration but use the one of the first.When running the same ArchUnit tests as JUnit5 tests using the maven-surefire-plugin, every module uses it's own
archunit.properties
. But that way causes other inconveniences as it is harder to reuse the same rules for multiple modules and mixes architecture tests with unit tests.Expected Behavior
For each module in a multi module build, its own
archunit.properties
and a separate store for freezing should be used.Steps to Reproduce (for bugs)
my
archunit.properties
insrc/test/resources
of each module (filterung in activated):My plugin configuration in the parent pom:
Your Environment
The text was updated successfully, but these errors were encountered: