0

I would like to produce a fat/standalone jar which contains both my test classes and test-scope dependencies. Using the maven-jar-plugin, I can create a jar which contains my test classes but it does not contain dependencies. Reading the internet, appears the solution is to combine maven-jar-plugin with maven-assembly-plugin.

I tried following these instructions https://jitblog.net/build-maven-standalone-tests/ but have had no success. Here is a repro of my issue: https://github.com/yanakad/commons-compress-test

  1. Run mvn clean package
  2. Expected: target/fatJar.jar will contain both SnakeYaml and TestClass
  3. Observed: SnakeYaml is indeed there but TestClass is not

My maven version is Apache Maven 3.6.0

Looking at the maven execution, it seems that

`[INFO] --- maven-assembly-plugin:3.2.0:single (fat-testjar) @ compress-test ---` 
is run before
`[INFO] --- maven-jar-plugin:3.2.0:test-jar (default) @ compress-test ---`

Not sure if that's the cause or a red herring, or how to fix...Any insight much appreciated

Yana K.
  • 1,926
  • 4
  • 19
  • 27

1 Answers1

0

So it did turn out to be a silly mistake but leaving here in case it helps someone else

maven-jar-plugin and maven-assembly-plugin run in the same build phase. Maven apparently executes plugins in the lexical order of the file. So the fact that the assembly plugin was running before the jar plugin was in fact the problem. The solution was to reorder the plugins in the pom.xml files to have maven-jar-plugin appear before maven-assembly-plugin

Yana K.
  • 1,926
  • 4
  • 19
  • 27