r/Maven • u/Tristan_Kruse • 14d 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/GermanBlackbot 14d 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/Tristan_Kruse 14d ago
Apologies, the formmating should now look better. Here’s the README quickstart, with an example.
1
u/GermanBlackbot 14d ago
Sorry, but I will not read your Readme to understand what it is you did.
You wrote a post on Reddit telling me to add some random test dependency, allude to some documented property and lastly that it requires JDK 25.
If you did something cool, post it here and say what it does and why I should want it. Don't just say "Add this dependency and then here's a Readme file explaining what it does". This is like saying "Guys, I wrote a book, you can buy it on Amazon, if you want to know what it is about here's a link to my blog".
1
u/CptGia 14d ago
I doubt OP wrote a single line of code, or even the content of this post
1
u/paul_h 14d ago
No need to be rude
1
u/GermanBlackbot 14d ago
I'd argue it is rude to drop a link to some test dependencypartially written by AI, but let's give the benefit of the doubt and assume it's largely good, not properly explaining what it does, slapping a "Written by AI" disclaimer at the bottom and expecting the community to care.
1
1
u/sweating_teflon 13d ago
Just force a version which will never exist. The build error you'll get is quite obvious.
<dependencyManagement>
<dependency>
<groupId>org.abc</groupId>
<artifactId>banned-artifact</artifactId>
<version>#FORBIDDEN#</version>
</dependency>
<dependencyManagement>
2
u/Jilljoy 14d ago
This seems like an alternative way of using the Maven Enforcer plugin. Why use this over that?