Gradle -> Geotools -> FatJar -> missing classes

I have a project that I build FatJar from. Recently I have included additional dependencies from geotools. What I quickly discovered is that due to the geotools architecture I need to merge the META-INF/services, which I do using the mergeServiceFiles() in my shadowJar task. However, even with the mergeServiceFiles I still get an error:
WARNING: Can't load a service for category "Operation". Cause is "ServiceConfigurationError: org.geotools.api.coverage.processing.Operation: Provider org.geotools.coverage.processing.operation.ShadedRelief could not be instantiated".

Both, org.geotools.api.coverage.processing.Operation and the org.geotools.coverage.processing.operation.ShadedRelief are present in my dependencies (gt-api and gt-coverage) and are also included in the services.

Also, after inspecting the generated FatJar I can see that classes org.geotools.api.coverage.processing.Operation and org.geotools.coverage.processing.operation.ShadedRelief are present in the jar and org.geotools.api.coverage.processing.Operation is present in the META-INF/services and it does contain org.geotools.coverage.processing.operation.ShadedRelief.

My Gradle settings is in line with the GeoTools for creating FatJars FAQ instruction – I am using Gradle’s shadowJar plugin with the mergeServiceFiles task which is equivalent of the Maven’s shadow plugin with the ServicesResourceTransformer:

plugins {
    id("com.gradleup.shadow") version "8.3.0"
    java
}

group = "test.it"
version = "0.0.1"

application {
    mainClass.set("test.it.ApplicationKt")
}

repositories {
    maven { url = uri("https://repo.osgeo.org/repository/release/") }
    mavenCentral()
}

dependencies {
    implementation("org.geotools:gt-coverage:31.2")
    implementation("org.geotools:gt-main:31.2")
    implementation("org.geotools:gt-api:31.2")
    implementation("org.geotools:gt-geotiff:31.2")
    implementation("org.geotools:gt-tile-client:31.2")
    implementation("org.geotools.xsd:gt-xsd-kml:31.2")
    implementation("org.geotools:gt-epsg-hsql:31.2")
    implementation("org.osgeo:proj4j:0.1.0")

}

tasks {
    shadowJar {
        mergeServiceFiles()
        isZip64 = true
        archiveFileName.set("${project.name}-${project.version}.jar")
        manifest {
            attributes["Main-Class"] = "test.it.ApplicationKt"
            //fix for the imageio vendor!=null error
            ///questions/7051603/jai-vendorname-null/18495658#18495658
            attributes["Specification-Title"] = "Java Advanced Imaging Image I/O Tools"
            attributes["Specification-Version"] = version
            attributes["Specification-Vendor"] = "Sun Microsystems, Inc."
            attributes["Implementation-Title"] = "com.sun.media.imageio"
            attributes["Implementation-Version"] = version
            attributes["Implementation-Vendor"] = "Sun Microsystems, Inc."
        }
    }
}

I tried (with no luck):

  • using all versions of geo-tools from 20.0 to 31.2
  • using JAVA 11, 17 and 21 for both, gradle and running the actual JAR
  • updating Gradle to the most recent version 8.10

It works fine when run with the -classpath including locations of the gt-api and gt-coverage jars.

UPADATE 12/09/2024

A temporary solution – adding exclude("META-INF/services/org.geotools.api.coverage.processing.*") to the shadowJar task helps. This resolves the issue for that particular missing Class throwing the error.

As described in the FAQ, you need to take care when combining modules with META-INF/services directories containing files of the same name. The recommendation is to use the Maven shade plugin, as far as I know none of the GeoTools developers uses gradle but I would expect there to be an equivalent plugin that can combine files rather than overwriting them.

If you work it out then could you add the information to the GeoTools FAQ for the benefit of others.

3

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật