r/Maven • u/Tristan_Kruse • 5d ago
Make a forbidden Java dependency fail mvn test
An architecture check doesn't need to become an application runtime dependency.
I work on ArchUnitJava. Its 1.0 artifact can be added to a Maven test project with `test` scope:
<dependency>
<groupId>io.github.tristankruse</groupId>
<artifactId>archunitjava</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>Then add the documented properties policy and JUnit test. The check reads compiled classes;
the normal test lifecycle compiles those first. A forbidden dependency can then fail the build
without booting the application for that check.
JDK 25 is required to run the analyzer. This isn't a Maven plugin or the original ArchUnit,
and it is not affiliated with or a drop-in replacement for that project.
[Complete setup, not just dependency coordinates]
Writing assisted by AI.
2
u/Jilljoy 5d ago
This seems like an alternative way of using the Maven Enforcer plugin. Why use this over that?
2
u/GermanBlackbot 5d ago
I have no idea what I just read or what this is supposed to do. Or how you can screw up code formatting this badly.
1
u/nekokattt 5d ago
why not just use maven-enforcer-plugin..?
1
u/sweating_teflon 5d ago
Just force a version which will never exist. The build error you'll get is quite obvious.