Run one or Exclude one test with Maven

From time to time you only want to run one test, one test method, one class or one package from the command-line.

Or on the contrary: you want to exclude / ignore one specific test or group of tests during the build cycle.

Excluding tests from the build cycle by the command line usually occurs when the following scenarios meet:

  • A test requires significant amount of resources (time, memory, disk space, etc.)
  • The run needs to be independent from the IDE (reenact the Continuous Integration / Continuous Delivery pipeline) as some IDEs load test-dependencies on the compile-time class-path.
  • You have no or limited ability to change the code-base
    Continue reading

Spicy Spring: Create New Projects From a URL

To quickly start with a Spring project we can use the website start.spring.io. Via a user interface we can set project properties and at the end we have a project archive (Zip or gzipped Tar file) or build file (pom.xml or build.gradle). We can also directory access an URL to create the output files and we set the properties via request parameters. This way you can share a link with someone and if they click on it they will download the generated project archive or build files.

Continue reading

Detect Maven Dependency Mediation

As of Maven 2.0.9 a new feature was added to Maven called dependency mediation.
Dependency mediation is the technique used by Maven to resolve your project dependencies in the specific case when a dependency occurs multiple times in your dependency tree.
Usually this occurs on transitive dependencies linked through the dependencies of your project.
In these cases mediation will be performed using the nearest win-strategy.
In short this strategy means that Maven will use the version declared in the pom.xml that is closest to your project pom.xml.
Hence, no in-depth intelligence is used to resolve the dependency conflict.
Actually, I can’t really think of a conflict resolve strategy that would really solve this problem.

Any strategy I can think of has the hazard of linking incompatible dependencies in to your project.
Using Maven version ranges can ofcourse resolve compatibility between artifacts, but this also requires you to establish a compatibility matrix of your dependencies. A pretty tedious task if you ask me.

Now this whole mediation feature might sound like a very undesirable feature, but it’s not!
With this feature you can now at least be made aware of any dependency conflicts in your project dependencies.
When you build your project using the -X switch, Maven will output all mediations (and a lot more) that have been performed.

Now, wouldn’t it be cool if there was a maven-plugin to detect mediation?
JDriven took the liberty of extending Apache’s dependency plugin with such a feature and share it with you.
Continue reading