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?
相关问题
- Include pom.xml in Jar with gradle
- What order does maven find its dependencies?
- proguard causing EnumMap NPE on dynamically declar
- Change value of R.string programmatically?
- Maven: How to read the Parent POM version
相关文章
- IDEA2020 安装maven 插件后,springboot程序 SpringBootApplic
- pom文件中的插件定义
- pom.xml中的project为何报红
- Hibernate Tutorial - Where to put Mapping File?
- Cannot use org.jvnet.jax-ws-commons.jaxws-maven-pl
- New Maven install: mvn -version java.lang.ClassNot
- What's the difference between archetype.xml an
- NoNodeAvailableException[None of the configured no
I know this is 3 years old but I had the same problem and this is the closest question I found, but still without correct answer so maybe someone will find it useful.
Example maven-assembly descriptor based on jar-with-dependencies (fixes overriding of log4j.properties by dependencies):
The key is to provide different rules for dependencies and the actual project (top of hierarchy). Those can be split by using
<useProjectArtifact>false</useProjectArtifact>
and providing separate rules infileSets
for the project. Otherwise none oflog4j.properties
would be packed, including the top one.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.