Gradle Task Fails with IllegalArgumentException: identity-provider not found

I am working on a Gradle task that fetches a GraphQL schema and saves it to a file. The task needs to load configuration details from a YAML file (application-dev.yml). However, I keep encountering an error that says “identity-provider not found”. I’m using the SnakeYAML library to parse the YAML file.

Here is the relevant code in my build.gradle.kts:

// Load configuration from YAML
fun loadConfig(): Map<String, String> {
    val yaml = Yaml()
    val inputStream = FileInputStream("src/main/resources/application-dev.yml")
    val data: Map<String, Any> = yaml.load(inputStream)
    println("Data loaded from YAML: $data")

    val customsConfig = data["customs"] as? Map<*, *> ?: run {
        println("Customs key not found or not a map!")
        throw IllegalArgumentException("customs not found")
    }
    println("Customs Config: $customsConfig")

    val identityProviderConfig = customsConfig["identity-provider"] as? Map<*, *> ?: run {
        println("Identity-provider key not found or not a map!")
        throw IllegalArgumentException("identity-provider not found")
    }
    println("Identity Provider Config: $identityProviderConfig")

    val tokenConfig = identityProviderConfig["token"] as? Map<*, *> ?: run {
        println("Token key not found or not a map!")
        throw IllegalArgumentException("token not found")
    }
    println("Token Config: $tokenConfig")

    return tokenConfig as Map<String, String>
}

// Task to fetch GraphQL schema
tasks.register("fetchSchema") {
    doLast {
        try {
            println("Loading configuration...")
            val config = loadConfig()
            val clientId = config["client-id"] ?: throw IllegalArgumentException("client-id not found")
            val clientSecret = config["client-secret"] ?: throw IllegalArgumentException("client-secret not found")
            val token = fetchToken(clientId, clientSecret)
            println("Token fetched: $token")
            println("Fetching GraphQL Schema...")
            fetchGraphQLSchema("https://xxx-data.api.dev.xxx.com/graphql", token, "src/main/resources/schema2.graphql")
            println("Schema has been fetched successfully.")
        } catch (e: Exception) {
            println("An error occurred: ${e.message}")
            e.printStackTrace()
        }
    }
}

And here is the application-dev.yml content:

customs:
  bridge:
    public-url: http://localhost:8080
  security:
    post:
      user:
        creation:
          enabled: false
  multi-tenancy:
    enabled: true
    default:
      maxPoolSize: 10
      minIdle: 0
      connectionTimeout: 5000
      idleTimeout: 20000
      maxLifetime: 600000
      driverClassName: oracle.jdbc.driver.OracleDriver
  identity-provider:
    token:
      url: https://login.dev.XXX.com/connect/token
      client-id: placeholder_client_id
      tenant-id: placeholder_tenant_id
      scope: placeholder_scope
      client-secret: placeholder_client_secret

I tried to load the YAML configuration and fetch a token using the fetchSchema task. I expected the task to load the configuration successfully and proceed to fetch the GraphQL schema. However, I encountered an error indicating that the “identity-provider” key was not found or not a map.

The console output is as follows:

> Task :fetchSchema
Loading configuration...
Data loaded from YAML: {server={port=8080, allow={origin=*}, tomcat={max-swallow-size=10MB}}, spring={sql={init-mode=never}, output={ansi={enabled=always}}, resources={cache-period=60000, chain={cache=true, enabled=true}}, thymeleaf={cache=false}, ...
Identity-provider key not found or not a map!
An error occurred: identity-provider not found

Could someone help me identify what might be wrong with my configuration loading logic or my YAML file?

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