Thank you so much.. this really helped me a lot.

I will still shade json into my artemis-commons package, but now that
I understand what's going on.. I will never depend on renamed classes
between the packages.. that really helps.
Perhaps this little bit of information should be added to the usage
page? a lot of the references I found on google were suggesting doing
this kind of "anti pattern" as I see now. Some work on the doc would
be clarifying. Perhaps you should even close
https://issues.apache.org/jira/browse/MSHADE-269 as explained, adding
a big note on IDEA that people should not really do that.

The way I think about this now builds would be a lot messier if shaded
dependencies were to become a standard like this.


On Thu, Nov 18, 2021 at 7:18 AM Matt Benson <[email protected]> wrote:
>
> I have not yet analyzed your example in full detail, but typically the idea
> with shaded code is that your original code will refer to the classes of
> the package to be shaded by their original names (that's assuming you're
> relocating packages, which you are in this case; otherwise the names would
> of course not differ). My thought with regard to dependencies among modules
> is that the whole idea of shading is that code depending on your shaded
> artifact is not typically expected to use directly/at compile time the
> shaded types and you can apply this rule to submodules of the same lineage
> as well.
> I think you could possibly accomplish what you want by creating a dedicated
> artifact that does nothing but repackage the JSON library/ies you want to
> consume among your modules; I thought of this when I saw you were
> attempting to reference your dependencies by their "relocated names" in
> your source code. Having created this artifact (which I have not called a
> module because as has been mentioned you will probably have a hard time
> getting your IDE to build it in the way you want) you can refer to the
> relocated types at source level as you have attempted, and across as many
> modules as you like. Apache Geronimo has done something like this
> (publishing a "shaded" version of a dependency) with asm for their xbean
> code as I recall.
>
> HTH,
> Matt
>
> On Wed, Nov 17, 2021, 8:07 AM Clebert Suconic <[email protected]>
> wrote:
>
> > 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]
> >
> >



-- 
Clebert Suconic

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to