Can I configure maven shade plugin in such a way, that when there are no source changes it will not create shaded plugin again (and leave the old one) - in scenario when I don't use "clean".
2 Answers
As faar as i know the answer is no (i however just overflew the plugins documentation again). Since the compiler recognizes changes on .java files and skips compilation if nothing changed my first guess was to bind the plugin to the process-classes
phase of the default lifecycle which obviously will throw an error (speaking for my self i just try such things before i acctually think about it... logicially its early for the plugin to pack the "uberJar" yet).
However if you are able to skip the package
phase of the default lifecycle in any way (i dont know how) if nothing (including resources) changed the plugin would also not be run.
Also note that the plugin is not triggered as long as you dont proceed to the phase package
of the default lifecycle (e.g. mvn prepare-package
which doesn't make much sence in any of my usecases so i would just run mvn test
unless i realy need something packed and/or installed.
I also have to admit that i only use the plugin for "reverse engineering" of certain project setups where "i just want everything from that project in my /target folder" :)

- 2,769
- 5
- 24
- 40
-
Let me know if you found a way :) (I like your question in the context of 'educational' relevance :)) – JBA Feb 27 '15 at 15:09
-
well I guess you are right :) in my usecase i have project with lots of deployable modules - so around 20 executable uberjars are created and it would save me a lot of time if it would shade only after changes (i run only "install" without clean) – keyer Feb 28 '15 at 11:42
-
Mind if i ask for the purpose of having a newer Snapshot installed in the local repository if there are no changes? :) – JBA Mar 02 '15 at 08:30
-
Another possibility i have seen in larger multi module projects (oftenly "time intensive" ZIP-Packaging of Batch-Components) is to have the build and packaging beeing seperated. Say you have 10 Maven Modules that lead to 10 jars which in the end are somehow packed to the executable uberJar - you could have your 10 Modules just beeing build by their common parent (packaging=pom) and their deliverys beeing installed to the repository - then have a independent Maven project with dependencies to those aretefacts which will do nothing but take them from the repo and pack them to the uberJar – JBA Mar 02 '15 at 08:31
-
ok so really I maybe should explain a bit: I am working on project where we are ending our "artifact" release by pushing application as docker image. when I type mvn install - it compiles, packages in uberpom, runs docker build to create docker image. when I type mvn deploy - it pushes docker image to docker repository what we have right now is not bad, as docker will detect, that uberjar file has not changed and will not waste any more time - problem is that shading takes time. I asked because in gradle it's possible (to not execute something if no code change) and hoped for it in mvn – keyer Mar 02 '15 at 19:12
Also came accross this problem.
What about implementing my own shader as proposed here:
https://maven.apache.org/plugins/maven-shade-plugin/examples/use-shader-other-impl.html
I wonder whether there is more straightforward way for doing it.
@Component( role = Shader.class, hint = "mock" )
public class MockShader extends DefaultShader
{
public void shade( Set<File> jars,
File uberJar,
List<Filter> filters,
List<Relocator> relocators,
List<ResourceTransformer> resourceTransformers )
throws IOException, MojoExecutionException
{
//pseudo code
if source code changes
call super.shade(.......)
else
do nothing
}
}

- 1,509
- 2
- 13
- 17