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

yrdbyhpb  于 2023-05-05  发布在  Java
关注(0)|答案(1)|浏览(129)

我有一个共享库,它有一个实现org.eclipse.microprofile.config.spi.ConfigSource的类(我们称之为CustomConfigSource.java)。在共享库的META-INF/services文件夹中有一个名为“org.eclipse.microprofile.config.spi.ConfigSource”的文件,其中包含我的www.example.com类的路径CustomConfigSource.java。这样,我可以在继承共享库的任何子项目中使用该类作为eclipse的microprofile config的别名。
在我的子项目中,我添加了共享库作为依赖项。我想做的是从我的共享库中扩展CustomConfigSource类,并创建一个名为www.example.com的类CustomConfigSourceChild.java。为了在我的子项目中使用CustomConfigSourceChild作为eclipse的微配置文件配置的别名,我需要在子项目的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的路径。然而,事实并非如此,因为我只看到包含www.example.com的路径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文件,有什么建议吗?

相关问题