IDEA can't download sources for my library
Asked Answered
S

3

10

I have a library (my own) in a private maven repo. I ship it there with javadoc and sources:

Repo

In my app I've declared this repo:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

    repositories {
        google()
        mavenCentral()

        maven {
            url = uri("https://jitpack.io")
        }
        maven { // <- This is my private repo
            credentials {
                username = extra["mavenUser"] as String
                password = extra["mavenPassword"] as String
            }
            url = uri(extra["mavenUrl"] as String)
        }
    }
}

It downloads the aar without any problems, but doesn't download sources, and when I'm trying to force it by clicking «Download sources» it fails:

Execution failed for task ':app:DownloadSources'.
> Could not resolve all files for configuration ':app:downloadSources_36c7b334-04c2-4099-b66c-2adc137cc95c'.
   > Could not find com.example.path:common-core:0.0.1@aar.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/example/path/common-core/0.0.1@aar/[email protected]
       - https://repo.maven.apache.org/maven2/com/example/path/common-core/0.0.1@aar/[email protected]
       - https://jitpack.io/com/example/path/common-core/0.0.1@aar/[email protected]
       - https://repo.replaced-domain.com/mvn/replaced/replaced/com/example/path/common-core/0.0.1@aar/[email protected] <-- This is my private repo
     Required by:
         project :app

UPD 1: If I click «Choose sources» and specify my local sources jar, it just does nothing.

How to fix it?

Sump answered 14/1, 2022 at 11:35 Comment(11)
Can you show where you declared the dependency?Pomace
@Pomace module's build.gradle.kts -> dependencies -> api("com.example.path:common-core:0.0.1")Sump
@Pomace btw should POM file contain information about sources and javadoc jar?Sump
From browsing some public POMs, I don't think so. Not an expert on that. I'm not sure what could cause your problem.Pomace
Could you run it with --debug key? What exact URL it's trying (and failing) to access?Latvian
@МихаилНафталь well with --debug I see the following: [INFO] [org.gradle.internal.resource.transport.http.HttpClientHelper] Resource missing. [HTTP GET: repo.replaced-domain.com/mvn/replaced/replaced/com/example/path/common-core/0.0.1@aar/[email protected]]. If I remove @aar it becomes a valid URL for the POM.Sump
where does this DownloadSources task come from?Latvian
Will it work if you add metadataSources { artifact() } to your maven repo declaration (it should disable search for pom files, orienting on artifacts layout)? Or it will try to fetch [email protected] in this case?Latvian
@МихаилНафталь if I add metadataSources { artifact() }, it fails to resolve the dependency. DownloadSources is the (probably synthetic) name of the task when that is launched when I click «Download Sources» in Idea. It doesn't work for any module from command line, like ./gradlew :core:DownloadSourcesSump
Variable extra is unknown, therefore this is missing debug information; try project.ext - or try substituting these variable with strings for a test. In every case, the repository isn't properly set up.Valverde
I have the exact same issue. For some reason the @aar gets placed where it shouldn't in the URL. Did you get this resolved?Noahnoak
F
3

I think it's a bug in Android Studio.

https://issuetracker.google.com/issues/247991770
https://youtrack.jetbrains.com/issue/IDEA-302178/Cannot-download-sources-for-AAR-dependencies

Facient answered 22/9, 2022 at 6:19 Comment(1)
Did you find any solution?Mesomorph
B
2

I am not developing with Android Studio currently, but when looking at your output:

Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/example/path/common-core/0.0.1@aar/[email protected]
       - https://repo.maven.apache.org/maven2/com/example/path/common-core/0.0.1@aar/[email protected]
       - https://jitpack.io/com/example/path/common-core/0.0.1@aar/[email protected]
       - https://repo.replaced-domain.com/mvn/replaced/replaced/com/example/path/common-core/0.0.1@aar/[email protected] <-- This is my private repo

it seems that the ext (extension) part is not correct resolved/calculated.

Maybe it's enough when you explicit set ext inside your dependencies :

build.gradle.kts -> dependencies -> {
    api(group="com.example.path", name="common-core", version="0.0.1", ext="aar")
}
Berlinda answered 18/1, 2022 at 9:34 Comment(0)
C
0

I have my own library as well, and I suggest to add a classifier in your artifact that specifically downloads sources and Javadoc. Although it is possibly not necessary, it might help in your case - the two last artifacts specifically bring sources and Javadoc:

<dependency>
     <groupId>com.github.michaelgantman</groupId>
     <artifactId>MgntUtils</artifactId>
     <version>1.6.0.1</version>
</dependency>

 <dependency>
     <groupId>com.github.michaelgantman</groupId>
     <artifactId>MgntUtils</artifactId>
     <version>1.6.0.1</version>
     <classifier>javadoc</classifier>
</dependency>

<dependency>
     <groupId>com.github.michaelgantman</groupId>
     <artifactId>MgntUtils</artifactId>
     <version>1.6.0.1</version>
     <classifier>sources</classifier>
</dependency> 
Cephalochordate answered 18/1, 2022 at 12:54 Comment(1)
How is this related to Gradle (despite the repo is Maven)?Valverde

© 2022 - 2024 — McMap. All rights reserved.