Maven Shade assemble order - maven

When I use Maven Shade to build my assembly jar, some properties files will be replaced if they have the same file name, for example, "logback.xml". I have my own logback.xml in my project, however, it exists in other 3rd jars, too.
How can it be configured to use project's properties files in prior?
Thanks.

Hi you can try filtering out files that you dont want to be included. See here.

Related

Does maven care about file names?

I am trying to install some dependencies using maven in a spring boot project.
I am looking for a jar
org.apache.maven.plugins:maven-resources-plugin:jar:3.1.0
But I wanna know if the jar file should have this name maven-resources-plugin, or if the file name is not important for maven. I mean if maven will automatically know which jar file should use.
I will appreciate any help or feedback.
That is a plugin, not a dependency as such (meaning that Maven needs it for building your project, your code doesn't need it to compile or run).
You should only have to specify the plugins groupId, artifactId and version plus any configuration in your pom.xml, and Maven knows exactly what jar to get and how to use it.
See https://maven.apache.org/plugins/maven-resources-plugin/plugin-info.html for further information.

Build additional ZIP with only sources

Is there a way in Maven to build additionally to the JAR file a ZIP file with only the sources and some text files in it?
I've tried using the assembly plugin for that but it seems it always includes the JAR in the ZIP file.
You use the Maven Source Plugin for this purpose.
You can use the includes parameter to customise exactly what it should include, such as your additional text files.
Maven Assembly plugin can solve this for you. You can configure as many zip artifacts as you want and add to your build process.

Maven: generate MANIFEST in custom location

I am trying to retrieve the implementation title and version for a maven jar module. If I use Myclass.class.getPackage().getImplementationVersion() on the built jar, it works, but the same does not work in a debugging environment where the jar is not built, but classes are available.
I am aware of using the Maven JAR plugin to generate the MANIFEST for a maven jar module. So one approach I am considering is to somehow create a copy of the MANIFEST in the generated sources output folder, which I include in my debug classpath. To achieve this:
Is it possible to generate the MANIFEST file in a custom location? If so, what is the plugin and execution configuration necessary?
If not, in which location is the file generated, so I may copy it my custom location using the maven-resources-plugin?
The Manifest file is created dynamically when the archive is assembled. There is no default way to do this.
The easiest I would come up with is to put a MANIFEST.MF in a resource directory, let Maven filter it and add the directory with a profile. This would mimic the way Maven Archiver creates your MANIFEST.MF. The hard way would be to create a custom plugin around Maven Archiver and pass the very same config as to the JAR plugin and enable it with a profile again.

include source files in war maven

I want to include source files also in Maven - War file . Some plugins in maven will do that but they are including source files in classes folder. But my requirement is that when I import the same war file again into eclipse I should be able to work on that war like any other normal war.
Basically I should be able to work on the same war after importing it to eclipse when I build maven project. (I'm using maven3. )
I remember that's not trivial because the war-plugin doesn't support the handy includes-configuration-element you know from the jar-plugin by default.
Therefore I suggest you to use the maven-assembly-plugin to configure the inclusion of your sourcefiles. You only need to define an assembly descriptor, where you list includes and excludes of your war-package. Maybe you can reuse one of the predefinied assembly descriptors to save some time.

Maven compile all source files, but include into jar only few of them

I have source folder with more than 500 source files.
I need to produce 4 Jars from this sources.
But there is one problem when i try to compile sources needed for my first jar they dont want to compile because, all sources are needed to compile my specific sources.
and here is the question: if i compiled once all my 500 source files with maven how i can split them into several JAR files? i dont need that all my for 4 jar were containing all 500 sources, each JAR must contain only their specific .class files...
With ant it was very easy, u just compile all sources once, and then when creating JAR u just include specified .class files into jar, and no problem... Can some thing similar be done i n MAVEN?
You should split your source code in multiple inter-dependant java projects.
Then, make each project compile to a jar.
I really recommend going Tristans solution but you should also achieve what you want by configurating the maven-jar-plugin to exclude/include the content that you (not) want. This is described here (see How to include/exclude content from jar artifact?).
As you can only build one artifact with one pom.xml (in general) you have to prepare several pom's (or you try the <classifier> configuration also described on the maven-jar-plugin Usage page (I never used it but it seams to help you to do what you want).
You SHOULD split this jar project into Multi-Module jar project. This will solve your problem and project structure will be much better.

Resources