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

Use relative path for local libraries #34

Closed
channingwalton opened this issue Sep 18, 2011 · 6 comments
Closed

Use relative path for local libraries #34

channingwalton opened this issue Sep 18, 2011 · 6 comments
Labels
Milestone

Comments

@channingwalton
Copy link

When the sbt option retrieveManaged is 'true', then it would be nice for the classpaths set in .classpath to be relative to the project root. This allows the .classpath to be shared by more than one user when devs check out code.

@ashewring
Copy link

I suggest that the plugin should generate "var" entries instead of "lib" entries with hard-coded paths. An example of such a "lib" entry is:

<classpathentry kind="lib" path="/home/myuser/.ivy2/cache/org.scala-tools.sbt/sbt_2.9.1/jars/sbt_2.9.1-0.11.0.jar"/>

It would be ideal if the user's home directory was assigned to a USER_HOME Classpath Variable. Then the .classpath can look like the following, allowing the .ivy2 and .sbt directories to be resolved:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/scala"/>
<classpathentry kind="var" path="USER_HOME/.ivy2/cache/org.scala-tools.sbt/sbt_2.9.1/jars/sbt_2.9.1-0.11.0.jar"/>
<classpathentry kind="var" path="USER_HOME/.ivy2/cache/org.scala-tools.sbt/main_2.9.1/jars/main_2.9.1-0.11.0.jar"/>
<!-- Snip -->
<classpathentry kind="var" path="USER_HOME/.sbt/boot/scala-2.9.1/lib/scala-compiler.jar"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path=".target/scala-2.9.1/sbt-0.11.0/classes"/>
</classpath>

This should work correctly under Linux and Windows (in the latter case, USER_HOME would be set to something like C:/Documents and Settings/myuser)

@channingwalton
Copy link
Author

One reason we want to use lib_managed is that we can check it in to version control. That may be crazy talk but in corporate environments its often the simplest thing to do to enable devs to check out code and start working easily. We don't always have easy/direct access to the internet.

@hseeberger
Copy link
Member

Will be part of sbteclipse 2.0.0.

@channingwalton
Copy link
Author

excellent thanks

@norru
Copy link

norru commented Aug 1, 2016

Is this still not fixed in 4.0.0?

EclipseKeys.relativizeLibs := true

generates

<classpathentry sourcepath="/home/norru/.ivy2/cache/org.slf4j/slf4j-api/srcs/slf4j-api-1.7.7-sources.jar" kind="lib" path="/home/norru/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.7.7.jar"/>

I would expect a mechanism to replace /home/norru with USER_HOME as suggested by a comment above.

In fact, I have a crude workaround already, in Build.scala but I hate that I have to copy it in every single project...

EclipseKeys.classpathTransformerFactories := Seq(ClasspathentryTransformer)

import sbt._
import Keys._
import scalaz.Scalaz._
import com.typesafe.sbteclipse.core._
import com.typesafe.sbteclipse.core.EclipsePlugin._
import scala.xml.transform._

object ClasspathentryRewriteRule extends RewriteRule {
    import scala.xml._
    override def transform(parent: Node): Seq[Node] = {
        val ivyHome = System.getProperty("user.home") + "/.ivy2"
        parent match {
            case c @ <classpathentry/> if (
                    ((c \ "@kind").toString() == "lib") 
                    && ((c \ "@path").toString() startsWith ivyHome) 
                    && ((c \ "@sourcepath").toString() startsWith ivyHome)) => {
                <classpathentry kind="var" path={ (c \ "@path").toString.replaceAll(ivyHome, "IVY_HOME") } 
                    sourcepath={ (c \ "@sourcepath").toString.replaceAll(ivyHome, "IVY_HOME") }  />
            }

            case c @ <classpathentry/> if (
                    ((c \ "@kind").toString() == "lib") 
                    && ((c \ "@path").toString() startsWith ivyHome)) => {
                <classpathentry kind="var" path={ (c \ "@path").toString.replaceAll(ivyHome, "IVY_HOME") }  />
            }
            case other => other
        }
    }
}

object ClasspathentryTransformer extends EclipseTransformerFactory[RewriteRule] {
    override def createTransformer(ref: ProjectRef, state: State): Validation[RewriteRule] = {
        ClasspathentryRewriteRule.success
    }
}

Thanks
Nico

@wasowski
Copy link

wasowski commented Sep 26, 2016

This seems to work with both keys set:
retrieveManaged := true
and
EclipseKeys.relativizeLibs := true,

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

No branches or pull requests

5 participants