在依赖性分类器中使用继承属性会导致构建失败

在依赖性分类器中使用继承属性会导致构建失败

本文介绍了Maven:在依赖性分类器中使用继承属性会导致构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出三个POM文件:


  • C取决于B。

  • B继承自A 。

  • 我可以构建A和B

  • C因为依赖于B而无法构建。

  • C depends on B.
  • B inherits from A.
  • I can build A and B
  • C fails to build because of its dependency on B.

完整的源代码和构建输出包含在下面供您查看。

The full source-code and build output is included below for your review.

这是A的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.foo</groupId>
    <artifactId>A</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>A</name>
    <repositories>
        <repository>
            <id>foo releases</id>
            <name>libs-releases-local</name>
            <layout>default</layout>
            <url>http://foo.net/artifactory/libs-releases-local</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.eclipse.swt</groupId>
            <artifactId>swt</artifactId>
            <classifier>${swt.classifier}</classifier>
            <version>3.6.1</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>windows-x86</id>
            <properties>
                <swt.classifier>win32-x86</swt.classifier>
            </properties>
        </profile>
    </profiles>
</project>

这是B的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.foo</groupId>
        <artifactId>A</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../A</relativePath>
    </parent>
    <artifactId>B</artifactId>
    <packaging>jar</packaging>
    <name>B</name>
    <profiles>
        <profile>
            <id>windows-x86</id>
            <properties>
                <swt.classifier>win32-x86</swt.classifier>
            </properties>
        </profile>
    </profiles>
</project>

这是C的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.foo</groupId>
    <artifactId>C</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>C</name>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>B</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>

以下是C的构建输出:

------------------------------------------------------------------------
Building C
   task-segment: [install]
------------------------------------------------------------------------
[compiler:compile]
Nothing to compile - all classes are up to date
Downloading: http://foo.net/artifactory/libs-releases-local/org/eclipse/swt/swt/3.6.1/swt-3.6.1-${swt.classifier}.jar
[WARNING] Unable to get resource 'org.eclipse.swt:swt:jar:${swt.classifier}:3.6.1' from repository foo releases (http://foo.net/artifactory/libs-releases-local): Error transferring file: foo.net
Downloading: http://repo1.maven.org/maven2/org/eclipse/swt/swt/3.6.1/swt-3.6.1-${swt.classifier}.jar
Unable to find resource 'org.eclipse.swt:swt:jar:${swt.classifier}:3.6.1' in repository central (http://repo1.maven.org/maven2)
------------------------------------------------------------------------
[ERROR]BUILD ERROR
------------------------------------------------------------------------
Failed to resolve artifact.

Missing:
----------
1) org.eclipse.swt:swt:jar:${swt.classifier}:3.6.1

我知道这个问题与但我不确定如何修复它。请帮助!

I know this issue is related to https://issues.apache.org/jira/browse/MNG-3228 but I'm not sure how to fix it. Please help!

更新

向B添加分类器有帮助。现在C构建只要存储库只包含B的jar文件。如果我将B的POM文件与存储库中的JAR一起上传,则C会因上述错误( $ {swt.classifier }未定义)而失败。任何想法?

Adding a classifier to B helped. Now C builds so long as the repository only contains B's jar file. If I upload B's POM file alongside the JAR in the repository, C fails with the aforementioned error (${swt.classifier} not defined). Any ideas?

推荐答案

从Maven 3.1.0开始,这是不可能的。以下是相关功能请求:

This isn't possible as of Maven 3.1.0. Here is the relevant feature request: https://issues.apache.org/jira/browse/MNG-1388

这篇关于Maven:在依赖性分类器中使用继承属性会导致构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 18:30