kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 124 forks source link

Unable to resolve dependency from google maven/jitpack #382

Closed waliahimanshu closed 1 year ago

waliahimanshu commented 1 year ago

I am trying to pull dependencies from google maven repository.

@file:DependsOn("com.google.firebase:firebase-analytics-ktx:21.1.1"")
// also tried with `https://dl.google.com/dl/android/maven2/`
@file:MavenRepository("maven", "https://maven.google.com/")

error

[kscript] [WARN] There are deprecated features in scripts. Use --report option to print full report.
[kscript] Adding repository: Repository(id=maven, url=https://dl.google.com/dl/android/maven2/, user=, password=)
[kscript] Resolving com.google.firebase:firebase-analytics-ktx:21.1.1...
[kscript] [ERROR] Failed while connecting to the server. Check the connection (http/https, port, proxy, credentials, etc.)of your maven dependency locators. If you suspect this is a bug, you can create an issue on https://github.com/holgerbrandl/kscript
[kscript] [ERROR] File 'com.google.firebase:firebase-analytics-ktx:21.1.1' not found
[kscript] [ERROR] org.jetbrains.kotlin.org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact com.google.firebase:firebase-analytics-ktx:jar:21.1.1 in maven central (https://repo.maven.apache.org/maven2/)
[kscript] [ERROR] org.jetbrains.kotlin.org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact com.google.firebase:firebase-analytics-ktx:jar:21.1.1 in https___repo.maven.apache.org_maven2 (https://repo.maven.apache.org/maven2)

With jetpack

@file:MavenRepository("jitpack","https://jitpack.io")
// link to jitpack https://jitpack.io/#cookpad/puree-android
@file:DependsOn("com.github.cookpad:puree-android:5.1.0")

It seems its failed to resolve androidx.sqlite:sqlite-framework:jar:2.0.1, however is it possible to specify and pull this from the google maven repo ? error

[kscript] Adding repository: Repository(id=jitpack, url=https://jitpack.io, user=, password=)
[kscript] Resolving com.github.cookpad:puree-android:5.1.0...
[kscript] [ERROR] Failed while connecting to the server. Check the connection (http/https, port, proxy, credentials, etc.)of your maven dependency locators. If you suspect this is a bug, you can create an issue on https://github.com/holgerbrandl/kscript
[kscript] [ERROR] File 'com.github.cookpad:puree-android:5.1.0' not found
[kscript] [ERROR] org.jetbrains.kotlin.org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact com.github.cookpad:puree-android:jar:5.1.0 in maven central (https://repo.maven.apache.org/maven2/)
[kscript] [ERROR] org.jetbrains.kotlin.org.eclipse.aether.resolution.DependencyResolutionException: The following artifacts could not be resolved: com.github.cookpad:puree-android:jar:5.1.0, androidx.sqlite:sqlite-framework:jar:2.0.1: Could not find artifact com.github.cookpad:puree-android:jar:5.1.0 in https___repo.maven.apache.org_maven2 (https://repo.maven.apache.org/maven2)
make: *** [new-screen-gen] Error 1
aartiPl commented 1 year ago

This seems to work in kscript 4.1.1:

@file:Repository("https://dl.google.com/android/maven2")
@file:DependsOn("com.google.firebase:firebase-analytics-ktx:aar:21.1.1"")

But a similar change for jitpack doesn't:

//@file:Repository("https://jitpack.io")
//@file:DependsOn("com.github.cookpad:puree-android:aar:5.1.0")

I will still have a look at the second case.

aartiPl commented 1 year ago

Ok. I think I got it. The jitpack fails not because of lack of "com.github.cookpad:puree-android:aar:5.1.0", but because of the lack of dependency for that library: "androidx.sqlite:sqlite-framework:jar:2.0.1"

The whole log in kscript goes as follows:

[kscript] Adding repository: Repository(id=, url=https://jitpack.io, user=, password=)
[kscript] Adding repository: Repository(id=, url=https://dl.google.com/android/maven2, user=, password=)
[kscript] [WARN] Configured repository: https___jitpack.io (https://jitpack.io, default, releases+snapshots)
[kscript] [WARN] Configured repository: https___dl.google.com_android_maven2 (https://dl.google.com/android/maven2, default, releases+snapshots)
[kscript] [WARN] Configured repository: https___repo.maven.apache.org_maven2 (https://repo.maven.apache.org/maven2, default, releases+snapshots)
[kscript] Resolving com.github.cookpad:puree-android:aar:5.1.0...
[kscript] Resolving com.google.firebase:firebase-analytics-ktx:aar:21.1.1...
[kscript] [WARN] Resolution result: Failure(reports=[WARNING File 'com.github.cookpad:puree-android:aar:5.1.0' not found, WARNING org.jetbrains.kotlin.org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact androidx.sqlite:sqlite-framework:jar:2.0.1 in https___jitpack.io (https://jitpack.io)])
[kscript] [ERROR] Failed while connecting to the server. Check the connection (http/https, port, proxy, credentials, etc.)of your maven dependency locators. If you suspect this is a bug, you can create an issue on https://github.com/holgerbrandl/kscript
[kscript] [ERROR] File 'com.github.cookpad:puree-android:aar:5.1.0' not found
[kscript] [ERROR] org.jetbrains.kotlin.org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact androidx.sqlite:sqlite-framework:jar:2.0.1 in https___jitpack.io (https://jitpack.io)

The message from resolver is correct - there is no such artifact "androidx.sqlite:sqlite-framework:jar:2.0.1", but there is another one: "androidx.sqlite:sqlite-framework :aar: 2.0.1". Please notice the type of the artifact - the correct one is of type aar.

Artifact resolution is done in Kotlin scripting artifact resolver. It looks for me that it assumes that resolved artifacts will always have 'jar' extension.

This is part of the pom file for "com.github.cookpad:puree-android:aar:5.1.0"

<dependencies>
  <dependency>
    <groupId>androidx.sqlite</groupId>
    <artifactId>sqlite-framework</artifactId>
    <version>2.0.1</version>
    <scope>compile</scope>
   </dependency>
</dependencies>

As you can see above there is no definition of type of sqlite-framework, so seems that Kotlin scripting dependency resolver assumes it is ".jar", but in this case it is ".aar".

So in my opinion it is something to be fixed in Kotlin scripting dependency resolver. Probably the rule here is that if initial file is of type 'aar', then also for resolved dependencies there should be assumption that dependency is also 'aar'. Or maybe if it is not defined both types should be checked.

Please have a look at my analysis: @ligee, @ileasile . Can you please raise the ticket if my analysis is correct?

ileasile commented 1 year ago

Hello @aartiPl! Thank you for your analysis. It seems that you're correct, Maven resolver takes jar as a type if another type isn't stated in the dependency. Workaround is to write DependsOn annotation for each transitive dependency manually. There is also an option in the latest versions of Kotlin that allows to skip unsuccessfully resolved dependencies, it may also help. You're interested in transitive and partial_resolution options here: https://github.com/JetBrains/kotlin/blob/af8b9e6700f25ed2fba40965accaf7d47f3dfda9/libraries/scripting/dependencies/src/kotlin/script/experimental/dependencies/impl/resolverNamedOptions.kt#L24

I'll filed an issue in the Kotlin project about it: https://youtrack.jetbrains.com/issue/KT-54757/Cant-resolve-dependency-with-non-jar-extension-if-it-has-dependencies-with-non-jar-extensions

aartiPl commented 1 year ago

Closing as it is an upstream issue.