为什么 gradle 无法使用分类器找到我的本地 Maven 依赖项?
Why can't gradle find my local maven dependency with a classifier?
我有一个包,它是本机代码的 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 找不到此依赖项?
Re os-maven-plugin
: Java System Properties:
os.name
os.arch
os.version
是available in POMs。这些对您的工件分类器来说还不够吗?
关于您未找到的依赖项:Gradle dependencies doc mentions classifiers just in conjunction with JavaScript. The examples for dependencies there use just <groupId>:<artifactId>:<version>
. (Where did you get the 3-colon syntax with the additional :<classifier>
?) The POM Reference 提到 classifiers/qualifiers 作为版本的一部分,所以我会尝试:
dependencies {
// ...
compile 'foo.bar.baz:project:0.0.1-SNAPSHOT-osx-x86_64'
}
从 6.8 开始,Gradle 目前不支持使用分类器解决依赖关系,this issue 证实了这一点。
我有一个包,它是本机代码的 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 找不到此依赖项?
Re os-maven-plugin
: Java System Properties:
os.name
os.arch
os.version
是available in POMs。这些对您的工件分类器来说还不够吗?
关于您未找到的依赖项:Gradle dependencies doc mentions classifiers just in conjunction with JavaScript. The examples for dependencies there use just <groupId>:<artifactId>:<version>
. (Where did you get the 3-colon syntax with the additional :<classifier>
?) The POM Reference 提到 classifiers/qualifiers 作为版本的一部分,所以我会尝试:
dependencies {
// ...
compile 'foo.bar.baz:project:0.0.1-SNAPSHOT-osx-x86_64'
}
从 6.8 开始,Gradle 目前不支持使用分类器解决依赖关系,this issue 证实了这一点。