如何解决 pom 类型的 Maven 依赖项?

时间:2021-02-15 21:18:15

标签: java maven kotlin kotlin-multiplatform

我正在尝试在 Maven 中导入一个库,它是 Kotlin Multiplatform

This 是 Github 存储库(当然实际上并不重要)

重点是,它说它可以使用 Gradle 的这个依赖项导入:

dependencies {
   implementation("com.github.ajalt.colormath:colormath:2.0.0")
}

显然,仅将其转换为 Maven 是行不通的:

    <dependencies>
        ...

        <dependency>
            <groupId>com.github.ajalt.colormath</groupId>
            <artifactId>colormath</artifactId>
            <version>2.0.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>

所以我按照 this answer 的解释将它的 pom 添加到项目中:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.github.ajalt.colormath</groupId>
                <artifactId>colormath</artifactId>
                <version>2.0.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

这个依赖解决了(它只能解析为pom type。然后我把它添加为dependency

    <dependencies>
        ...

        <dependency>
            <groupId>com.github.ajalt.colormath</groupId>
            <artifactId>colormath</artifactId>
            <version>2.0.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>

它仍然找不到它。

我还添加了 repo1,因为我没有看到 Maven 在哪里寻找这个工件:

    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo1.maven.org/maven2</url>
        </repository>
    </repositories>

但是还是没有成功。我不明白为什么它不起作用。

代码可以在 repo1 中找到,但 Maven 无法解析。

这一定是个很简单的事情,我在这里不明白,请帮忙。

1 个答案:

答案 0 :(得分:1)

GitHub 到 Maven Central 的链接指向一个裸 POM 工件,没有任何依赖项和/或附加的 JAR。

看起来 Kotlin MP 上传了具有不同 artifactId 的 JVM 特定工件 - 在这种情况下为 colormath-jvm。请检查Maven Central中的相应目录。

我建议在 POM 中使用以下依赖声明:

<groupId>com.github.ajalt.colormath</groupId>
<artifactId>colormath-jvm</artifactId>
<version>2.0.0</version>