如何解决为什么 gradle 无法使用分类器找到我的本地 Maven 依赖项?
我有一个包,它是本机代码的 JNI 包装器,因此依赖于平台。我想使用 os-maven-plugin 创建一个特定于平台的 jar。我的pom相关部分如下:
<groupId>foo.bar.baz</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.1</version>
</extension>
</extensions>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<classifier>${os.detected.classifier}</classifier>
</configuration>
</plugin>
</plugins>
// ...
运行 mvn clean install
后,似乎构建了正确的工件:
$ ls /Users/erip/.m2/repository/foo/bar/baz/project/0.0.1-SNAPSHOT
_remote.repositories project-0.0.1-SNAPSHOT-osx-x86_64.jar
maven-metadata-local.xml project-0.0.1-SNAPSHOT.pom
但是,当我将此依赖项添加到我的 gradle 文件时...
repositories {
// ...
mavenLocal()
}
dependencies {
// ...
compile 'foo.bar.baz:project:0.0.1-SNAPSHOT:osx-x86_64'
}
并尝试构建,gradle 说它找不到文件:
$ ./gradlew clean build
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find foo.bar.baz:project:0.0.1-SNAPSHOT.
Searched in the following locations:
...
- file:/Users/erip/.m2/repository/foo/bar/baz/project/0.0.1-SNAPSHOT/project-0.0.1-SNAPSHOT.pom
Required by:
project :
它在现有的 pom 中查找,但无法解析 jar,那么为什么 gradle 找不到此依赖项?
解决方法
从 6.8 开始,Gradle 目前不支持使用分类器解决依赖关系,this issue 已证实。
,回复os-maven-plugin
:Java System Properties:
os.name
os.arch
os.version
是 available in POMs。这些对于您的工件分类器来说还不够吗?
关于您未找到的依赖项:Gradle dependencies doc 提到 分类器 只是与 JavaScript 结合使用。那里的依赖项示例仅使用 <groupId>:<artifactId>:<version>
。 (您从哪里获得带有附加 :<classifier>
的 3 冒号语法?)POM Reference 提到分类器/限定符作为版本的一部分,所以我会尝试:
dependencies {
// ...
compile 'foo.bar.baz:project:0.0.1-SNAPSHOT-osx-x86_64'
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。