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

Unable to reference to DWL script files in Mule 4 dataweave from Project Libraries(jar)

我最近在 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 存储库中,然后将其作为 pom 依赖项和另一个辅助 mule 应用程序 (app2) 的 mule-maven-plugin 的共享库包含在内。 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: 如果我在 app2 pom.xml 文件中包含 app1 依赖项,范围为 <system>,在其中包含一个 并添加一个共享库,那么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 作为依赖项包含在 app2 pom.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 识别 app1 的 dwl 文件和所有其他文件,这些文件在成功下载 jars 后由 Studio 自动添加到 app2 的 mule 包资源管理器的项目库 (PL) 中使用我们添加的 pom 依赖项。

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

Still I couldn't get those files recognised in the app2 mule XML dataweave. I need help figuring this out.

注意:我还包括了各种使用 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 并在工作室中重新部署我的 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>