westnordost / osm-legal-default-speeds

Infer default legal speed limits from OpenStreetMap tags
https://westnordost.github.io/osm-legal-default-speeds
BSD 3-Clause "New" or "Revised" License
21 stars 9 forks source link

Include dependency in JVM project fails #2

Closed westnordost closed 2 years ago

westnordost commented 2 years ago

from https://github.com/graphhopper/graphhopper/issues/2392

To reproduce, it should be enough to create a new Java or Kotlin project and try to include this library (unconfirmed).

Execution failed for task ':compileKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':compileKotlin'
   > Could not resolve all files for configuration ':compileClasspath'.
      > Could not resolve de.westnordost:osm-legal-default-speeds:1.1.
        Required by:
            project :
         > No matching variant of de.westnordost:osm-legal-default-speeds:1.1 was found. The consumer was configured to find an API of a library compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
             - Variant 'nativeApiElements-published' capability de.westnordost:osm-legal-default-speeds:1.1 declares a library:
                 - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
                 - Other compatible attributes:
                     - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                     - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                     - Doesn't say anything about its target Java version (required compatibility with Java 11)
                     - Doesn't say anything about its elements (required them packaged as a jar)

This error doesn't ring a bell, but some keywords (nativeApiElements-published etc.) may be useful to search for details on this error.

easbar commented 2 years ago

Running ./gradlew publishToLocalMaven I get these warnings:

> Task :library:publishKotlinMultiplatformPublicationToMavenLocal
Multiple publications with coordinates 'de.westnordost:osm-legal-default-speeds:1.1' are published to repository 'mavenLocal'. The publications 'js' in project ':library' and 'kotlinMultiplatform' in project ':library' will overwrite each other!

> Task :library:publishNativePublicationToMavenLocal
Multiple publications with coordinates 'de.westnordost:osm-legal-default-speeds:1.1' are published to repository 'mavenLocal'. The publications 'js' in project ':library' and 'native' in project ':library' will overwrite each other!
Multiple publications with coordinates 'de.westnordost:osm-legal-default-speeds:1.1' are published to repository 'mavenLocal'. The publications 'kotlinMultiplatform' in project ':library' and 'native' in project ':library' will overwrite each other!

> Task :library:publishJvmPublicationToMavenLocal
Multiple publications with coordinates 'de.westnordost:osm-legal-default-speeds:1.1' are published to repository 'mavenLocal'. The publications 'js' in project ':library' and 'jvm' in project ':library' will overwrite each other!
Multiple publications with coordinates 'de.westnordost:osm-legal-default-speeds:1.1' are published to repository 'mavenLocal'. The publications 'jvm' in project ':library' and 'kotlinMultiplatform' in project ':library' will overwrite each other!
Multiple publications with coordinates 'de.westnordost:osm-legal-default-speeds:1.1' are published to repository 'mavenLocal'. The publications 'jvm' in project ':library' and 'native' in project ':library' will overwrite each other!
easbar commented 2 years ago

When I add the $name to the artifactId like this (in library/build.gradle.kts)

publishing {
    publications {
        withType<MavenPublication> {
            artifactId = "osm-legal-default-speeds-$name"

the warnings are gone and I get separate artifacts for the different targets.

westnordost commented 2 years ago

Hm, probably. I noticed that I ignored this part of the tutorial for "publishing multiplatform libraries":

https://kotlinlang.org/docs/multiplatform-publish-lib.html#avoid-duplicate-publications

, mainly because I didn't and still don't understand what the snippet they gave there does.

easbar commented 2 years ago

I saw this too and did not understand it either. But the solution I suggested is pretty clear(?!). It simply appends the target name so there are separate publications/artifacts for each platform. And isn't this exactly what we want? For example when developing on the JVM I do not want the artifact to contain JS or native stuff?

westnordost commented 2 years ago

Yeah. Would you like to create a PR?

I am still in Florence and I think I am not set up here to publish things on maven central, so it will be a week or so (anyway) till a new publication can appear on maven central.