我正在尝试使用 mule maven 插件创建构建,它必须执行 MUnit 测试用例。我使用了一个配置属性,它已配置为 app-{mule.env}.yaml 在运行应用程序时它工作正常,因为我传递了参数 mule.env=dev 但在使用 mule maven 插件创建 maven 构建时导致失败下面是POM结构
MUnit 特定配置:
<configuration>
<environmentVariables>
<mule.env>dev</mule.env>
<mule.key>23454646576575675</mule.key>
</environmentVariables>
<coverage>
<runCoverage>true</runCoverage>
<failBuild>true</failBuild>
<requiredApplicationCoverage>${app.coverage}</requiredApplicationCoverage>
<requiredResourceCoverage>0</requiredResourceCoverage>
<requiredFlowCoverage>0</requiredFlowCoverage>
<formats>
<format>console</format>
<format>html</format>
</formats>
</coverage>
</configuration>
完成 POM
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>myapp</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>mule-application</packaging>
<name>app</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mule.version>4.2.1</mule.version>
<munit.version>2.2.1</munit.version>
<app.runtime>4.2.1</app.runtime>
<mule.maven.plugin.version>3.2.7</mule.maven.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<server>anypoint-platform</server>
<environment>${environment}</environment>
<applicationName>${application.name}</applicationName>
<muleVersion>${mule.version}</muleVersion>
<businessGroup>${business.group}</businessGroup>
<properties>
<mule.env>${mule.env}</mule.env>
<mule.key>${mule.key}</mule.key>
<anypoint.platform.analytics_base_uri>https://analytics-ingest.anypoint.mulesoft.com</anypoint.platform.analytics_base_uri>
<anypoint.platform.client_id>${client-id}</anypoint.platform.client_id>
<anypoint.platform.client_secret>${client-secret}</anypoint.platform.client_secret>
<anypoint.platform.base_uri>https://anypoint.mulesoft.com</anypoint.platform.base_uri>
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
<plugin>
<groupId>com.mulesoft.munit.tools</groupId>
<artifactId>munit-maven-plugin</artifactId>
<version>${munit.version}</version>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<environmentVariables>
<mule.env>dev</mule.env>
<mule.key>23454646576575675</mule.key>
</environmentVariables>
<coverage>
<runCoverage>true</runCoverage>
<failBuild>true</failBuild>
<requiredApplicationCoverage>${app.coverage}</requiredApplicationCoverage>
<requiredResourceCoverage>0</requiredResourceCoverage>
<requiredFlowCoverage>0</requiredFlowCoverage>
<formats>
<format>console</format>
<format>html</format>
</formats>
</coverage>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-http-connector</artifactId>
<version>1.4.1</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-sockets-connector</artifactId>
<version>1.1.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.modules</groupId>
<artifactId>mule-secure-configuration-property-module</artifactId>
<version>1.0.2</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-runner</artifactId>
<version>2.1.5</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency> <dependency>
<groupId>com.mulesoft.munit</groupId>
<artifactId>munit-tools</artifactId>
<version>2.1.5</version>
<classifier>mule-plugin</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mule.connectors</groupId>
<artifactId>mule-jms-connector</artifactId>
<version>1.3.6</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>anypoint-mq-connector</artifactId>
<version>3.1.0</version>
<classifier>mule-plugin</classifier>
</dependency>
<dependency>
<groupId>org.mule.modules</groupId>
<artifactId>mule-apikit-module</artifactId>
<version>1.1.9</version>
<classifier>mule-plugin</classifier>
</dependency>
</dependencies>
<repositories>
<repository>
<id>anypoint-exchange</id>
<name>Anypoint Exchange</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/maven</url>
<layout>default</layout>
</repository>
<repository>
<id>mulesoft-releases</id>
<name>MuleSoft Releases Repository</name>
<url>https://repository.mulesoft.org/releases/</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
当我尝试使用 Maven 构建时,它会出现以下错误
INFO 2020-01-02 13:43:20,651 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.munit.runner.remote.api.server.RunnerServer: Waiting for client connection
INFO 2020-01-02 13:43:21,155 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.munit.runner.remote.api.server.RunnerServer: Client connection received from 127.0.0.1 - true
INFO 2020-01-02 13:43:21,564 [[MuleRuntime].io.03: [my-app].io@org.mule.munit.runner.remote.api.server.RunnerServer.initialise:154 @6bc6d88] org.mule.runtime.api.message.AbstractMuleMessageBuilderFactory: Loaded MuleMessageBuilderFactory implementation 'org.mule.runtime.core.internal.message.DefaultMessageBuilderFactory' from classloader 'java.net.URLClassLoader@5177e388'
org.mule.runtime.api.exception.MuleRuntimeException: java.util.NoSuchElementException: No value present
Caused by: java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.lambda$null$15(LazyMuleArtifactContext.java:278)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.lambda$createComponents$16(LazyMuleArtifactContext.java:278)
at org.mule.runtime.core.api.util.ClassUtils.lambda$withContextClassLoader$10(ClassUtils.java:794)
at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:227)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:849)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:813)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:793)
at org.mule.runtime.config.internal.LazyMuleArtifactContext.createComponents(LazyMuleArtifactContext.java:225)
应用程序-dev.yaml
anypoint:
mq:
name: "in-queue"
url: https://mq-us-west-1.anypoint.mulesoft.com/api/v1
clientId: "![0iop3V64o9uyhffvvn605a9wLr/kuoqX2B6tcMrt2A6MSIPg3f0zR0+W/Cv]"
clientSecret: "![l0vHmQFIgKjoii8998&*07dsdsfdd4LaMdsfdsEHcxS0]"
该应用程序及其测试用例在 Anypoint Studio 中正常工作,但在 Maven 构建中唯一失败。