Skip to content

pom.xml: shade Jackson artifacts#225

Merged
bhelx merged 3 commits into
masterfrom
shaded-jar
Apr 11, 2018
Merged

pom.xml: shade Jackson artifacts#225
bhelx merged 3 commits into
masterfrom
shaded-jar

Conversation

@pierre
Copy link
Copy Markdown
Member

@pierre pierre commented Dec 21, 2017

See discussion at #187.

Note that the library jar is now 1.8M.

@bhelx Do you have a project handy using this library for testing?

See discussion at #187.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
@bhelx
Copy link
Copy Markdown
Member

bhelx commented Dec 21, 2017

Thanks @pierre ! I'll find a way to test this. I can create a project to try.

@bhelx bhelx self-requested a review December 21, 2017 19:03
@bhelx
Copy link
Copy Markdown
Member

bhelx commented Jan 2, 2018

I've been on vacation for a few days. Making time to test this today.

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Jan 2, 2018

@pierre can you give me some instructions on how to test this?

I have a new java/maven project. I ran mvn package to build the recurly jar. Then pointed my new pom.xml to that jar:

<dependency>
  <groupId>com.ning.billing</groupId>
  <artifactId>recurly-java-library</artifactId>
  <version>0.13.2</version>
  <scope>system</scope>
  <systemPath>/Users/ben/R/recurly-java-library/target/recurly-java-library-0.13.2-SNAPSHOT.jar</systemPath>
</dependency>

This won't compile and it seems is expecting me to explicitly list recurly's dependencies in my pom file. Is this expected?

@pierre
Copy link
Copy Markdown
Member Author

pierre commented Jan 4, 2018

@pierre can you give me some instructions on how to test this?

The shaded jar becomes the main artifact, so there isn't anything special to do.

Just run mvn clean install and then add the dependency in your project pom.xml:

<dependency>
    <groupId>com.ning.billing</groupId>
    <artifactId>recurly-java-library</artifactId>
    <version>0.13.2-SNAPSHOT</version>
</dependency>

@easel
Copy link
Copy Markdown
Contributor

easel commented Mar 9, 2018

In order to get this to work, I also had to shade woodstox. Changes at easel@e994de5

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Mar 16, 2018

Following up on this, I can get my test project to build, but not run:

/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/bin/java -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/lib/tools.jar:/Users/ben/code/recurly/recurlyshadedjava/target/classes:/Users/ben/.m2/repository/com/ning/billing/recurly-java-library/0.13.3-SNAPSHOT/recurly-java-library-0.13.3-SNAPSHOT.jar:/Users/ben/.m2/repository/com/google/code/findbugs/jsr305/2.0.3/jsr305-2.0.3.jar:/Users/ben/.m2/repository/com/ning/async-http-client/1.9.8/async-http-client-1.9.8.jar:/Users/ben/.m2/repository/io/netty/netty/3.10.0.Final/netty-3.10.0.Final.jar:/Users/ben/.m2/repository/joda-time/joda-time/2.7/joda-time-2.7.jar:/Users/ben/.m2/repository/org/slf4j/slf4j-api/1.7.10/slf4j-api-1.7.10.jar:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain com.recurly.shadedjava.Main
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/io/Resources
	at com.ning.billing.recurly.RecurlyClient.buildUserAgent(RecurlyClient.java:1876)
	at com.ning.billing.recurly.RecurlyClient.<init>(RecurlyClient.java:150)
	at com.ning.billing.recurly.RecurlyClient.<init>(RecurlyClient.java:143)
	at com.ning.billing.recurly.RecurlyClient.<init>(RecurlyClient.java:139)
	at com.ning.billing.recurly.RecurlyClient.<init>(RecurlyClient.java:135)
	at com.recurly.shadedjava.Main.main(Main.java:7)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: com.google.common.io.Resources
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 11 more

@mmichalko
Copy link
Copy Markdown

Hello.

I am using custom build of this branch few months in our production system without issues. Had to setup pom.xml in a following way, to get it working:

<!-- Custom recurly lib build to work with newer jackson version START -->
		<!-- TODO remove this and jar dependencies and use dependency from maven central after
		https://github.com/killbilling/recurly-java-library/issues/187 is resolved, also remove exception from .gitignore-->
		<dependency>
			<groupId>com.ning.billing</groupId>
			<artifactId>recurly-java-library</artifactId>
			<version>0.13.2-SNAPSHOT</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/lib/recurly-java-library-0.13.2-SNAPSHOT.jar</systemPath>
		</dependency>
		<!-- manually included recurly jar dependencies -->
		<dependency>
			<groupId>com.google.code.findbugs</groupId>
			<artifactId>jsr305</artifactId>
			<version>2.0.3</version>
		</dependency>
		<dependency>
			<groupId>com.ning</groupId>
			<artifactId>async-http-client</artifactId>
			<version>1.9.8</version>
		</dependency>
		<dependency>
			<groupId>joda-time</groupId>
			<artifactId>joda-time</artifactId>
			<version>2.7</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.woodstox</groupId>
			<artifactId>stax2-api</artifactId>
			<version>4.0.0</version>
		</dependency>
		<!-- Custom recurly lib build to work with newer jackson version END -->

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Mar 28, 2018

Okay, I've gotten this working with jackson 2.9.0. Here is my pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.recurly.shadedjava</groupId>
    <artifactId>recurly-shaded-java</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.recurly.shadedjava.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jackson.version>2.9.0</jackson.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.ning.billing</groupId>
            <artifactId>recurly-java-library</artifactId>
            <version>0.13.2-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>2.0.3</version>
        </dependency>
        <dependency>
            <groupId>com.ning</groupId>
            <artifactId>async-http-client</artifactId>
            <version>1.9.8</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.woodstox</groupId>
            <artifactId>stax2-api</artifactId>
            <version>4.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-joda</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>

</project>

Here is a test Main class to make sure everything is okay at runtime.

package com.recurly.shadedjava;

import com.ning.billing.recurly.RecurlyClient;
import com.ning.billing.recurly.model.Account;

public class Main {
    public static void main(String[] args) {
        try {
            final RecurlyClient client = new RecurlyClient("1fcc92ddc21e409f85e3ad1179e43929", "java-client-sandbox");
            client.open();
            final Account account = client.getAccount("fg5q0RKQ7r");
            System.out.println("Account found: " + account.getAccountCode());
            client.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Mar 28, 2018

@pierre how do we plan to release this? will we have a shaded and original version of the library? How do we communicate changes to the users?

@easel
Copy link
Copy Markdown
Contributor

easel commented Mar 29, 2018

@bhelx have you got all the tests passing with Jackson 2.9? I ran into a number of code api changes in addition to the dependency issues.

pierre added 2 commits March 29, 2018 14:53
The provided scope was useful during the transition from Google Collections,
but hopefully nobody uses it anymore.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
@pierre
Copy link
Copy Markdown
Member Author

pierre commented Mar 29, 2018

In order to get this to work, I also had to shade woodstox. Changes at easel/recurly-java-library@e994de5

Thank you @easel for the testing! I've applied it to this PR.

Following up on this, I can get my test project to build, but not run

This was related to Guava being provided (for legacy reasons). Fixed.

@pierre how do we plan to release this? will we have a shaded and original version of the library? How do we communicate changes to the users?

I would simply bump the minor. I don't think there is any side effect regarding Jackson / Woodstock now that the main jar is shaded (the only drawback would be for people to import unused jars in their projects if they don't cleanup their pom.xml). For Guava, the change is a bit more subtle, but hopefully we can get away with a warning in the README.

@bhelx have you got all the tests passing with Jackson 2.9? I ran into a number of code api changes in addition to the dependency issues.

@bhelx, @easel: I would not try to upgrade Jackson now it is shaded, unless there is a good reason for it (CVE, etc.).

Let me know if the latest changes work for you and I'll prepare a release!

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Mar 29, 2018

@easel yeah there does appear to be some breaking API changes. I'm not sure how we can handle those.

@easel
Copy link
Copy Markdown
Contributor

easel commented Mar 29, 2018

@bhelx I was able to get everything ported as far as Jackson 2.8 successfully at easel@dcec432

There are a couple of seemingly undocumented changes in Jackson 2.9 I couldn't quite figure out and dropped in favor of shading.

@pierre I just updated my local snapshot against your changed branch and everything I use is still working. Looking forward to the release!

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Mar 29, 2018

@easel are those changes backwards compatible?

@easel
Copy link
Copy Markdown
Contributor

easel commented Mar 29, 2018

@bhelx no they aren't, at least as far as I can tell. Perhaps somebody who knows Jackson better than I would know more, and how to cross the last gap to get things working with 2.9. Given we're shading in this library, I don't think it's such a high priority, but on the other hand, if we're shading we can also move forward safely so it might be worth it from a performance or security standpoint if we get everything working.

Copy link
Copy Markdown
Member

@bhelx bhelx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be working for me up to jackson 2.8.11. I think it's worth getting this out now due to security concerns and jackson 2.5 is pretty old. This will give our users some more flexibility.

@bhelx bhelx merged commit 45a079c into master Apr 11, 2018
@bhelx
Copy link
Copy Markdown
Member

bhelx commented Apr 11, 2018

@easel thanks for helping us!

@easel
Copy link
Copy Markdown
Contributor

easel commented Apr 12, 2018

@bhelx glad to help out, I'm a happy user of the library. Are you thinking to try and bring the shaded version of jackson forward to 2.8?

@pennstatephil
Copy link
Copy Markdown

pennstatephil commented Jun 7, 2018

Can someone help me understand what this whole shading thing is about? I'm trying to upgrade from v14 to v16, and the first issue I'm running into is when trying to use the XmlMapper

/codev/workspace/billing-service/src/main/java/com/service/billing/service/RecurlyNotificationListener.java:23: error: incompatible types: com.ning.billing.recurly.shaded.com.fasterxml.jackson.dataformat.xml.XmlMapper cannot be converted to com.fasterxml.jackson.dataformat.xml.XmlMapper
    private XmlMapper xmlMapper = RecurlyObject.newXmlMapper();

@easel -- you seem to have a handle on this?

@easel
Copy link
Copy Markdown
Contributor

easel commented Jun 8, 2018

@pennstatephil net-net, shading lets us extract a version of a dependency for our own usage, allowing your application to use a different version. Changes are if you change your XmlMapper import from com.fasterxml.jackson.dataformat.xml.XmlMapper to com.ning.billing.recurly.shaded.com.fasterxml.jackson.dataformat.xml.XmlMapper things might work for you.
For more details on shading, you might want to check out https://maven.apache.org/plugins/maven-shade-plugin/

@pennstatephil
Copy link
Copy Markdown

@easel so, it essentially allows the two versions to work side-by-side? Or can we override the internal version of the library's Jackson with a newer version (say, 2.8)?

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Jun 8, 2018

@pennstatephil which version or jackson are you currently using? You might need to include some more dependencies in your maven pom.xml like i've done here: #225 (comment)

@bhelx
Copy link
Copy Markdown
Member

bhelx commented Jun 8, 2018

@pennstatephil also, what it essentially means is that this library is no longer locked to the old version of jackson and you can now provide your own.

@aaron-junot aaron-junot deleted the shaded-jar branch September 12, 2018 15:28
mmetterle pushed a commit to barklyprotects/recurly-java-library that referenced this pull request Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants