Projects need fixing in Anypoint Studio
Typically I find that some troubleshooting and configuration is required to get an imported project to a state where it builds and the unit tests run, and the reasons usually aren’t obvious.
Importing a project
Most Mulesoft developers would have made the mistake, at least once, of trying to import a project using one of the options under the ‘General’ section, as that’s the first displayed in the import options window. The project appears to load, if that’s done, but it obviously wouldn’t even build.
In Anypoint Studio’s Package Explorer panel, right-click and select ‘Import…’. The correct option in the next menu is ‘Anypoint Studio’ -> ‘Anypoint Studio project from File System’.
The Project Root will be the directory cloned from the GitHub repository (where applicable). If this is done correctly, the project name and server runtime fields should be automatically populated.
Error Logs
The Console window, which we’d assume would reveal all messages in their verbosity, won’t actually display all the low-level errors that might prevent unit tests running - those errors are printed to an error log window that is, for some reason, hidden by default in Anypoint Studio.
Select ‘Window’ -> ‘Show View’ -> ‘Other…’.
Search for ’error’ in the filter field, and select ‘General’ -> ‘Error Log’.
Authentication
We sometimes get the following message when Anypoint Studio attempts to fetch dependencies during a build:
[ERROR] Failed to execute goal on project
[...]
Could not resolve dependencies for project
[...]
(https://maven.anypoint.mulesoft.com/api/v2/maven): status code: 401, reason phrase: Unauthorized (401) -> [Help 1]
The reason for this is Anypoint Studio isn’t authenticated with whatever service is hosting the dependencies - usually this will be Anypoint Exchange.
In the Preferences window, navigate to ‘Anypoint Studio’ -> ‘Authentication’. If the login details for Anypoint Exchange are listed, delete them and sign in again. Anypoint Studio should then be able to download dependencies when the project is cleaned and rebuilt.
Missing development configuration
Another very common error we encounter is something like the following:
ERROR [Embedded] org.mule.runtime.module.deployment.internal.DefaultArchiveDeployer: PropertyNotFoundException: Couldn't find configuration property value for key ${mule.env}
org.mule.runtime.deployment.model.api.DeploymentInitException: PropertyNotFoundException: Couldn't find configuration property value for key ${mule.env}
The issue here is that Anypoint Studio or MUnit is looking at the editor’s run configuration for the environment name, and, for some reason, is failing to read it from the project’s configurations.
Select ‘Run’ -> ‘Run Configurations…’.
In the Run Configurations window, select the project name under the MUnit section. The Environment tab should display the following:
- mule.env = dev
- mule.key = [Encryption Key]
The same environment variables might need adding to the Debug configuration also.
MUnit DB Server does not support Java 17
Currently MUnit and Java version 17 aren’t entirely compatible with each other, and this causes all sorts of problems when trying to test, build and deploy applications.
ERROR
org.mule.runtime.deployment.model.api.DeploymentInitException: JavaVersionNotSupportedByExtensionException: Extension 'MUnit DB Server' does not support Java 17. Supported versions are: [1.8, 11]
There are two possible fixes. The quickest is to change the Java Runtime to a version that’s more compatible with the version of MUnit. Select ‘Window’ -> ‘Preferences’. Usually this means downgrading the JRE.
In the Preferences window, select ‘Java’ -> ‘Installed JREs’. In the list of installed Java runtimes, select an older version, if it’s available.
Alternatively, if the MUnit DB Server module isn’t needed for the project, references to it can be removed from the pom.xml file. The section to comment out will look something like:
<dependency>
<groupId>com.mulesoft.munit.utils</groupId>
<artifactId>munit-dbserver-module</artifactId>
<version>2.0.2</version>
<scope>test</scope>
<classifier>mule-plugin</classifier>
</dependency>