Vaibhav Aggarwal
4 min readApr 4, 2024

How to create a Mule SDK Custom Connector compatible with JDK 17?

Disclaimer:

The content provided in this Medium blog is for informational purposes only. It represents the views and opinions of the author at the time of publication. The author makes no representations or warranties regarding the accuracy, completeness, or suitability of the information presented in this blog.

I also want to extend a sincere apology for any errors or mistakes you may come across in this post. While I strive for accuracy and clarity in every piece I write, I’m only human, and sometimes errors slip through despite my best efforts. If you notice anything that doesn’t seem quite right or have any feedback at all, please don’t hesitate to reach out. Your input helps me improve and ensures that future content is even better.

Overview:

In this blog post, we’ll create a basic Mule SDK based custom connector for JDK 17. We’ll publish it to exchange as well and try to use it in Mule App running on Java 17.

Prerequisites:

  1. Anypoint Studio: 7.17 Configured to use JDK 17
  2. Open JDK 8
  3. Maven 3.9.6

Task 1: Setup your settings.xml file

Add the server tag in settings.xml file

<server>
<id>exchange-server</id>
<username>username</username>
<password>********</password>
</server>

Add profiles in settings.xml file

<profile>
<id>archetype-repository</id>
<repositories>
<repository>
<id>archetype</id>
<name>Mule Repository</name>
<url>https://repository-master.mulesoft.org/nexus/content/repositories/public</url>
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
</profile>

<profile>
<id>mule-extra-repos</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>mule-public</id>
<url>https://repository.mulesoft.org/nexus/content/repositories/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mule-public</id>
<url>https://repository.mulesoft.org/nexus/content/repositories/public</url>
</pluginRepository>
</pluginRepositories>
</profile>

Task 2: Generate a project structure for custom connector

Select a folder and run the following command

mvn org.mule.extensions:mule-extensions-archetype-maven-plugin:generate

Provide the following details:

  1. Enter the name of the extension (empty for default): demo
  2. Enter the extension’s groupId (empty for default): com.personal.connectors
  3. Enter the extension’s artifactId (empty for default): demo
  4. Enter the extension’s version (empty for default): 1.0.0
  5. Enter the extension’s main package (empty for default): Leave it blank

Task 3: Import the project into the Anypoint Studio

Configure the JDK 17 in Anypoint Studio by following below steps

Window -> Preferences -> Java -> Installed JREs

Click Apply and Close

For now, we can delete the test-mule-config.xml file and DemoOperationsTestCase.java

Task 4: Add the JavaVersionSupport to the custom connector to make it compatible with Java 17

<dependencies>
<dependency>
<groupId>org.mule.sdk</groupId>
<artifactId>mule-sdk-api</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>

Now add the JavaVersionSupport annotation in the Extension.java file under src/main/java

Add @JavaVersionSupport({JavaVersion.JAVA_17, JavaVersion.JAVA_11, JavaVersion.JAVA_8}) in Extension.java file

Task 5: Maven Clean Install the connector and use it in the Mule App

Go to the project folder and run the below command

mvn clean install

Task 6: Add the connector to the Mule App running on Java 17

Add the following dependency to your Mule App

<dependency>
<groupId>com.personal.connectors</groupId>
<artifactId>demo</artifactId>
<version>1.0.8</version>
<classifier>mule-plugin</classifier>
</dependency>

Task 7: Publish the connector to Anypoint Exchange

Add the following repositories

<repositories>
<repository>
<id>exchange-server</id>
<name>Corporate Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/${project.groupId}/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>anypoint-exchange-v3</id>
<name>Anypoint Exchange V3</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
<layout>default</layout>
</repository>
</repositories>

<distributionManagement>
<!-- Target Anypoint Organization Repository -->
<repository>
<id>exchange-server</id>
<name>Corporate Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/${project.groupId}/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>

Also change the project.groupId to Anypoint Platform orgId

<groupId>${orgId}</groupId>
<artifactId>demo</artifactId>
<version>1.0.8</version>

Run the following command

mvn clean deploy

This connector should run on the Mule Apps running on Java 17. I hope you’ve enjoyed learning about this topic. Please provide your feedback in the comments. Follow for more blogs and stay tuned for further insights!