The problem with this configuration is that in the published pom.xml of my library the dependency is of type jar (by default) and declared like that:<dependency> <groupId>org.apache.sshd</groupId> <artifactId>apache-sshd</artifactId> <version>1.6.0</version> <!-- Should declare pom type --> <scope>compile</scope> <exclusions> <exclusion> <artifactId>*</artifactId> <groupId>org.slf4j<groupId> </exclusion> </exclusions></dependency>因此,当我尝试使用另一个项目中的已发布库时,它会失败,因为没有诸如 apache-sshd 之类的工件,因为它的类型应为 pom .那么如何使用Gradle正确发布所需的依赖关系呢?So when I try to use my published library from another project it fails as there is no such artifact as apache-sshd because it's type should be pom. So how to correctly publish desired dependency using Gradle?在带有Kotlin DSL的Gradle 5.3.1上运行.Running on Gradle 5.3.1 with Kotlin DSL.推荐答案尝试使用以下构造在Gradle中声明依赖项Try to use following construction for declaring dependency in Gradleapi("org.apache.sshd:apache-sshd:1.6.0@pom") { exclude(group = "org.slf4j") isTransitive = true}默认情况下,像Gradle一样使用所有依赖项作为jar类型.Maven插件使用此提取的类型在pom文件中生成依赖项部分.对于pom依赖性,必须将正确的值放入生成的文件的type字段中.但是,如果您为依赖项添加pom扩展名,则Gradle将无法解析此工件中声明的可传递依赖项.设置传递标记的值可以解决此问题.Looks like Gradle consumes all dependencies as jar type by default. And Maven plugin generates dependency section in pom file by using this extracted type. For pom dependency it is necessary to put correct value into type field of generated file. But if you put pom extension for your dependency, Gradle won't resolve transitive dependencies that are declared in this artifact. Set the value of transitive flag resolves this issue. 这篇关于如何在Gradle中使用Pom类型依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 20:31