Hello Clebert

I hope my comment will help you.
In my experience, using the shade plugin is tricky because the rule of
thumb I came up with is: "your shaded artifacts must be the last artifact
to be built in your multi modules Maven project".
Which can read "you must not depend onto your shaded artifact if shading
happens in the same Maven execution (or Maven reactor)".
You have to have a first execution of Maven to install/deploy your shaded
artifact, and then a second execution can depend onto this shaded artifact.
So you must have 2 different project trees.

Why so much trouble ?
because Maven computes the dependency trees for each module right at the
start of the build, whereas the Shade plugin happens to mess with the
dependency tree in the middle of Maven's execution. Shade plugin is a hack
and therefore extreme care must be taken in its use.
At least that's my understanding after using it for years and having been
bitten numerous times.

Hope it helps




*- - - - -François Marot*



Le mer. 17 nov. 2021 à 15:07, Clebert Suconic <[email protected]> a
écrit :

> Right.. This should happen by default. and it will only work if I'm
> using the shaded jar outside of my project. However if I use it within
> my project it will not work at all.
>
>
> I have created a minimal version of my issue on this github project:
>
>
> https://github.com/clebertsuconic/clebert-shade-issue
>
>
>
> I expect the following line to give me a compilation error:
>
>
> https://github.com/clebertsuconic/clebert-shade-issue/blob/main/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/JsonLoader.java#L38
>
>
> And that shading isolation will only work (that means give me the
> compilation error) if I remove this line from the main pom (after mvn
> install on artemis-commons-json of course):
>
> https://github.com/clebertsuconic/clebert-shade-issue/blob/main/pom.xml#L34
>
>
> if I also call "mvn dependency:tree", you will see the dependency
> listed and not giving the isolation I expected:
>
>
> https://gist.github.com/clebertsuconic/cb025175470a0f429582d3f656b48377#file-gistfile1-txt-L5-L6
>
>
>
>
>
> So, in other words, shading does not work internally. The pom
> replacement will not work through the internal dependency list.
>
> It seems like a bug to me, unless someone finds an explanation?
>
> and how I would be able to achieve this? would anybody know?
>
> On Wed, Nov 17, 2021 at 8:39 AM Matt Benson <[email protected]> wrote:
> >
> >
> https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#createDependencyReducedPom
> >
> > On Tue, Nov 16, 2021, 10:47 PM Clebert Suconic <
> [email protected]>
> > wrote:
> >
> > > I’m not sure how you mean.
> > >
> > > Just get the Pom at the source level or am intermediate build process ?
> > >
> > >
> > > How to do that ?
> > >
> > > On Tue, Nov 16, 2021 at 11:34 PM Matt Benson <[email protected]>
> wrote:
> > >
> > > > You probably want to rewrite the pom, using the property provided by
> the
> > > > shade goal for this purpose.
> > > >
> > > > Matt
> > > >
> > > > On Tue, Nov 16, 2021, 7:48 PM Clebert Suconic <
> [email protected]
> > > >
> > > > wrote:
> > > >
> > > > > I am trying to create a component within ActiveMQ Artemis that
> would
> > > > > shade johnzon and javax.json.
> > > > >
> > > > > That component should then be used by other components within
> Artemis.
> > > > >
> > > > > I'm doing that because some users want to use javax.json and others
> > > > > want to use jakarta.json on their runtimes. Since we only use json
> > > > > internally I am trying to shade our own usage and not relay on
> either
> > > > > one of these package names.
> > > > >
> > > > >
> > > > > However I'm getting crazy on this. I can't make shade to hide the
> > > > > dependency. mvn dependency:tree still shows the libraries. and
> shade
> > > > > will not work if I make them provided.e.
> > > > >
> > > > >
> > > > > What is the right way to shade within my own project?
> > > > >
> > > > >
> > > > > I have the project available on my own github fork here:
> > > > >
> > > > >
> https://github.com/clebertsuconic/activemq-artemis/tree/commons-json
> > > > >
> > > > > (type this if you can download my branch:
> > > > >
> > > > > git clone https://github.com/clebertsuconic/activemq-artemis.git
> > > > > cd activemq-artemis
> > > > > git clone commons-json
> > > > > mvn install -DskipTests=true
> > > > > mvn dependency:tree
> > > > >
> > > > > and here is what gets interesting.
> > > > > if I go to artemis-selector (a package that relied on
> > > > > artemis-commons-json) and type mvn dependency:tree on that package,
> > > > > the dependency does not show up.
> > > > >
> > > > >
> > > > > The issue is only when building the whole project...
> > > > >
> > > > >
> > > > > and I have played with quite a few options! )
> > > > >
> > > > >
> > > > >
> > > > > Any help would be appreciated ! :)
> > > > >
> > > > >
> > > > > Thanks
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [email protected]
> > > > > For additional commands, e-mail: [email protected]
> > > > >
> > > > >
> > > >
> > > --
> > > Clebert Suconic
> > >
>
>
>
> --
> Clebert Suconic
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to