'TokenCredentialTrait not found even when used

I have proper credentials below in the connection String, even after giving the proper connection string does not work. Even though I use the credential variable or not it throws this exception.

public static void main(String[] args) {
    startReciever();
    TokenCredential credential = new DefaultAzureCredentialBuilder()
            .build();
    ServiceBusSenderClient sender = new ServiceBusClientBuilder()
            .credential(CONNECTION_STRING, credential)
            .sender()
            .queueName(SIMPLE)
            .buildClient();
    List<ServiceBusMessage> messages = Arrays.asList(
            new ServiceBusMessage("Hello world").setMessageId("1"),
            new ServiceBusMessage("Bonjour").setMessageId("2"));
    sender.sendMessages(messages);
    sender.close();
}

private static void startReciever() {
    TokenCredential credential = new DefaultAzureCredentialBuilder()
            .build();
    ServiceBusReceiverAsyncClient receiver = new ServiceBusClientBuilder()
            .credential(CONNECTION_STRING, credential)
            .receiver()
            .queueName(SIMPLE)
            .buildAsyncClient();
    Flux<ServiceBusReceivedMessage> serviceBusReceivedMessageFlux = receiver.receiveMessages();
    Disposable subscription = serviceBusReceivedMessageFlux.subscribe(message -> {
        System.out.printf("Received Seq #: %s%n", message.getSequenceNumber());
        System.out.printf("Contents of message as string: %s%n", message.getBody());
    });
    subscription.dispose();
    receiver.close();
}

Dependencies:

<dependencies>
    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-core</artifactId>
        <version>1.13.0</version>
    </dependency>
    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-messaging-servicebus</artifactId>
        <version>7.7.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.azure/azure-identity -->
    <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-identity</artifactId>
        <version>1.4.6</version>
    </dependency>

</dependencies>

Error is

java: cannot access com.azure.core.client.traits.TokenCredentialTrait
class file for com.azure.core.client.traits.TokenCredentialTrait not found


Solution 1:[1]

Changing the dependency to

<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-core</artifactId>
    <version>1.26.0</version>
</dependency>

solves this issue. azure docs had given 1.13.0 in docs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abhijeet Mishra