Search code examples
jcloudsballerina

Newbie / Ballerina Build with gson issue while running the build


I am a newbie in Ballerina. I am importing a platform lib as a executable jar , which is an inter op method call in java using openstack swift api using jclouds.

There has been a known issue with JCLOUDS where it fails to build due to gson version issues higher than 2.5 not compatible with jclouds Apache jclouds java.lang.NoSuchMethodError when using Rackspace in a Spring Boot application.

I face the same error when trying to execute this inter op method call from my bal file which was built during ballerina build. Upon inspection of the jar, which ballerina created during the build of the project , it shows that the jar is created with a set of prebuilt dependencies with gson 2.7.

is there any way i can change this dependency , i am not also very clear on how ballerina packages all this jars during the build phase of bal files.

It will help to have a detailed understanding on what happens below the hood when ballerina build is invoked.


Solution

  • The following GitHub issue explains why we had to package com.google:gson:2.7 with any Ballerina executable jar.

    https://github.com/ballerina-platform/ballerina-lang/issues/17878

    Let me try to explain why Ballerina compiler packages some third-party jars with the executable jar created for your Ballerina program. We can categorize these third-party jars into two main categories.

    1. Jar dependencies of the Ballerina runtime
    2. Jar dependencies of each Ballerina module that you've imported in your program.

    Dependencies of the Ballerina runtime

    Every Ballerina executable program contains the Ballerina runtime - the bare minimum layer on top of the JVM that is required to execute any Ballerina program. Runtime contains the Java implementations of Ballerina values, types, Ballerina modules in the lang lib, and the runtime type checker logic. This layer is essential to enforce Ballerina language semantics on top of the JVM.

    At the moment, Ballerina runtime depends on many third-party Java libraries. GSON is one such library that we are planning to remove soon. You can get more details from the above issue.

    Dependencies of a Ballerina module

    Each Ballerina module, whether it belongs to the standard library or whether you pulled it from the Ballerina central, may depend on one or more third-party Java libraries. The Ballerina module author lists these dependencies in Ballerina.toml of the project in which they develop the Ballerina module. Here are some examples.

    While I was working on this answer, I realized the requirement of a debugging tool that emits the details of third-party libraries. It would be nice if this tool can be integrated into the ballerina command-line tool. Here is the issue that I've created to track this.

    https://github.com/ballerina-platform/ballerina-lang/issues/20116