I have two Maven modules, A and B. A is a dependency of B. Both modules have a resource file named default.properties located in src/main/resources. I need to keep the filenames the same and the location of the file the same in both projects because both A and B are using code which expects the file to be named and located where it is. When building B, A‘s default properties is in the final jar. I wish to have B‘s properties when I build B. How can I do this?
I have two Maven modules, A and B . A is a dependency of
Share
Ok, Maven Resources Plugin and Assembly plugin did not cut it, so I dug some more.
It seems this is doable with Maven Shade plugin.
So, inside the
<configuration> ... </configuration>-tags I’ve defined two things: a transformer-implementation that takes care of modifying the jar-manifest to be runnable and use the current directory as classpath root, and excluding all the files ending with .properties from inside of dependency org.something:SomeDependency.The actual filtering part is where you can exclude the files you don’t want to end up in the final jar built by shade. You can exclude the files from all the dependencies and the current project using
<artifact>*:*</artifact>inside the defined<filter>, or you can select only certain dependency using<artifact>dependcyGroupId:dependencyArtifact</artifact>, for example<artifact>junit:junit</artifact>, or even using wildcards for one or the other (<artifact>*:junit</artifact>). The excluded files are then defined inside the<excludes>...</excludes>-tags. Again, you can use exact filenames or wildcards. This should get you going with your current problem, although I’d suggest reading the documentation from the plugin-site, because shade can do a lot more than this.