societe-generale / arch-unit-maven-plugin Goto Github PK
View Code? Open in Web Editor NEWA maven wrapper around ArchUnit, to easily share and enforce architecture rules across projects
License: Apache License 2.0
A maven wrapper around ArchUnit, to easily share and enforce architecture rules across projects
License: Apache License 2.0
Hi,
We would like to suggest a feature allowing us to exclude certain rules from a configured rule "package".
It is a :
We enforce certain architecture rules across various projects. Those are part of a platform used by said projects. Those rules are static fields contained in a single class so that we only have to include a single rule.
configurableRules>
<configurableRule>
<rule>our.custom.Rules</rule>
</configurableRule>
</configurableRules>
This is working for 90% of our use cases. However, we have some projects that are doing things slightly different and need to exclude some of those rules. Let's assume that we have rules A, B and C and only C should not be applied. The projects in question can now configure those checks explicitly:
configurableRules>
<configurableRule>
<rule>our.custom.Rules</rule>
<checks>
<check>A</check>
<check>B</check>
</checks>
</configurableRule>
</configurableRules>
This has two disadvantages:
Thus we would like to exclude certain checks from the rule set, like a negation of the check property.
configurableRules>
<configurableRule>
<rule>our.custom.Rules</rule>
<excludedChecks>
<excludedCheck>C</excludedCheck>
</excludedChecks>
</configurableRule>
</configurableRules>
Either the whole rule set is executed or the given checks.
It should be possible to exclude single checks from the rule set.
Thank you and best regards
Nils
The README still specifies the minimum arch-unit-build-plugin-core
version as SOME_VERSION_GREATER_THAN_2.3.0
. It should be updated to SOME_VERSION_GREATER_THAN_2.6.0
.
Ideally the major version of the arch-unit-build-plugin-core
should be incremented for every breaking change.
It is a :
I have my lib called arch-rules with my rules like this:
@ArchTest
public void layerController(JavaClasses javaClasses) {
layeredArchitecture()
.consideringAllDependencies()
.layer(CONTROLLER).definedBy(CONTROLLER_PACKAGE)
.layer(SERVICE).definedBy(SERVICE_PACKAGE)
.layer(REPOSITORY).definedBy(REPOSITORY_PACKAGE)
.layer(MAPPER).definedBy(MAPPER_PACKAGE)
.whereLayer(CONTROLLER).mayNotBeAccessedByAnyLayer()
.allowEmptyShould(true)
.check(javaClasses);
}
I added this library in another internal lib called parent as a dependency
I have my service with my parent lib as a dependency
In my service I have this test:
@AnalyzeClasses(packages = "my package", importOptions = ImportOption.DoNotIncludeTests.class)
public class ProductionScopeArchTest {
@ArchTest
static final ArchTests validateProdScope = ArchTests.in(ArchValidationProdScopeTest.class);
}
My question is:
How can run my arch tests in the maven build and remove this test class and pass my package in the plugin? because for the moment, I need create this test class for all my services that I want apply the rules. Is it possible or Did I understand wrong the goal of the plugin?
Thank you!
Currently every analyzed class is logged via INFO log level, looking like this:
[INFO] --- arch-unit-maven-plugin:1.0.2:arch-test (default) @ com.company.foobar ---
[INFO] Analysing class 'com/foo/class1'
[INFO] Analysing class 'com/foo/class2'
[INFO] Analysing class 'com/foo/class3'
[INFO] Analysing class 'com/foo/class4'
That is way to much, since INFO is the standard maven console log level. Please change that to DEBUG or similar. Other maven plugins do not output anything in case of working correctly or just the number of affected artifacts.
Grouped Tests of type ArchTests (instead of ArchRule) are not picked up by the maven plugin
@ArchTest
public static final ArchTests TESTS_SUITE = ArchTests.in(RulesLibrary.class);
It is a :
When executing this test the maven plugin do not load CODING_RULES ; only MY_RULE
@AnalyzeClasses( packages = xxx, importOptions = xxx)
public class GroupedTest {
@ArchTest
public static final ArchTests TESTS_SUITE = ArchTests.in(CodingRulesLibrary.class);
@ArchTest
public static final ArchRule MY_RULE = classes().xxx ;
}
Tests inside CodingRulesLibrary.class
must be executed
Try to run Tests grouped with ArchTests.in
Currently the predefined rules are also scanning class files in generated-sources
, which I have no control over. Is there a way to configure the plugin to ignore generated-sources
?
It is a :
I don't have any control over the class files generated in generated-sources
, thus have no way to resolve violations in the generated class files.
Starting the build via mvn clean
you will get a number of WARNING's about deprecated properties etc.
You will face the following WARNINGs:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.societegenerale.commons:arch-unit-maven-plugin:maven-plugin:2.2.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 187, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-javadoc-plugin is missing. @ line 204, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-resources-plugin is missing. @ line 280, column 21
[WARNING] The expression ${build.directory} is deprecated. Please use ${project.build.directory} instead.
[WARNING] The expression ${build.directory} is deprecated. Please use ${project.build.directory} instead.
[WARNING] The expression ${build.directory} is deprecated. Please use ${project.build.directory} instead.
[WARNING] The expression ${build.directory} is deprecated. Please use ${project.build.directory} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
It is a :
A maven build should be without any WARNING.
The build should be without any WARNING.
There are two classes inside target/generated-sources/api/src/main/java
matching my ArchUnitRul that I'd like to filter.
In my multi-module project, I used this in the parent-pom as well as the sub-module pom.xml:
<excludedPaths>
<excludedPath>generated-sources</excludedPath>
</excludedPaths>
But I get below error. Unfortunately, I cannot tell which of my classes causes the exception.
It is a :
classes()
.that().areAnnotatedWith(RestController.class)
.should().bePackagePrivate()
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit</artifactId>
<version>0.23.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.societegenerale.commons</groupId>
<artifactId>arch-unit-maven-plugin</artifactId>
<version>2.9.2</version>
<configuration>
<excludedPaths>
<excludedPath>generated-sources</excludedPath>
</excludedPaths>
<rules>
<configurableRules>
<configurableRule>
<rule>foo.bar.ArchUnitRules</rule>
<applyOn>
<packageName>foo.bar</packageName>
<scope>main</scope>
</applyOn>
<checks>
<check>FOO</check>
</checks>
</configurableRule>
<configurableRule>
<rule>foo.bar.ArchUnitRules</rule>
<applyOn>
<packageName>foo.bar</packageName>
<scope>test</scope>
</applyOn>
<checks>
<check>BAR</check>
</checks>
</configurableRule>
</configurableRules>
</rules>
</configuration>
<executions>
<execution>
<id>arch-test</id>
<goals>
<goal>arch-test</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
mvn -e test
[ERROR] Failed to execute goal com.societegenerale.commons:arch-unit-maven-plugin:2.9.2:arch-test (arch-test) on project foo: String index out of range: -1 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.societegenerale.commons:arch-unit-maven-plugin:2.9.2:arch-test (arch-test) on project foo: String index out of range: -1
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:274)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:196)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:160)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.mvndaemon.mvnd.builder.SmartBuilderImpl.buildProject(SmartBuilderImpl.java:178)
at org.mvndaemon.mvnd.builder.SmartBuilderImpl$ProjectBuildTask.run(SmartBuilderImpl.java:198)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.apache.maven.plugin.MojoFailureException: String index out of range: -1
at com.societegenerale.commons.plugin.maven.ArchUnitMojo.execute(ArchUnitMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:271)
... 11 common frames omitted
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.base/java.lang.String.substring(String.java:1837)
at com.societegenerale.commons.plugin.service.JavaFileParser.extractClassName(JavaFileParser.java:124)
at com.societegenerale.commons.plugin.service.JavaFileParser.parse(JavaFileParser.java:44)
at com.societegenerale.commons.plugin.service.ExcludedPathsPreProcessor.determineClassNames(ExcludedPathsPreProcessor.java:194)
at com.societegenerale.commons.plugin.service.ExcludedPathsPreProcessor.processExcludedPaths(ExcludedPathsPreProcessor.java:65)
at com.societegenerale.commons.plugin.service.RuleInvokerService.<init>(RuleInvokerService.java:49)
at com.societegenerale.commons.plugin.maven.ArchUnitMojo.execute(ArchUnitMojo.java:94)
... 13 common frames omitted
See: #44
No exception, and generated code filtered.
See above
Back when I played around with the code to adjust the behavior of configurable rules, I started to get the impression, that the handling of preconfigured rules could be unified (and thus simplified).
Also the naming seemed slightly inconsistent now, for predefined rules, a <rule>
is a single ArchRule
, for configurable rules, <rule>
is the class where the rules are contained and <check>
is a single ArchRule
. I know it would break the syntax, but I would still propose the following adjustments.
If you look at <configurableRule>
it has all the necessary infrastructure to execute predefined rules as well. I could imagine to just declare a class
public class PreconfiguredRules{
static final ArchRule do_not_write_to_standard_streams = ...;
static final ArchRule do_not_use_PowerMock = ...;
}
Then simply adjust the POM configuration
<rules>
<preConfiguredRules>
<rule>do_not_write_to_standard_streams</rule>
<rule>do_not_use_PowerMock</rule>
</preConfiguredRules>
</rules>
And the rest of the infrastructure is already there, because that's exactly how configurable rules are evaluated (would probably need to add some meta data for scope though, so a little more is needed). As a benefit you would not need any boiler plate like the extra interface all preconfigured rules have to implement at the moment, and future extensions would be limited to the very bare minimum, adding an ArchRule
field to PreconfiguredRules
. As far as I saw from comments on PRs, this would eliminate the confusion of how to import which path and how to test the execute(..)
method.
To be consistent with <predefinedRule>
I would suggest to rename the tag the specifies where the rules are declared to either <ruleLocation>
or <declaringClass>
.
Then the configurable rules could be defined like
<rules>
<configurableRules>
<ruleSet>
<ruleLocation>com.mylibrary.MyCustomArchRules<ruleLocation>
<rules>
<rule>my_custom_rule_one</rule>
<rule>my_custom_rule_two</rule>
</rules>
</ruleSet>
</customRules>
</rules>
A little fuzzy about the extensive plurals ๐ Because in the end the child of <condigurableRules>
is a plural again because it can house many <rules>
.
What do you think? I would be willing to contribute / pitch in a PR if you're open to this, but I realize that it would be a major version upgrade since it would break the existing syntax of clients.
when run maven in multi-thread, it warns 'The following plugins are not marked@threadSafe'
if this plugin is thread safe, I think the solution is just add threadSafe=true as following
@mojo(... threadSafe=true)
It is a :
to support multi-thread without warning msg
warn msg
no warning msg
run a multi module maven project in multi-thread mode
Regarding #17 it would be nice to have something like
<failOnPriority>LOW|MEDIUM|HIGH</failOnPriority>
to let the rules run, check, but give warnings instead of errors if the failOnPriority
is set higher than the rules priority.
It is a :
#17 allows skipping a certain rule which allows adding new rules to the ArchUnit Maven Plugin configuration for a large set of artifacts: you could just skip the rule in all artifacts where it doesn't pass (at the moment).
But normally what you don't see is hard to remember, so it would be nice to run the rule, see the problem but still have the build passing.
You can either skip a rule or stick to it with all the consequences like failing builds.
Allow successful builds even if a rule fails.
ArchUnit has the priority available for the rules - is it used somewhere? Normally I would expect that you could define a certain level (like with logging) and rule violations above that level make the build fail and rule violations below that level appear as warnings.
What's your opinion? And would you rather add it to ArchUnit and make it available here (maybe with the same problems like the configuration file as mentioned in #13 ) or would you completely add the functionality here in the Maven plugin? Or even not at all? ;-)
It is a :
Not possible to set a custom store for the freezing rule
possibility to use a custom store via the maven plugin
When using the arch-unit-maven-plugin in a multi module build together with archunit.properties
file for each module, only the archunit.properties
of the first module is loaded and used for all modules.
It is a :
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.
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.
For each module in a multi module build, its own archunit.properties
and a separate store for freezing should be used.
my archunit.properties
in src/test/resources
of each module (filterung in activated):
freeze.store.default.path=${project.basedir}/archunit_store
freeze.store.default.allowStoreCreation=true
My plugin configuration in the parent pom:
...
<modules>
<module>mod1</module>
<module>mod2</module>
</modules>
...
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
...
<plugins>
...
<plugin>
<groupId>com.societegenerale.commons</groupId>
<artifactId>arch-unit-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<!--force current "target" as project path for submodules -->
<projectPath>${project.build.directory}</projectPath>
<excludedPaths>playground</excludedPaths>
<rules>
<preConfiguredRules>
...
</preConfiguredRules>
<configurableRules>
<configurableRule>
<!-- ArchUnit test using freezing -->
<rule>my.project.architecture.MainClassesArchTest</rule>
<applyOn>
<scope>main</scope>
</applyOn>
</configurableRule>
<configurableRule>
<rule>my.project.architecture.TestClassesArchTest</rule>
<applyOn>
<scope>test</scope>
</applyOn>
</configurableRule>
</configurableRules>
</rules>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>arch-test</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugins>
...
</build>
Classes under excluded paths are checked by configurableRules.
It is a :
It's the first time that i'm using arch-unit-maven-plugin so maybe it's not a bug but a misconfiguration.
Classes under excluded paths are checked by configurableRules. I have a multi module maven projekt and one of the sub modules generates classes in the folder generated-sources\annotations\my.packages which are checked by a configurable rules.
Classes under excluded path are ignored by configurableRules.
this is the plugin configuration in my main pom:
<plugins>
<plugin>
<groupId>com.societegenerale.commons</groupId>
<artifactId>arch-unit-maven-plugin</artifactId>
<version>2.4.0</version>
<configuration>
<projectPath>${project.basedir}/target</projectPath>
<!-- optional - you can exclude classes that have a path containing any of the mentioned paths -->
<excludedPaths>
<excludedPath>generated-sources</excludedPath>
</excludedPaths>
<rules>
<!-- using a rule available out of the box... -->
<preConfiguredRules>
<rule>com.societegenerale.commons.plugin.rules.NoPublicFieldRuleTest</rule>
<rule>com.societegenerale.commons.plugin.rules.NoStandardStreamRuleTest</rule>
<rule>com.societegenerale.commons.plugin.rules.NoJodaTimeRuleTest</rule>
<rule>com.societegenerale.commons.plugin.rules.NoPrefixForInterfacesRuleTest</rule>
</preConfiguredRules>
<!-- ... and a custom one, coming from a dependency of the plugin -->
<configurableRules>
<configurableRule>
<rule>com.tngtech.archunit.library.GeneralCodingRules</rule>
<applyOn>
<packageName>my.packages</packageName>
<!-- scope can be "main" or "test" -->
<scope>main</scope>
</applyOn>
<checks>
<!-- otherwise you can specify either field or method names here. If no checks block is defined, all are executed -->
<!-- <check>NO_CLASSES_SHOULD_ACCESS_STANDARD_STREAMS</check>-->
</checks>
</configurableRule>
</configurableRules>
</rules>
</configuration>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>arch-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Some test scenarios rely on Main and Test classes as well. Is there a way to configure the scope for both? I guess no, because documentation says
<!-- scope can be "main" or "test" -->
It is a :
For example have a look on this rule from GeneralCodingRules
https://github.com/TNG/ArchUnit/blob/43fe9e28f01ba0c781f56fed75977e62251f08e5/archunit/src/main/java/com/tngtech/archunit/library/GeneralCodingRules.java#L434C33-L434C33
It requires Main and Test classes loaded together to compare them and tell if there is a violation.
I can't get this Rule running as intended with this Plugin. However, if i run the Rule as JUnit Test without the Plugin and import Main and Test classes, it works as expected:
@Test
public void testClassesShouldResideInTheSamePackageAsImplementation() {
JavaClasses myClasses = new ClassFileImporter().importPaths("target/classes", "target/test-classes");
com.tngtech.archunit.library.GeneralCodingRules.testClassesShouldResideInTheSamePackageAsImplementation().check(myClasses);
}
If no source files are found in a module of a multi module project, no analysis should be done (e.g. in modules which just assemble war files or docker images).
It is a :
The plugin is used in a multi module project and defined in the root POM. Some of our modules only contain test code (integration tests) or they don't contain any java code at all (e.g. modules for building docker images). When building these modules the plugin adds all possible directories for analysis and therefore analyses the whole classpath of our application (including 3rd party libs). Unfortunately this behavior can't be switched off and the plugin definition has to be overridden in the client modules.
It would be very helpful to have the possibility to switch off this behavior in the plugin configuration.
If you use POM modules, the ArchUnit Maven Plugin does not search the correct path.
It is a :
If you have your project separated into different modules and define ArchUnit Maven Plugin in the root, then the module classes are not scanned.
It looks like ArchUnit Maven Plugin by default searches ./target
if you don't specify another directory in the plugin's configuration.
IMO the plugin should always use the configured values for build directory, output directory and test output directory.
This would not only allow to use the plugin with module builds but also allow using the -f
switch of Maven (which currently also seems to break the ArchUnit Maven Plugin).
mvn clean verify
Using Maven 3.6.1 and the plugin's newest 2.2.0 release.
When there are some errors, however noFailOnError is set to true. It should log errors as Warning, so that developers will actually see it.
It is a :
When there are some validation errors, and the property noFailOnError, an error is logged on the info level. Thus, it can be easily lost, instead it should be logged as warning. This way it would bring attention.
Change is trivial, should be done on the line:
When there are some validation errors, it is logged as info:
[INFO] Merging properties: The following properties have been overwritten by system properties: {noFailOnError=true}
[INFO] applying rules on 12 classe(s). To see the details, enable debug logs
SKIPPED
[INFO] ArchUnit Maven plugin reported architecture failures listed below :Rule Violated - SKIPPED
[INFO]
When there are some validation errors, it should be logged as warning:
[INFO] Merging properties: The following properties have been overwritten by system properties: {noFailOnError=true}
[INFO] applying rules on 12 classe(s). To see the details, enable debug logs
SKIPPED
[WARNING] ArchUnit Maven plugin reported architecture failures listed below :Rule Violated - SKIPPED
[INFO]
Set property true
Make sure there are some validation errors.
Thanks a lot for the cool initiative to create this plugin ๐
As far as I can see, you have to add arch-unit-maven-plugin to your dependencies and implement ArchRuleTest
if you want to execute your own rules?
I think it would be cool to allow to specify something like
<rule>
<class>com.my.CustomRule</class>
<check>
<package>com.my.app</package>
<scope>main</scope>
</check>
</rule>
Especially since the classes to import maybe vary under certain conditions (projects are pretty diverse...).
Yes, I know, a PR would be nicer, but I'm completely full at the moment
Generate HTML Report like junit or checkstyle
It is a :
Only stdout logs report the arch-unit errors : it is not user friednly and not useable in jenkins pipeline.
it would be great if the errors detected by the plugin/archunit rules generate an html report
In a multi module build which contains modules which have packaging pom
. Basic example is the root of a multi module build and maybe other children could
be defined with <packaging>pom</packaging>
.
It is a :
The current behaviour is that it produces a warning like this for each module which <packaging>pom</packaging>
[INFO] --- arch-unit-maven-plugin:2.2.0:arch-test (default) @ xyz-parent ---
[WARNING] classpath ..../target/test-classes doesn't exist..
which is a litte bit misleading cause modules which have been defined <packaging>pom</packaging>
could not have code which would be compiled etc.
Based on the convention in Maven there should not be a WARNING for a module which is defined with <packaging>pom</packaging>
cause it could not contain code at all.
It would also be a good idea to have a configuration which could be turned on to support edge cases where people define life cycle bindings in a module with <packaging>pom</packaging>
on their own.
Create a simple multi module build which contains a parent and two children. For the parent you will get the described WARNING.
When I build my project by using jdk15, there are tons of logs like that;
[WARNING] Couldn't import class from ...class-name...
java.lang.IllegalArgumentException: Unsupported class file major version 59
at com.tngtech.archunit.thirdparty.org.objectweb.asm.ClassReader. (ClassReader.java:195)
at com.tngtech.archunit.thirdparty.org.objectweb.asm.ClassReader. (ClassReader.java:176)
at com.tngtech.archunit.thirdparty.org.objectweb.asm.ClassReader. (ClassReader.java:162)
at com.tngtech.archunit.thirdparty.org.objectweb.asm.ClassReader. (ClassReader.java:283)
at com.tngtech.archunit.core.importer.ClassFileProcessor.process (ClassFileProcessor.java:56)
at com.tngtech.archunit.core.importer.ClassFileImporter.importLocations (ClassFileImporter.java:336)
at com.tngtech.archunit.core.importer.ClassFileImporter.importPaths (ClassFileImporter.java:158)
at com.tngtech.archunit.core.importer.ClassFileImporter.importPaths (ClassFileImporter.java:141)
at com.tngtech.archunit.core.importer.ClassFileImporter.importPath (ClassFileImporter.java:120)
at com.societegenerale.commons.plugin.utils.ArchUtils.importAllClassesInPackage (ArchUtils.java:66)
at com.societegenerale.commons.plugin.service.RuleInvokerService.invokeConfigurableRules (RuleInvokerService.java:110)
at com.societegenerale.commons.plugin.service.RuleInvokerService.invokeRules (RuleInvokerService.java:64)
at com.societegenerale.commons.plugin.maven.ArchUnitMojo.execute (ArchUnitMojo.java:88)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:64)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
There is no issue on jdk11, it works as expected. there is also no information about supported java versions on readme (only information is 1.8 on pom.xml). am i missing something or there is no support? thanks
since we upgraded to java 21, a bunch of new warnings are showing up in build logs
Also, tests are not executed anymore !!
Parallel execution of arch-test show some warnings.
It would be nice to check the possibility of parallel execution and mark methods as @threadsafe to eliminate the maven warnings.
It is a :
Executing the maven build with parameter -T 2.0C to speed up overall build time.
With parameter -T 2.0C the warning is printed which shall be fixed.
Execution of the plugin in parallel without maven warning.
Call arch-test with maven parameter -T 2.0C.
There is archunit test(Layering testing) that need to perform on 'pom' packaging but the default behavior of the plugin is skip 'pom' packaging by default.
It is a :
I want to perform Archunit Layer Check using the plugin on many of our projects.
The plugin will skip 'pom' packaging by default
The plugin configuration should provide a way to execute archunit check on 'pom' packaging and all its sub-module projects instead of just skipping it.
For example we can provide a configuration in the applyOn like this.
<configurableRule>
<rule>com.test.LayerTest</rule>
<applyOn>
<!-- can be "true" or "false" -->
<aggregator>true</aggregator>
</applyOn>
<checks>
<check>LAYER_CHECK</check>
</checks>
</configurableRule>
I've setup a configuration with plugin 4.0.0 that seems to works pretty well. However, I want the new feature fallbackToRootDirectory
so I updated to 4.0.1 but then the plugin fails.
It is a :
mvn arch-unit:arch-test
Running the normal plugin and goal throws the following exception:
[ERROR] Failed to execute goal com.societegenerale.commons:arch-unit-maven-plugin:4.0.1:arch-test (default-cli) on project rider-parent: Unable to retrieve component configurator include-project-dependencies for configuration of mojo com.societegenerale.commons:arch-unit-maven-plugin:4.0.1:arch-test: java.util.NoSuchElementException
[ERROR] role: org.codehaus.plexus.component.configurator.ComponentConfigurator
[ERROR] roleHint: include-project-dependencies
[ERROR] -> [Help 1]
Check out this example repository and change the plugin version from 4.0.0 to 4.0.1. I was able to reproduce the issue with this simple project that basically contains nothing else.
https://github.com/moneaOrg/archunit-example
Run with mvn arch-unit:arch-test
mvn -version
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /opt/homebrew/Cellar/maven/3.9.6/libexec
Java version: 21.0.1, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
Default locale: en_SE, platform encoding: UTF-8
OS name: "mac os x", version: "14.2.1", arch: "aarch64", family: "mac"
I'm trying to run a bunch of custom rules we created with the plugin instead of copy pasting them on a new test in every repo but I'm having issues
[ERROR] Failed to execute goal com.societegenerale.commons:arch-unit-maven-plugin:4.0.2:arch-test (default) on project holamundo-spring: class com.kalyp.buildingblocks.archunit.ArchitectureRules cannot be cast to class com.societegenerale.commons.plugin.rules.ArchRuleTest (com.kalyp.buildingblocks.archunit.ArchitectureRules and com.societegenerale.commons.plugin.rules.ArchRuleTest are in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @1ee5792a)
The class is simple:
`
public class ArchitectureRules {
public static final ArchRule CONTROLLER_CLASSES_SHOULD_BE_IN_APPROPRIATE_PACKAGE = classes().that()
.areAnnotatedWith(RestController.class)
.or().haveNameMatching(".*Controller*")
.should().resideInAPackage(API_PACKAGE)
.orShould().resideInAPackage(REST_PACKAGE)
.orShould().resideInAPackage(CONTROLLER_PACKAGE);
public static final ArchRule SERVICE_CLASSES_SHOULD_BE_IN_APPROPRIATE_PACKAGE = classes().that()
.areAnnotatedWith(Service.class)
.or().haveNameMatching(".*Service*")
.should().resideInAPackage(SERVICE_PACKAGE);
}`
Thanks in advance
Before version 2.6.x, if the projectPath
is not specified, if the plugin is run from the aggregate POM level, it will default to /target
, relative to the path the plugin is run from, in this case the aggregate POM level instead of the module level (eg. /target
instead of /module/target
), which will fail. The workaround was to explicitly configure projectPath
as ${project.build.directory}
, which would cause it to run relative to the project base directory, regardless of where the plugin was run from.
With version 2.6.x, #39 is automatically getting the output directory and test output directory from Build#getOutputDirectory() and Build#getTestOutpuDirectory, which is great, however both of these paths are still used relative to the path the plugin was run from. Hence if the plugin is run from the aggregate POM level, it will again use the wrong path (/target
instead of /module/target
). And since projectPath
is removed, there is currently no workaround for this as well.
A solution would be to resolve the output directory and test output directory to the project base directory, which can be obtained using MavenProject#getBasedir().
If you want, I can create a PR for this.
It is a :
How can I configure arch-unit-maven-plugin
to include JARs for a rule? It seems to imply ImportOption.DoNotIncludeJars
by default.
When the plugin runs, we see that even the standard java classes are scanned
It is a :
Execution would be faster if we were scanning only the classes from the project. Furthermore, it may happen that one standard java class has a violation for some rules.
When I run the build I have this :
[INFO] Analysing class 'java/io/IOException'
[INFO] Analysing class 'java/time/format/TextStyle'
[INFO] Analysing class 'java/util/Locale'
[INFO] Analysing class 'java/time/ZoneOffset'
[INFO] Analysing class 'java/time/zone/ZoneRules'
[INFO] Analysing class 'java/io/ObjectInputStream'
[INFO] Analysing class 'java/io/InvalidObjectException'
(..my classes are also scanned)
Only "my" classes should be scanned.
I guess this happens in all projects..
Looking at the documentation i dont' see a way to ignore the units test as part of the scan.
on AnalyzeClasses we have importOptions = ImportOption.DoNotIncludeTests.class Is this something simular to this in the plugin? for defaults.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.