gradleguidewire

How do I specify Java dependecies in Guidewire's v10 build.gradle file?


We are using GW ClaimCenter 10.2. Within our application we use several external Java dependencies, e.g. jackson-databind. Up until now we used to put those JARs into the folder ClaimCenter/modules/configuration/plugins/shared/basic/lib.

Since we migrated from v8 to v10 a couple of months ago, we were wondering if we could leverage the "new" Gradle build system to import those dependencies. We tried to specify the dependencies like this in ClaimCenter/modules/configuration/build.gradle: build.gradle

Unfortunately, GW Studio did not recognize the dependencies and the application failed to start.

Is there a way to define and use external dependencies in Gradle for GW ClaimCenter?


Solution

  • The challenge is that any modification to the project or configuration level build.gradle files is not detected while building the project in Guidewire Studio which has intentionally been modified to get rid of build tools support. I figured out a way to generate the gradle wrapper by running gwb wrapper. Then using the wrapper we can run gradlew.bat build and force a re-compile of project-level and configuration-level gradle files. However, Studio still doesn't detect the jar, and while some hacks can allow you to add a jar to the WAR / EARs classpath, it may not be recommended to do so. Out of the box, it appears that all dependencies are loaded from the repository jar or Guidewire expects the jars to be present in one of the local directories of the source code. One of the below files can be modified to add mavenCentral() as a valid repository along with the compile or implementation dependency.

    1. Platform level build.gradle that is present in the project root.

    2. Configuration level build.gradle

    3. gw-build.gradle present in modules/script

    Also make sure to register the central maven repository using

      repositories {
        mavenCentral()
        maven { url rootProject.file('repository') }
      }
    

    The recommended and correct way to add external libs is to stick to the plugins/shared/lib folder. Please note that plugins/shared/basic has been deprecated post v8 and should be avoided. Any modifications or tweaks made to the above gradle files would be putting your project at constant risk of a minor version upgrade overwriting one of the files. So while what you are looking to achieve is doable, it is not the recommended or correct way of adding dependencies. It appears that Guidewire uses Gradle mostly for building the platform level and studio code and doesn't expect customers to modify it. Placing a jar in a local directory and then referencing it in the build.gradle file defeats the purpose of having a gradle-based dependency management and that's why the former approach is safer.