Service loader在使用gradle时找不到提供者,但在maven中运行正常。

huangapple go评论143阅读模式
英文:

Service loader not can't find providers when using gradle but works with maven

问题

我已经创建了一个存储库,位于 https://github.com/bigbang4u2/query-dsl-hibernate-types (这是从 这里 复制过来的)。

由我创建的存储库 这里 包含了 Gradle 和 Maven。在使用 Maven 时,所有提供者都会正确加载到服务加载程序中(请参阅 querydsl-ext-apt,其中提供者存在并列在 META-INF/services 中)。不知何故,不清楚为什么在使用 Gradle 时,所有这些都被忽略,只生成了与 querydsl 本身相关的 QClass。

我需要使用 Gradle 进行工作,因为这是我在项目中使用的。

请帮忙。

英文:

I have created a repository here https://github.com/bigbang4u2/query-dsl-hibernate-types (This has been copied from here).

Repository created by me here contains both gradle and maven. When using maven all providers are loaded correctly in service loader (see querydsl-ext-apt where providers are present and also listed in META-INF/services). For some reason don't know why maven is able to generate all querydsl QClass with extensions listed in META-INF but when I use gradle all these are ignored and just generate QClasses which are native to querydsl

I need to to work with gradle as that's what I am using in my project

Kindly help

答案1

得分: 1

因为Maven将不应混在一起的东西混在一起,而Gradle会正确地分离它们。
使用你定义的服务的类作为注解处理的一部分运行。
因此,你的服务不需要作为“implementation”依赖项,而是作为“annotationProcessor”依赖项。

将以下代码段替换为:

annotationProcessor project(':querydsl-ext-apt')

这样你的服务将在需要的地方被找到。

英文:

Because Maven throws together things that should not be thrown together which Gradle properly separates.
The class using the services you define is run as part of annotation processing.
So your services are not needed as implementation dependencies, but as annotationProcessor dependencies.

Replace

implementation project(':querydsl-ext-apt')

by

annotationProcessor project(':querydsl-ext-apt')

and your services are found where necessary.

huangapple
  • 本文由 发表于 2023年3月3日 18:19:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75625807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定