无法从项目库(jar)引用Mule 4数据编织中的DWL脚本文件



我最近在Maven Central Repo中托管了一个mule应用程序。该应用程序包含两个java文件和一个dwl文件。dwl文件使用这些java文件来执行一些操作。这是我想在另一个应用程序(app2(中作为pom依赖项引用的主要应用程序(app1(。

主设备的名称为encryption-1.0.5-mule-application.jar

它包含的dwl脚本的名称是encryption.dwl。Java文件在jar文件/company包中提供。

情况1:如果我将这个主mule应用程序(app1(打包为一个jar,并将该应用程序安装到我的本地.m2 repo中,然后将其作为pom依赖项和另一个辅助mule应用软件(app2(的mule-maven插件的共享库。app2能够识别dwl脚本,并且在部署时可以工作。

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
<version>1.0.5</version>
</dependency>
<dependencies>

情况2:如果我在作用域为<system>的app2-pom.xml文件中包括app1依赖项,则包括<systemPath=";jarfilelocation/app1.jar">在其中添加一个共享库,然后将jar添加到app2的根文件夹中,部署后一切正常。

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
<version>1.0.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/encryption-1.0.5-mule-application.jar</systemPath>
</dependency>
<dependencies>

情况3:如果我将app1作为依赖项包含在app2pom.xml中,作用域为<provided>,并添加一个共享库,则jar将从上游下载并添加到app2的项目库中。但是app2无法识别项目库中可用的dwl脚本。如果不添加作用域,pom将使部署无效,从而导致失败。

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependencies>

我的目标是让app2在使用我们添加的pom依赖项成功下载jar后,识别app1的dwl文件以及Studio自动添加到app2的mule包资源管理器的项目库(PL(中的所有其他文件。

我已经可以在app2的PL中看到encryption-1.0.5-mule-application.jar下可用的所有app1文件,这些文件是使用pom依赖项获取的。

仍然无法在app2 mule XML数据编织中识别这些文件。我需要帮助弄清楚这一点。

注意:我还包括了使用mule-artifact.json 的各种组合

{
"name": "MyApp",
"minMuleVersion": "4.3.0",
"classLoaderModelLoaderDescriptor": {
"id": "mule",
"attributes": {
"exportedPackages": [
"company"
],
"exportedResources": [
"encryption/encryption.dwl",
"encryption.dwl",
"*/encryption.dwl",
"company/encryption.dwl"
]
}
}
}

我认为Studio不会识别依赖项中的文件。您需要编辑原始项目(即app1(。

顺便说一句,要正确地打包应用程序以供共享使用,您可能需要阅读https://help.mulesoft.com/s/article/How-to-add-a-call-to-an-external-flow-in-Mule-4.

我已经解决了这个问题。

起初,我认为<scope>provided</scope>在某种程度上造成了这个问题。我没有完全理解作用域的概念。我还试着通过<classifier>mule-application<classifier>。分类器不能是上面提到的类型mule-application是没有意义的。当我尝试将分类器用作mule-plugin,并重命名我之前下载的本地存储库jar,并在studio中重新部署我的mule应用程序时,我就知道了这一点。

事实上,问题是我向OSSRH发布的jar的名称。将值为mule-application的jar打包是无效的。像这个<packaging>mule-application</packaging>

后来,我发布了一个经过修改的pom.xml版本,其中<packaging></packaging>设置为jar。我还删除了mule-maven-plugin,因为它不允许使用类型为jar的包装注意:这是App1。

在上游发布后,我简单地引用了App2中生成的App1的Nexus依赖项,它运行得很好。

现在也不需要在App2中传递如下所示的共享库依赖项。此外,您不需要向mule-artifact.json添加任何内容。

<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sharedLibraries>
<sharedLibrary>
<groupId>com.github.xyz</groupId>
<artifactId>encryption</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>

最新更新