Across several projects I have some resources (specifically Flyway database migration scripts) that I’d like to be shared.
Is it possible to have these shared resources exist as a Maven artifact, and prior to a build have Maven resolve that dependency and unpack the contents of the artifact to /src/main/resources/? If so, how would one go about this?
If you place some files in
/src/main/resourcesthey will be placed on the CLASSPATH in the target JAR artifact. This means if you depend on such an artifact, you will have access to all resources, just as you have access to classes in it.If
my-resourcesartifact contains some resources in/src/main/resources, you can access them at runtime just like you (or any other library) can access/src/main/resourcescontents from the same artifact.Note that this won’t work with
/src/test/resourcesbecause test resources are only placed on CLASSPATH duringsurefireexecution of current artifact.