I am currently using the maven-jar-plugin to build a JAR from a specific class folder which I have included as a provided scope dependency. I now need to include this JAR as a dependency in my final build.
So, is it possible to include a dependency at a specific phase of the build?
NOTE: The dependency is built during the build process, so it is only available during the compile phase.
The simplest way to tackle this would be to separate the code you are building with the maven-jar-plugin into a separate Maven project, and just refer to it as a normal dependency in the main Maven project.
This way you don’t need to mess around with having one Maven build produce two different artifacts (the JAR you are generating and then the main output minus that JAR’s classes) while having the output of the first being referred to in the second.
Alternatively, assuming your main project has the package type set to
jar, you could just add the “specific class folder” classes to the project’s<resources>element and then configure/override themaven-jar-pluginexecution that runs during thepackagephase to exclude these classes, with the<excludes>element in the<configuration>.