Librabry shading example

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Librabry shading example

Goyot, Martin
Hi there,

I have an issue with a dependency on my plugin and would like to shade it. I've found the docs here: https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#shading

But can't seem to get it to work. Right now I'm trying on Guava, I have this in my <build> section in pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Any idea on how to proceed ?

Thanks in advance !

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9fZvyE%3DS1ZGtuu3gD%3D13vDgxsc2w_o0TMfV%3DFnRNYLgQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Gavin Mogan
> But can't seem to get it to work.

A question online/async question should always include the 3 items:

What did you try (sorta provided)?
What happened?
What did you expect to happen?



On Mon, Aug 17, 2020 at 5:35 AM Goyot, Martin <[hidden email]> wrote:
Hi there,

I have an issue with a dependency on my plugin and would like to shade it. I've found the docs here: https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#shading

But can't seem to get it to work. Right now I'm trying on Guava, I have this in my <build> section in pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Any idea on how to proceed ?

Thanks in advance !

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9fZvyE%3DS1ZGtuu3gD%3D13vDgxsc2w_o0TMfV%3DFnRNYLgQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DuvS1HCY-7V0M8TLdi%2BKHr2jg6jEOhca7WDJmLKxJ-cv8g%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Goyot, Martin
Yes, you are right sorry.

What did you try ?

So, I have a dependency on guava 29.0-jre. I had a problem due to the Guava in Jenkins so I decided to give shading a try. Here is what I added to my pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

I then tried to run mvn hpi:run to check if my bug (toImmutableList() no such method) was gone.

What happened ?

The bug still is present, I still get a toImmutableList no such methode. Also, in the trace of the mvn hpi:run I don't see any call to shading, while if I execute mvn package I see it, which seems normal as the selected <phase> is package but then what should I use ?

What did you expect ?

To see the call to shading in the trace, and my bug to be gone.

Le lun. 17 août 2020 à 23:11, 'Gavin Mogan' via Jenkins Developers <[hidden email]> a écrit :
> But can't seem to get it to work.

A question online/async question should always include the 3 items:

What did you try (sorta provided)?
What happened?
What did you expect to happen?



On Mon, Aug 17, 2020 at 5:35 AM Goyot, Martin <[hidden email]> wrote:
Hi there,

I have an issue with a dependency on my plugin and would like to shade it. I've found the docs here: https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#shading

But can't seem to get it to work. Right now I'm trying on Guava, I have this in my <build> section in pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Any idea on how to proceed ?

Thanks in advance !

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9fZvyE%3DS1ZGtuu3gD%3D13vDgxsc2w_o0TMfV%3DFnRNYLgQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DuvS1HCY-7V0M8TLdi%2BKHr2jg6jEOhca7WDJmLKxJ-cv8g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9g140rfL1EGvy9fBCf-GAK-9FJ3zA4f%2B72z89wQnzwWQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Gavin Mogan
Did you switch your imports to use the new shaded library? Is the object coming from your code or external?

If you create the object with the new shaded imports does it have that method?

On Tue., Aug. 18, 2020, 1:35 a.m. Goyot, Martin, <[hidden email]> wrote:
Yes, you are right sorry.

What did you try ?

So, I have a dependency on guava 29.0-jre. I had a problem due to the Guava in Jenkins so I decided to give shading a try. Here is what I added to my pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

I then tried to run mvn hpi:run to check if my bug (toImmutableList() no such method) was gone.

What happened ?

The bug still is present, I still get a toImmutableList no such methode. Also, in the trace of the mvn hpi:run I don't see any call to shading, while if I execute mvn package I see it, which seems normal as the selected <phase> is package but then what should I use ?

What did you expect ?

To see the call to shading in the trace, and my bug to be gone.

Le lun. 17 août 2020 à 23:11, 'Gavin Mogan' via Jenkins Developers <[hidden email]> a écrit :
> But can't seem to get it to work.

A question online/async question should always include the 3 items:

What did you try (sorta provided)?
What happened?
What did you expect to happen?



On Mon, Aug 17, 2020 at 5:35 AM Goyot, Martin <[hidden email]> wrote:
Hi there,

I have an issue with a dependency on my plugin and would like to shade it. I've found the docs here: https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#shading

But can't seem to get it to work. Right now I'm trying on Guava, I have this in my <build> section in pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Any idea on how to proceed ?

Thanks in advance !

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9fZvyE%3DS1ZGtuu3gD%3D13vDgxsc2w_o0TMfV%3DFnRNYLgQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DuvS1HCY-7V0M8TLdi%2BKHr2jg6jEOhca7WDJmLKxJ-cv8g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9g140rfL1EGvy9fBCf-GAK-9FJ3zA4f%2B72z89wQnzwWQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DutZZvfbSMbQ%3DZ%3DErH6N55SyjyzrBsYwYz3fBqfB3wF0rw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Goyot, Martin
Hi Gavin,

so, here is the incriminated code in my plugin:

    private Boolean scopesAreValid(Secret secret) {
        return client
        .getAccessKeyScopes(secret)
        .stream()
        .map(AccessKeyScope::getIdentifier)
        .collect(ImmutableList.toImmutableList())
        .containsAll(MANDATORY_SCOPES);
    }

which imports: import com.google.common.collect.ImmutableList;

I thought that the shading would do the switch by itself, but as you hinted me in your mail, I just tried to change the import with import shaded.com.google.common.collect.ImmutableList;  and re-run mvn hpi:run, which gives me the error package shaded.com.google.common.collect does not exist.

Le mar. 18 août 2020 à 10:42, 'Gavin Mogan' via Jenkins Developers <[hidden email]> a écrit :
Did you switch your imports to use the new shaded library? Is the object coming from your code or external?

If you create the object with the new shaded imports does it have that method?

On Tue., Aug. 18, 2020, 1:35 a.m. Goyot, Martin, <[hidden email]> wrote:
Yes, you are right sorry.

What did you try ?

So, I have a dependency on guava 29.0-jre. I had a problem due to the Guava in Jenkins so I decided to give shading a try. Here is what I added to my pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

I then tried to run mvn hpi:run to check if my bug (toImmutableList() no such method) was gone.

What happened ?

The bug still is present, I still get a toImmutableList no such methode. Also, in the trace of the mvn hpi:run I don't see any call to shading, while if I execute mvn package I see it, which seems normal as the selected <phase> is package but then what should I use ?

What did you expect ?

To see the call to shading in the trace, and my bug to be gone.

Le lun. 17 août 2020 à 23:11, 'Gavin Mogan' via Jenkins Developers <[hidden email]> a écrit :
> But can't seem to get it to work.

A question online/async question should always include the 3 items:

What did you try (sorta provided)?
What happened?
What did you expect to happen?



On Mon, Aug 17, 2020 at 5:35 AM Goyot, Martin <[hidden email]> wrote:
Hi there,

I have an issue with a dependency on my plugin and would like to shade it. I've found the docs here: https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/#shading

But can't seem to get it to work. Right now I'm trying on Guava, I have this in my <build> section in pom.xml:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                </plugin>
                <plugin>
                    <groupId>org.jenkins-ci.tools</groupId>
                    <artifactId>maven-hpi-plugin</artifactId>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>shaded.com.google.common</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Any idea on how to proceed ?

Thanks in advance !

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9fZvyE%3DS1ZGtuu3gD%3D13vDgxsc2w_o0TMfV%3DFnRNYLgQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DuvS1HCY-7V0M8TLdi%2BKHr2jg6jEOhca7WDJmLKxJ-cv8g%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB9g140rfL1EGvy9fBCf-GAK-9FJ3zA4f%2B72z89wQnzwWQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAG%3D_DutZZvfbSMbQ%3DZ%3DErH6N55SyjyzrBsYwYz3fBqfB3wF0rw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB-5_q%3Dz_cfrAsqqmLAfYtyRPtdwZMoGfVhd5wKz1hHcqA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Jesse Glick-4
In reply to this post by Goyot, Martin
On Mon, Aug 17, 2020 at 8:35 AM Goyot, Martin <[hidden email]> wrote:
> I have an issue with a dependency on my plugin and would like to shade it.

In my experience you need to switch to a multimodule (reactor)
project, with one helper module that shades the lib, and then depend
on the helper module from your plugin.

`artifact-manager-s3` has a dep on newer Guava using
`pluginFirstClassLoader`, though this forms its own type of hell.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr07mhUiGBj1nGLMpZXkcAfVrYUX2N2kWVyZBqdrLzVzUQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Goyot, Martin
Hi Jesse,

Thanks, I'm gonna look into this multimodule project, see if I can make it work.

Is `pluginFirstClassLoader` an acceptable tradeoff or am I still better off making shading work ?

Le mer. 19 août 2020 à 22:04, Jesse Glick <[hidden email]> a écrit :
On Mon, Aug 17, 2020 at 8:35 AM Goyot, Martin <[hidden email]> wrote:
> I have an issue with a dependency on my plugin and would like to shade it.

In my experience you need to switch to a multimodule (reactor)
project, with one helper module that shades the lib, and then depend
on the helper module from your plugin.

`artifact-manager-s3` has a dep on newer Guava using
`pluginFirstClassLoader`, though this forms its own type of hell.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr07mhUiGBj1nGLMpZXkcAfVrYUX2N2kWVyZBqdrLzVzUQ%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CA%2Bb6JB_8xvpKOnRHsmRB7TOb0Zneg3BrN-bg-XZGN0eJ0AC5zg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Librabry shading example

Jesse Glick-4
On Thu, Aug 20, 2020 at 3:50 AM Goyot, Martin <[hidden email]> wrote:
> Is `pluginFirstClassLoader` an acceptable tradeoff

It is just very risky. For example, you cannot say with confidence
that because all `JenkinsRule`-based tests pass that the plugin
actually works. It may explode in colorful ways when you actually run
it in a real Jenkins instance.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1otfD6qoQayPnxJJjigko_XFhFFY-jsHUy9gy3eU10zA%40mail.gmail.com.