Skip to content

Android: Show class sources in IDE - #6856

Merged
lihaoyi merged 9 commits into
com-lihaoyi:mainfrom
vaslabs-ltd:android-include-sources-jar
Mar 4, 2026
Merged

lihaoyi merged 9 commits into
com-lihaoyi:mainfrom
vaslabs-ltd:android-include-sources-jar

Conversation

@souvlakias

@souvlakias souvlakias commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

Addresses #6634

This is a POC on linking the classes jar with their respective sources.jar using bsp

The problem

Since android deps are aars, we extract them into a Task.dest and pass the found .jars into the classpath.
Bsp sees the sources.jars that exist in ~/.cache/coursier and doesnt pair the two.

How it works

  • When unpacking an aar that we want to include in the classpath, also copy it's sources.jar in the extract directory
  • Create a BspAndroidModule that overrides bspBuildTargetDependencySources to show to the sources.jars that exist next to the jars that we pass in the classpath

Tweaks

  • Changed resolvedMvnDeps0 from private to private[mill] so AndroidModule has access to it, in order to get the Sources Jars
  • androidResolvedMvnDeps (which is what we pass to compileclasspath), now needs to use a helper task that returns Seq[UnpackedDep]], in order for the bsp module to find _.sourcesJar from that helper task (that exist in the same Task.dest with the ones in classpath)

Notes

This may not be the best approach. Another solution could be to use GenIdea, and create xmls that link the two jars for each dep.

Screencast.From.2026-02-20.18-48-54.mp4

@vaslabs

vaslabs commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

this looks reasonable to me but I'm not familiar with that area, we'll need some help reviewing to see if it's in the right direction @lihaoyi @lefou

Also if you could attach a small video recording with the sources working @souvlakias , would be great

@souvlakias

souvlakias commented Feb 21, 2026 •

Copy link
Copy Markdown
Contributor Author

If it's in the right direction, it might be a good time to organize all of the tasks that extract aars into using a helper task that extracts all of them instead of every task extracting to its own Task.dest.

(I mean that I just messed with androidResolvedMvnDeps for the POC for now, but it could be a good choice to update the rest of the relevant tasks like androidUnpackArchives and their Run variants)

If it would be out of scope, this could be done in a different PR

@vaslabs

vaslabs commented Feb 21, 2026

Copy link
Copy Markdown
Contributor

If it's in the right direction, it might be a good time to organize all of the tasks that extract aars into using a helper task that extracts all of them instead of every task extracting to its own Task.dest.

(I mean that I just messed with androidResolvedMvnDeps for the POC for now, but it could be a good choice to update the rest of the relevant tasks like androidUnpackArchives and their Run variants)

If it would be out of scope, this could be done in a different PR

I think this is an important fix, we can follow up with optimisations on follow up prs

@souvlakias
souvlakias marked this pull request as ready for review February 21, 2026 11:38
Comment on lines +1130 to +1132
def resolvedMvnJarSources: T[Seq[PathRef]] = Task {
resolvedMvnDeps0(sources = true)()
}

@lefou lefou Feb 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this required to show source JARs in the IDE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ressolvedMnvDeps0 is private in JavaModule, so this serves as a way for the AndroidModule to easily get the sources.jars

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just change resolvedMvnDeps0 to private[mill] and avoid another public task?

If not, I find the name unlucky, since Sources suffix is typically not associated archives but plain files. Instead, we could name it resolvedMvnSourceJars (If it is guaranteed to always be jar files) or resolvedMvnSourceDeps.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you renamed it. So why not the first option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean the private[mill] vs having a public task, both felt acceptable so I just went with the clearer api.
About the name, im not sure about the "only jars" guarantee so the latter suggestion (resolvedMvnSourceDeps) seemed ok too.

If you prefer to avoid the public task, yes I can change to private[mill]

@vaslabs vaslabs Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my point of view, let's not increase the surface of the API if not necessary @souvlakias (e.g. especially since JavaModule is not experimental), it is convenient to run it directly and check the output, but since this looks straightforward functionality to me, private[mill] is preferable for me

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to private[mill]

@vaslabs

vaslabs commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Any objections merging this? @lihaoyi @lefou

@lihaoyi
lihaoyi merged commit 39794eb into com-lihaoyi:main Mar 4, 2026
36 checks passed
@lefou lefou added this to the 1.1.3 milestone Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants