Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

unresolved reference from gradle multiplatform build #16

Closed
martysaxton opened this issue Dec 11, 2018 · 19 comments
Closed

unresolved reference from gradle multiplatform build #16

martysaxton opened this issue Dec 11, 2018 · 19 comments

Comments

@martysaxton
Copy link

I'm not able to reference klock in a multiplatform gradle build. Not sure what I'm doing wrong. Here's a minimal example:

build.gradle:

buildscript {
    ext.repos = {
        jcenter()
        mavenCentral()
        maven { url "https://dl.bintray.com/soywiz/soywiz" }
    }
    repositories repos

    dependencies {
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11'
    }
}

apply plugin: 'org.jetbrains.kotlin.multiplatform'

repositories repos

kotlin {
    targets {
        fromPreset(presets.jvm, 'jvm')
        fromPreset(presets.js, 'js')
    }
    sourceSets {
        commonMain {
            dependencies {
                api "com.soywiz:klock:1.0.0"
            }
        }
        jvmMain {
            dependencies {
               api "com.soywiz:klock-jvm:1.0.0"
            }
        }
        jsMain {
            dependencies {
               api "com.soywiz:klock-js:1.0.0"
            }
        }
    }
}

src/commonMain/kotlin/main.kt

import com.soywiz.klock.DateTime

val dateTime = DateTime.now()

Gradle error:

:compileKotlinMetadata (Thread[Execution worker for ':',5,main]) started.
e: /Users/asdf/klock/src/commonMain/kotlin/main.kt: (2, 8): Unresolved reference: com
e: /Users/asdf/klock/src/commonMain/kotlin/main.kt: (5, 16): Unresolved reference: DateTime

> Task :compileKotlinMetadata FAILED

@soywiz
Copy link
Collaborator

soywiz commented Dec 11, 2018

Which is the ./gradlew output and the ./gradlew --version?

@martysaxton
Copy link
Author

`~/klock(master*) » ./gradlew --version

Gradle 5.0

Build time: 2018-11-26 11:48:43 UTC
Revision: 7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987

Kotlin DSL: 1.0.4
Kotlin: 1.3.10
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_181 (Oracle Corporation 25.181-b13)
OS: Mac OS X 10.13.1 x86_64

~/klock(master*) » ./gradlew --console=plain -i clean build asdf@fido
Initialized native services in: /Users/asdf/.gradle/native
The client will now receive all logging from the daemon (pid: 60533). The daemon log file: /Users/asdf/.gradle/daemon/5.0/daemon-60533.out.log
Starting 4th build in daemon [uptime: 1 mins 50.674 secs, performance: 98%, no major garbage collections]
Using 8 worker leases.
Starting Build
Settings evaluated using settings file '/Users/asdf/klock/settings.gradle'.
Projects loaded. Root project using build file '/Users/asdf/klock/build.gradle'.
Included projects: [root project 'klock']

Configure project :
Evaluating root project 'klock' using build file '/Users/asdf/klock/build.gradle'.
Kotlin Multiplatform Projects are an experimental feature.
file or directory '/Users/asdf/klock/src/commonTest/kotlin', not found
file or directory '/Users/asdf/klock/src/commonTest/kotlin', not found
All projects evaluated.
Selected primary task 'clean' from project :
Selected primary task 'build' from project :
Tasks to be executed: [task ':cleanJsSourceMap', task ':cleanJsTestSourceMap', task ':clean', task ':compileKotlinJs', task ':jsMainClasses', task ':jsJar', task ':compileKotlinJvm', task ':jvmProcessResources', task ':jvmMainClasses', task ':jvmJar', task ':compileKotlinMetadata', task ':metadataMainClasses', task ':metadataJar', task ':assemble', task ':compileTestKotlinJs', task ':jsTestClasses', task ':jsTest', task ':compileTestKotlinJvm', task ':jvmTestProcessResources', task ':jvmTestClasses', task ':jvmTest', task ':check', task ':build']
:cleanJsSourceMap (Thread[Execution worker for ':',5,main]) started.

Task :cleanJsSourceMap SKIPPED
Skipping task ':cleanJsSourceMap' as task onlyIf is false.
:cleanJsSourceMap (Thread[Execution worker for ':',5,main]) completed. Took 0.002 secs.
:cleanJsTestSourceMap (Thread[Execution worker for ':',5,main]) started.

Task :cleanJsTestSourceMap SKIPPED
Skipping task ':cleanJsTestSourceMap' as task onlyIf is false.
:cleanJsTestSourceMap (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:clean (Thread[Execution worker for ':',5,main]) started.

Task :clean
Task ':clean' is not up-to-date because:
Task has not declared any outputs despite executing actions.
:clean (Thread[Execution worker for ':',5,main]) completed. Took 0.032 secs.
:compileKotlinJs (Thread[Execution worker for ':',5,main]) started.
w: Module "klock" depends on module with the same name

Task :compileKotlinJs
file or directory '/Users/asdf/klock/src/jsMain/kotlin', not found
Task ':compileKotlinJs' is not up-to-date because:
Output property 'destinationDir' file /Users/asdf/klock/build/classes/kotlin/js/main has been removed.
Output property 'destinationDir' file /Users/asdf/klock/build/classes/kotlin/js/main/klock has been removed.
Output property 'destinationDir' file /Users/asdf/klock/build/classes/kotlin/js/main/klock/root-package.kjsm has been removed.
All input files are considered out-of-date for incremental task ':compileKotlinJs'.
file or directory '/Users/asdf/klock/src/jsMain/kotlin', not found
:compileKotlinJs (Thread[Execution worker for ':',5,main]) completed. Took 0.459 secs.
:jsMainClasses (Thread[Execution worker for ':',5,main]) started.

Task :jsMainClasses
Skipping task ':jsMainClasses' as it has no actions.
:jsMainClasses (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:jsJar (Thread[Execution worker for ':',5,main]) started.

Task :jsJar
Task ':jsJar' is not up-to-date because:
Output property 'archivePath' file /Users/asdf/klock/build/libs/klock-js.jar has been removed.
:jsJar (Thread[Execution worker for ':',5,main]) completed. Took 0.038 secs.
:compileKotlinJvm (Thread[Execution worker for ':',5,main]) started.

Task :compileKotlinJvm
file or directory '/Users/asdf/klock/src/jvmMain/kotlin', not found
Task ':compileKotlinJvm' is not up-to-date because:
Output property 'destinationDir' file /Users/asdf/klock/build/classes/kotlin/jvm/main has been removed.
Output property 'destinationDir' file /Users/asdf/klock/build/classes/kotlin/jvm/main/META-INF has been removed.
Output property 'destinationDir' file /Users/asdf/klock/build/classes/kotlin/jvm/main/META-INF/klock.kotlin_module has been removed.
All input files are considered out-of-date for incremental task ':compileKotlinJvm'.
file or directory '/Users/asdf/klock/src/jvmMain/kotlin', not found
file or directory '/Users/asdf/klock/src/jvmMain/kotlin', not found
Using Kotlin incremental compilation
Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0], reportSeverity=2, requestedCompilationResults=[0]), areFileChangesKnown=false, modifiedFiles=null, deletedFiles=null, workingDir=/Users/asdf/klock/build/kotlin/compileKotlinJvm, customCacheVersionFileName='gradle-format-version.txt', customCacheVersion=4, multiModuleICSettings=MultiModuleICSettings(buildHistoryFile=/Users/asdf/klock/build/kotlin/compileKotlinJvm/build-history.bin, useModuleDetection=false), usePreciseJavaTracking=truelocalStateDirs=[/Users/asdf/klock/build/classes/kotlin/jvm/main])
:compileKotlinJvm (Thread[Execution worker for ':',5,main]) completed. Took 0.827 secs.
:jvmProcessResources (Thread[Execution worker for ':',5,main]) started.

Task :jvmProcessResources NO-SOURCE
file or directory '/Users/asdf/klock/src/jvmMain/resources', not found
file or directory '/Users/asdf/klock/src/commonMain/resources', not found
Skipping task ':jvmProcessResources' as it has no source files and no previous output files.
:jvmProcessResources (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:jvmMainClasses (Thread[Execution worker for ':',5,main]) started.

Task :jvmMainClasses
Skipping task ':jvmMainClasses' as it has no actions.
:jvmMainClasses (Thread[Execution worker for ':',5,main]) completed. Took 0.0 secs.
:jvmJar (Thread[Execution worker for ':',5,main]) started.

Task :jvmJar
Task ':jvmJar' is not up-to-date because:
Output property 'archivePath' file /Users/asdf/klock/build/libs/klock-jvm.jar has been removed.
:jvmJar (Thread[Execution worker for ':',5,main]) completed. Took 0.005 secs.
:compileKotlinMetadata (Thread[Execution worker for ':',5,main]) started.
e: /Users/asdf/klock/src/commonMain/kotlin/main.kt: (2, 8): Unresolved reference: com
e: /Users/asdf/klock/src/commonMain/kotlin/main.kt: (5, 16): Unresolved reference: DateTime

Task :compileKotlinMetadata FAILED
Task ':compileKotlinMetadata' is not up-to-date because:
Task has failed previously.
All input files are considered out-of-date for incremental task ':compileKotlinMetadata'.
:compileKotlinMetadata (Thread[Execution worker for ':',5,main]) completed. Took 0.045 secs.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileKotlinMetadata'.

Compilation error. See log for more details

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
6 actionable tasks: 6 executed
`

@martysaxton
Copy link
Author

martysaxton commented Dec 12, 2018

It looks klock uses the exterimental metadata publish mode: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#experimental-metadata-publishing-mode

I put enableFeaturePreview('GRADLE_METADATA') in settings.gradle. Now I'm getting:

~/klock(master*) » ./gradlew --console=plain -i build

Initialized native services in: /Users/asdf/.gradle/native
The client will now receive all logging from the daemon (pid: 60533). The daemon log file: /Users/asdf/.gradle/daemon/5.0/daemon-60533.out.log
Starting 8th build in daemon [uptime: 26 mins 47.978 secs, performance: 100%, no major garbage collections]
Using 8 worker leases.
Starting Build
Settings evaluated using settings file '/Users/asdf/klock/settings.gradle'.
Projects loaded. Root project using build file '/Users/asdf/klock/build.gradle'.
Included projects: [root project 'klock']

Configure project :
Evaluating root project 'klock' using build file '/Users/asdf/klock/build.gradle'.
Kotlin Multiplatform Projects are an experimental feature.
file or directory '/Users/asdf/klock/src/commonTest/kotlin', not found
file or directory '/Users/asdf/klock/src/commonTest/kotlin', not found
All projects evaluated.
Selected primary task 'build' from project :
Tasks to be executed: [task ':compileKotlinJs', task ':jsMainClasses', task ':jsJar', task ':compileKotlinJvm', task ':jvmProcessResources', task ':jvmMainClasses', task ':jvmJar', task ':compileKotlinMetadata', task ':metadataMainClasses', task ':metadataJar', task ':assemble', task ':compileTestKotlinJs', task ':jsTestClasses', task ':jsTest', task ':compileTestKotlinJvm', task ':jvmTestProcessResources', task ':jvmTestClasses', task ':jvmTest', task ':check', task ':build']
:compileKotlinJs (Thread[Execution worker for ':',5,main]) started.

Task :compileKotlinJs
file or directory '/Users/asdf/klock/src/jsMain/kotlin', not found
Cached resource https://dl.bintray.com/soywiz/soywiz/com/soywiz/klock/1.0.0/klock-1.0.0.module is up-to-date (lastModified: Sun Nov 04 21:52:01 CST 2018).
Cached resource https://dl.bintray.com/soywiz/soywiz/com/soywiz/klock-js/1.0.0/klock-js-1.0.0.module is up-to-date (lastModified: Sun Nov 04 21:51:47 CST 2018).
Resource missing. [HTTP HEAD: https://repo.jfrog.org/artifactory/libs-release-bintray/com/soywiz/klock/1.0.0/klock-1.0.0.module?referrer]
Resource missing. [HTTP HEAD: https://repo.jfrog.org/artifactory/libs-release-bintray/com/soywiz/klock-js/1.0.0/klock-js-1.0.0.module?referrer]
Resource missing. [HTTP HEAD: https://repo.jfrog.org/artifactory/libs-release-bintray/com/soywiz/klock/1.0.0/klock-1.0.0.pom?referrer]
Resource missing. [HTTP HEAD: https://repo.jfrog.org/artifactory/libs-release-bintray/com/soywiz/klock-js/1.0.0/klock-js-1.0.0.pom?referrer]
Resource missing. [HTTP HEAD: https://repo.maven.apache.org/maven2/com/soywiz/klock-js/1.0.0/klock-js-1.0.0.module]
Resource missing. [HTTP HEAD: https://repo.maven.apache.org/maven2/com/soywiz/klock/1.0.0/klock-1.0.0.module]
Resource missing. [HTTP HEAD: https://repo.maven.apache.org/maven2/com/soywiz/klock/1.0.0/klock-1.0.0.pom]
Resource missing. [HTTP HEAD: https://repo.maven.apache.org/maven2/com/soywiz/klock-js/1.0.0/klock-js-1.0.0.pom]

Task :compileKotlinJs FAILED
:compileKotlinJs (Thread[Execution worker for ':',5,main]) completed. Took 4.476 secs.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileKotlinJs'.

Could not resolve all files for configuration ':jsCompileClasspath'.
Could not resolve com.soywiz:klock:1.0.0.
Required by:
project :
> Could not resolve com.soywiz:klock:1.0.0.
> Could not parse module metadata https://dl.bintray.com/soywiz/soywiz/com/soywiz/klock/1.0.0/klock-1.0.0.module
> Unsupported format version '0.3' specified in module metadata. This version of Gradle supports format version 0.4 only.
Could not resolve com.soywiz:klock-js:1.0.0.
Required by:
project :
> Could not resolve com.soywiz:klock-js:1.0.0.
> Could not parse module metadata https://dl.bintray.com/soywiz/soywiz/com/soywiz/klock-js/1.0.0/klock-js-1.0.0.module
> Unsupported format version '0.3' specified in module metadata. This version of Gradle supports format version 0.4 only.
[snip]

@soywiz
Copy link
Collaborator

soywiz commented Dec 12, 2018

Kotlin/kotlinx.coroutines#564

When you tried I was trying gradle 5.0, but switched back to 4.7 again. The problem is that I export it using gradle 5.0 that uses metadata 0.4, you won't be able to use it along kotlinx.coroutines for now since it is published with metadata 0.3 and gradle 4.7.

So your best bet is to stick to gradle 4.7 for now until an official solution is provided.

@fardavide
Copy link

Is there update about that?

@jonl-percsolutions-com
Copy link

jonl-percsolutions-com commented Jan 16, 2019

Kotlin 1.3.20 will support Gradle 4.8+ according to https://youtrack.jetbrains.com/issue/KT-29045. Building with Kotlin 1.3.20 eap 100 w/ klock 1.0.0 on the path produces the following:

warning: skipping .../.gradle/caches/modules-2/files-2.1/com.soywiz/klock-iosx64/1.0.0/9046561f9a2bb43014b071450a866d16305e955d/klock.klib. The abi versions don't match. Expected '[5]', found '2'
warning: the compiler versions don't match either. Expected '[1.1]', found '1.0.1-release-4583'
error: compilation failed: Could not find "../.gradle/caches/modules-2/files-2.1/com.soywiz/klock-iosx64/1.0.0/9046561f9a2bb43014b071450a866d16305e955d/klock.klib" in [../Code/SRTSApps, ../.konan/klib, ../.konan/kotlin-native-macos-1.1-rc2-5686/klib/common, ../.konan/kotlin-native-macos-1.1-rc2-5686/klib/platform/ios_x64].

@soywiz
Copy link
Collaborator

soywiz commented Jan 16, 2019

Sorry for the delay. I will create a new version with Kotlin 1.3.20 and will update gradle version too.

@soywiz
Copy link
Collaborator

soywiz commented Jan 18, 2019

Just for the record: I have pushed a pre-release version using gradle 5.1.1 (metadata 0.4) and kotlin 1.3.20-eap-100: https://bintray.com/soywiz/soywiz/klock/1.1.0-eap-100
And for testing in my own projects, I have created a temporal version of kotlinx-coroutines-core 1.1 that uses gradle 5.1.1: https://github.com/korlibs/kotlinx.coroutines -> https://bintray.com/soywiz/soywiz/kotlinx/1.1.0-native-1.3.20-eap-100-gradle-5-v2

It seems to work just fine. So I will release it again for final Kotlin 1.3.20 when out.
Hopefully kotlinx.coroutines will be released with gradle 5.1.1 and metadata 0.4.

@soywiz
Copy link
Collaborator

soywiz commented Jan 24, 2019

Should be fixed with #23 Also I have published 1.1.0: https://bintray.com/soywiz/soywiz/klock/1.1.0

Feel free to close if this is fixed already

@mschirmacher
Copy link

Are there any chances not to depend on this experimental feature? While klock is now usable again, having to enable GRADLE_METADATA collides with other dependencies why we can only use either klock or the other dependency.
Im sad :(

@soywiz
Copy link
Collaborator

soywiz commented Feb 1, 2019

@mschirmacher
Copy link

@soywiz Awesome thank you! Unfortunately i think the common klock package is missing

@soywiz
Copy link
Collaborator

soywiz commented Feb 1, 2019

As far as I know the common suffix is called -metadata so my guess is that you have to write something like:

commonMainImplementation “com.soywiz:klock-metadata:$klockVersion”
jvmMainImplementation ...-jvm...
jsMain ...-js...
...

Do not confuse -metadata that is how is called Kotlin common IR and in gradle (though it is a bit misleading), with gradle metadata that was used to determine the artifacts per platform with a .module file per platform describing the target artifacts

@danthonywalker
Copy link

When I add the "metadata" library to my common module I get this:

> Task :compileKotlinJvm FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlinJvm'.
> Could not resolve all files for configuration ':jvmCompileClasspath'.
   > Could not resolve com.soywiz:klock-metadata:1.1.1.
     Required by:
         project :
      > Unable to find a matching variant of com.soywiz:klock-metadata:1.1.1:
          - Variant 'metadata-api':
              - Found artifactType 'jar' but wasn't required.
              - Found org.gradle.status 'release' but wasn't required.
              - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-api'.
              - Required org.jetbrains.kotlin.platform.type 'jvm' and found incompatible value 'common'.

I'm simply defining this in my common module:

implementation("com.soywiz:klock-metadata:$klockVersion")

When I don't define that, everything builds fine, but I obviously don't have access to Klock in the common module then (klock-jvm is defined and detected just fine in either scenarios).

@mschirmacher
Copy link

@soywiz thank you!

@soywiz
Copy link
Collaborator

soywiz commented Feb 11, 2019

@danthonywalker sorry for the delay. Not sure what happens to you.
I have migrated all my libraries to not use metadata and it works fine.

https://github.com/korlibs/klock/blob/354613e20b6d4d45f821f0e63c1f9f0ad4c620d5/buildSrc/src/main/kotlin/com/soywiz/korlibs/KorlibsPlugin.kt#L49-L75

The only thing is to take into account is that common is metadata.

So:

commonMainApi "com.soywiz:klock-metadata:$klockVersion"
jvmMainApi "com.soywiz:klock-jvm:$klockVersion"
ksMainApi "com.soywiz:klock-js:$klockVersion"

@danthonywalker
Copy link

danthonywalker commented Feb 17, 2019

@soywiz Here's my build.gradle, still getting the same error
https://hastebin.com/ogikutitof.bash

EDIT: It appears commenting out enableFeaturePreview("GRADLE_METADATA") in settings.gradle solves the issue. Considering IntelliJ by default includes this in its multiplatform template, it probably should be noted in the README that this should be disabled.
Or, ideally, make the two be able to work together.

@soywiz
Copy link
Collaborator

soywiz commented Feb 17, 2019

Starting with 1.1.1-no-metadata and 1.2.0 all the new versions are released without metadata:
https://bintray.com/soywiz/soywiz/klock

@danthonywalker
Copy link

Ah yes, 1.2.0 works. Sorry for the trouble!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants