Helidon MP/Maven:在从共享库继承的子项目中添加自定义配置源的路径

问题描述 投票:0回答:0

我有一个共享库,它有一个实现 org.eclipse.microprofile.config.spi.ConfigSource 的类(我们称之为 CustomConfigSource.java)。在共享库的 META-INF/services 文件夹中,有一个名为“org.eclipse.microprofile.config.spi.ConfigSource”的文件,其中包含我的 CustomConfigSource.java 类的路径。这样我就可以在继承共享库的任何子项目中将该类用作 eclipses 的 microprofile 配置的别名。

在我的子项目中,我添加了共享库作为依赖项。我想要做的是从我的共享库扩展 CustomConfigSource 类并创建一个名为 CustomConfigSourceChild.java 的类。为了在我的子项目中使用 CustomConfigSourceChild 作为 eclipse 的 microprofile 配置的别名,我需要在子项目的 META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource 文件中添加 CustomConfigSourceChild.java 的路径。

换句话说,这是我的共享库的资源文件夹结构:


├── META-INF
│   └── services
│       └── org.eclipse.microprofile.config.spi.ConfigSource

我的子项目的资源文件夹:


├── META-INF
│   └── services
│       └── org.eclipse.microprofile.config.spi.ConfigSource

我的子项目和共享库的 org.eclipse.microprofile.config.spi.ConfigSource 文件都包含到它们各自的自定义配置源实现 java 文件的路径。

现在问题来了。当我编译我的子项目 (mvn clean package) 时,在我的子项目的 target/META-INF/services/ 中,理想情况下我应该看到 CustomConfigSource.java 和 CustomConfigSourceChild.java 的路径。但是,情况并非如此,因为我只看到包含 CustomConfigSource.java 的路径。

我尝试通过添加以下 maven-shade-plugin 来解决这个问题:

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource</resource>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

理想情况下应该合并共享库和子项目中的 META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource 文件,但这没有用。

关于如何合并来自共享库和子项目的 META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource 文件的任何建议?

java maven maven-shade-plugin helidon eclipse-microprofile-config
© www.soinside.com 2019 - 2024. All rights reserved.