0

I am trying to import a library in Maven which is Kotlin Multiplatform.

This is it's Github repo (does not actually matter much of course)

Point is, it says it can be imported in with this dependency for Gradle:

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

Obviously, just converting it to Maven does not work:

    <dependencies>
        ...

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

So I added it's pom to the project as this answer explains it:

    <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>

This dependency is resolved (it can be only resolved as pom type. Then I add it as dependency:

    <dependencies>
        ...

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

It still cannot find it.

I also added the repo1, because I did not see where Maven was looking for this artifact:

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

But still no success. I don't understand why it's not working.

The code can be found in the repo1, but Maven does not resolve it.

This must be a very simple thing I am not understanding here, please help.

andras
  • 3,305
  • 5
  • 30
  • 45

1 Answers1

1

The link to the Maven Central from GitHub points to a bare POM artifact, without any dependencies and/or attached JARs.

It looks like Kotlin MP uploads JVM-specific artifacts with a different artifactId - colormath-jvm in this case. Please check corresponding directory in the Maven Central.

I suggest using following dependency declaration in the POM:

<groupId>com.github.ajalt.colormath</groupId>
<artifactId>colormath-jvm</artifactId>
<version>2.0.0</version>
Illya Kysil
  • 1,642
  • 10
  • 18
  • While this works, I need to understand the thought process for fixing this issue - how did you know it must be postfixed with `-jvm`? The `pom.xml` in my original link did not include any info about the url you linked. How did you find it? Was it because you know about `Kotlin Multiplatform` and it's publish process or is this `Maven`-specfic? – andras Feb 16 '21 at 05:54
  • 1. The published artifacts for artifact id colormath contain pom.xml ONLY, no JARs 2. Maven Repository Layout - see https://cwiki.apache.org/confluence/display/MAVEN/Remote+repository+layout 3. Limited experience with Gradle - enough to know that a pom.xml is constructed by the Maven publishing plugin – Illya Kysil Feb 20 '21 at 22:39