Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenIdea/idea task should generate appropriate config from libs build.sc depends on #347

Closed
Baccata opened this issue May 22, 2018 · 6 comments
Labels
solved The issue was fixed/resolved
Milestone

Comments

@Baccata
Copy link
Contributor

Baccata commented May 22, 2018

If the build depends on external libraries (imported through import $ivy), the GenIdea/idea task should generate configuration for those libraries accordingly.

I assume the difficulty comes from the fact that the references to those libraries are not easily inspectable from the task. Maybe by looking at the classloader (ammonite has a SpecialClassLoader that keeps track of the urls of loaded jars) and inferring the various libs from where they are stored in the coursier cache ?

@lihaoyi
Copy link
Member

lihaoyi commented May 23, 2018

Perhaps Mill could ask Ammonite what jars it has loaded into the classpath by the time the script is running, and use those? Ammonite already tracks all this stuff, and it should accurately reflect what code you are able to utilize in your build.sc and related scripts

@Baccata
Copy link
Contributor Author

Baccata commented May 23, 2018

Is there an easy way to access ammonite's interpreter from mill ? My initial idea was :

  • get class loader
  • cross fingers and cast as SpecialClassLoader
  • call allJars to get jar paths
  • build library name from jar paths

but if we can replace the get class loader bit by a safe reference, it'd be great

Also, a quick look at the sources tells me that ammonite resolves the sources as well as the jars by default. Can you confirm ?

@lihaoyi
Copy link
Member

lihaoyi commented May 24, 2018

For now just grab the SpecialClassloader however you can; once it's working we can put a nice API in place for Mill to use

Yeah ammonite resolves sources to make the source builtin utility work.

@lihaoyi lihaoyi closed this as completed Jun 2, 2018
@lefou lefou added this to the 0.2.3 milestone May 9, 2019
@lefou lefou added the solved The issue was fixed/resolved label Jul 3, 2019
@lilyevsky
Copy link

lilyevsky commented Sep 4, 2020

This is still not working. In my build.sc I have this dependency:

import $ivy.`com.github.pureconfig::pureconfig:0.13.0`

The actual Mill build works fine, compiles, produces artifact, etc. It finds and downloads the pureconfig dependency.
However, mill.scalalib.GenIdea/idea task does not include it in the IDEA libraries, so I have to add it manually to avoid all that red stuff in the editor.
Saving the IDEA files in git after manual addition would not help; from time to time I need to run mill.scalalib.GenIdea/idea, and it will break everything again.

My environment:
Windows or Linux (same problem on both). Latest Mill 0.8.0.
My workstation is behind corporate Nexus, in the predefScript.sc I override interp.repositories() to point to local maven repository and Nexus.

@lefou
Copy link
Member

lefou commented Oct 6, 2020

@lilyevsky Can you please open a new issue with a repro?

@lilyevsky
Copy link

lilyevsky commented Oct 7, 2020

@lefou I started working on the new issue, and I created some simple example, and it actually worked. So there was no problem there.

However, my other projects where I use my special predefScript.sc has this problem. The difference is, in that predefScript.sc I set it to take all libraries from our Nexus:

import java.io.FileInputStream
import java.util.Properties

import coursierapi.{Credentials, MavenRepository}

val gradleProps = new Properties()
val homeDir = System.getProperty("user.home")
gradleProps.load(new FileInputStream(s"${homeDir}/.gradle/gradle.properties"))
val nexusUsername = gradleProps.getProperty("nexusUsername")
val nexusPassword = gradleProps.getProperty("nexusPassword")
val nexusUrl = "http://gtsnexus.liquidnet.com/repository"
val nexusPublicUrl = s"${nexusUrl}/public"
val localUrl = s"file://${homeDir}/.m2/repository"
val nexusRepo = MavenRepository.of(nexusPublicUrl).withCredentials(Credentials.of(nexusUsername, nexusPassword))
val localRepo = MavenRepository.of(localUrl)
System.setProperty("localUrl", localUrl)
System.setProperty("nexusUrl", nexusUrl)
System.setProperty("nexusPublicUrl", nexusPublicUrl)
System.setProperty("nexusUsername", nexusUsername)
System.setProperty("nexusPassword", nexusPassword)

interp.repositories() = List(localRepo, nexusRepo)

I use this predefScript.sc in all my projects - I have to, because we are behind the firewall, and so the official build on buildserver would not work otherwise. In my own workspace I can get artifacts from internet directly, this is how I can test.

So I am not sure how to give you something that you can reproduce. You need to have Nexus, set up predefScript.sc similar to mine, and then in your build.sc put something like this:

import $ivy.`com.github.pureconfig::pureconfig:0.13.0`

Then you will see, when you do GenIdea thing and open the project in IntelliJ, that pureconfig library was not added to the list of external libraries.

If you think this is enough information to reproduce, let me know, then I can create a new issue.

Related question: do you know if anybody is planning to create a real mill Idea plugin? That would be really nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved The issue was fixed/resolved
Projects
None yet
Development

No branches or pull requests

4 participants