50 MB Maven dependencies?

34 views
Skip to first unread message

steffen...@gmail.com

unread,
Jun 1, 2018, 12:21:13 PM6/1/18
to jsonschema2pojo-users
Hi,

I have to build reproducible from a version-controlled, read-only, internet-less environment ("you can burn it on CD") and thus have to care about Maven repository packages. Every used file must be under version control.

When I use jsonschema2pojo-cli, I just need 1 JAR file (and a small shell script). I'd prefer integrating into Maven2, so I used the provided example. Unfortunately, using the Maven Plugin increases repository size by 49872 KB (from 60MB to 109MB). Some downloaded packages look really unexpected (proto-google-cloud-logging, commons-fileupload, google-api-services-translate...).

Could it be that there are some unneeded dependencies accidentally added (via jsonschema2pojo-scala or such)?

Is there anything I can do to improve this?

Regards,
Steffen


(I used jsonschema2pojo-maven-plugin 0.5.1, jsonschema2pojo-core 0.5.1)

steffen...@gmail.com

unread,
Jun 1, 2018, 2:11:50 PM6/1/18
to jsonschema2pojo-users
* Steffen wrote:
> (I used jsonschema2pojo-maven-plugin 0.5.1, jsonschema2pojo-core 0.5.1)

I noticed that older (0.4.37) and newer (1.0.0-alpha2) need ~27 MB. This is close to the size of the CLI tar.gz (24 MB). Thanks to Maven a lot of needed packages already exist in my repo (which is for several JavaEE applications), but in different versions. For some reason I don't understand the code generator needs functionality from packages that it optionally can generate code for, such as Android (13 MB for Parcelable etc) or Scala (5 MB). Removing Android support in a small GIT fork seems non-trivial.

Maybe I try going back to 0.4.7 (needs just 5 MB), but who knows that kind of issues I'd be inviting by this (at least, my generated code does not compile).

Steffen

Joe Littlejohn

unread,
Jun 3, 2018, 3:39:15 PM6/3/18
to jsonschema...@googlegroups.com
Hi Steffen

There was a Google cloud dependency that I added incorrectly to the maven plugin. This was added in 0.5.0 and removed in 1.0.0-alpha2. So it's definitely true that the maven plugin has incorrect and bloated dependencies in 0.5.0 and 0.5.1.

When we support new kinds of code generation this sometimes requires that we rely on new libraries. We don't currently load any dependencies dynamically when the plugin is executing, so if there is a feature that requires an additional library, this will get downloaded whether you use that feature or not.

I could release a 0.5.2 that removes the google-cloud dependency if that would be useful.

Cheers

Joe



--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
Visit this group at https://groups.google.com/group/jsonschema2pojo-users.
For more options, visit https://groups.google.com/d/optout.

steffen...@gmail.com

unread,
Jun 4, 2018, 7:30:45 AM6/4/18
to jsonschema2pojo-users
Hi,

thanks again for your quick and helpful reply!

Yes, thank you, I saw the Cloud dependencies are already solved in 1.0.0-alpha2, the deps have been reduced to 27 MB.
Thank you so much for offering 0.5.2, but I would just use 1.0.0-alpha2 instead.
However, this still depends on e.g Android (13 MB for Parcelable etc) and Scala (5 MB). 

Just for my curiosity, if generating code for Scala or Android, why are Scala or Android Libs needed by the generator itself? To execute unit tests? In this case, could these dependencies changed to be for test only?

To avoid loading deps dynamically, could it be possible to somehow separate the schema2pojo functions for new kinds of code generation, e.g. for Scala/Android/...? Like having schema2pojo-core, schema2pojo-scalagen, schema2pojo-android etc? schema2pojo-scalagen could depend statically on *-core and having maven-plugin-core, maven-plugin-scalagen etc? I assume that most projects won't mix.

(I know that this probably isn't of common need, since most projects have no issue with bigger or smaller dependencies.)

If I understand correctly, the parts I need just are ~5 MB. Is the android support glued into the code or could it be removed (by me in a fork)? Scala could be removed in such a way, I assume. But probably such work and its maintenance would not be considered by my project anyway.

Steffen

Joe Littlejohn

unread,
Jun 4, 2018, 10:06:14 AM6/4/18
to jsonschema...@googlegroups.com
Can you simply add exclusions for these dependencies? Like so: https://stackoverflow.com/a/7405917/125825

--

Steffen Dettmer

unread,
Jun 4, 2018, 4:59:56 PM6/4/18
to jsonschema...@googlegroups.com
Hello again!

On Mon, Jun 4, 2018 at 4:05 PM, Joe Littlejohn <joelit...@gmail.com> wrote:
> Can you simply add exclusions for these dependencies? Like so:
> https://stackoverflow.com/a/7405917/125825

ohh, thank you so much! I didn't knew overriding and disabling
dependencies is possible at all.
This looks very promising! I made a prototype POM and so far it seems
to work well with very small footprint.

Steffen

Joe Littlejohn

unread,
Jun 5, 2018, 12:19:03 PM6/5/18
to jsonschema...@googlegroups.com
I did some further examination to refresh my memory on why the Android and Scala dependencies exist. 

For Scala we use a conversion library that itself depends on Scala, so we need Scala available to run that conversion process. For Android, we refer to a few of interfaces Android's interfaces, but we really don't need the actual classes on the classpath to do this. I'm going to remove the runtime dependency on Android for v1.0.0-alpha3. We just need Android for the integration tests, so that we can test the Parcelable types.

Thanks again for raising this!

steffen...@gmail.com

unread,
Jun 7, 2018, 9:07:18 AM6/7/18
to jsonschema2pojo-users
Hi,

thank you for the update.

I tested with v1.0.0-alpha2 (GSON mode) and the team updated some unit and integration tests and they pass.
Beside excluding some deps, I forced others to a different version, so my repository increased by only 3 MB, yeah!
Thank you so much for your great help!

In case someone else may ever have a similar requirement (which is very unlikely, as I have a *very* specific environment), as a point to start I include my "exclusions" as an example below. It was found empirically and may break things.

Steffen



pom.xml:/project/build/plugins:
            <!-- Do not use, may break everything. -->
            <plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>1.0.0-alpha2</version>
                <configuration>
                    <sourceDirectory>${basedir}/../../src/schema</sourceDirectory>
                    <targetPackage>com.example.pkg.json</targetPackage>
                    <!-- Netbeans *requires* generated sources to be in ${basedir}/target/generated-sources/PLUGIN/ -->
                    <outputDirectory>${project.build.directory}/generated-sources/jsonschema2pojo/</outputDirectory>
                    <annotationStyle>GSON</annotationStyle>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                   <dependency>
                        <groupId>org.jsonschema2pojo</groupId>
                        <artifactId>jsonschema2pojo-core</artifactId>
                        <version>1.0.0-alpha2</version>
                        <exclusions>
                            <exclusion>
                                <groupId>org.scala-lang</groupId>
                                <artifactId>scala-library</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>com.google.android</groupId>
                                <artifactId>android</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>net.sourceforge.collections</groupId>
                                <artifactId>collections-generic</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>com.google.code.javaparser</groupId>
                                <artifactId>javaparser</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>com.google.code.findbugs</groupId>
                                <artifactId>jsr305</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>com.squareup.moshi</groupId>
                                <artifactId>moshi</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>javax.validation</groupId>
                                <artifactId>validation-api</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>org.codehaus.jackson</groupId>
                                <artifactId>jackson-mapper-asl</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>org.codehaus.plexus</groupId>
                                <artifactId>plexus-utils</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>org.apache.maven.shared</groupId>
                                <artifactId>maven-shared-utils</artifactId>
                            </exclusion>
                            <exclusion>
                                <groupId>com.google.code.findbugs</groupId>
                                <artifactId>annotations</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                </dependencies>
            </plugin>

Joe Littlejohn

unread,
Jun 8, 2018, 7:23:32 AM6/8/18
to jsonschema...@googlegroups.com
Great. Thanks!

Based on the work you've done above, I'm also going to investigate removing the runtime dependency on Moshi.

steffen...@gmail.com

unread,
Jun 8, 2018, 11:15:19 AM6/8/18
to jsonschema2pojo-users
Hi,

I deployed a first version with it today and everything seems to work very well.
The developers like the tool and the code it generates and we think it will save us a lot of boring work.
Thank you so much for your great work and the spent efforts!

I wish you a great weekend!

Steffen
Reply all
Reply to author
Forward
0 new messages