3

I have a versioned ZIP file deployed in my artifact repository that I need to download, extract, and include as a resource with Maven.

I have been successful using the maven-dependency-plugin to retrieve the artifact and extract it during the package phase with the unpack goal. I see the extracted ZIP where I want it in the build directory. I then have that unpacked directory included as a resource. I can see the directory getting included with the appropriate files inside of the source-jar/myProject-sources.jar. I do not see this folder included in the final JAR myProject.jar.

Any suggestions or examples on how to include this extracted resource would be appreciated.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107

1 Answers1

3

If you extract during the package phase that's long after the process-resources phase when the maven-resources-plugin's resources goal runs by default:

Maven Lifecycles, Phases, Goals, Plugins

resources:resources copies the resources for the main source code to the main output directory.

This goal usually executes automatically, because it is bound by default to the process-resources life-cycle phase. It always uses the project.build.resources element to specify the resources, and by default uses the project.build.outputDirectory to specify the copy destination.

I'd try to extract at the generate-resources phase.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • 1
    My IDE was marking unpack with the error of 'Plugin execution not covered by lifecycle configuration' when I had previously tried to change the phase. I ignored it and compiled from the command prompt; works just fine with your suggestion. – bkstradling Jan 16 '21 at 17:39
  • 1
    @bkstradling In Eclipse I can _Ignore_ these messages in _Preferences_ → _Maven_ → _Error/Warnings_ or edit the _lifecycle mappings metadata_ file in _Maven_ → _Lifecycle Mappings_. – Gerold Broser Jan 16 '21 at 17:48