sbt / sbt-eclipse

Plugin for sbt to create Eclipse project definitions
Apache License 2.0
718 stars 167 forks source link

include root directory in .classpath (in sbt build) #186

Open mighdoll opened 10 years ago

mighdoll commented 10 years ago

When following standard conventions, users put .scala files in the root of the project directory in sbt. However, sbt-eclipse doesn't add a .classpath entry for these .scala files in the root directory.

see stack overflow for an example where the .classpath generated for the sbt build is missing the the root directory, and for a manually generated solution.

It's probably possible to detect this situation automatically by noticing .scala files in the root directory. But even without an automatic detection, an option like sourcesInRootDirectory=true would be nice.

hseeberger commented 10 years ago

I think putting .scala files into the project root directory is bad style. Could you please explain why you consider this "standard conventions"?

Anyway, Eclipse doesn't like nested source directories. There are ways to work around it (exclusion rules), but this feature would definitely add some complexity.

mighdoll commented 10 years ago

I mean in the directory called 'project' if that was unclear.

http://www.scala-sbt.org/release/docs/Getting-Started/Directories.htmlshows build.scala at the root of the 'project' directory - I think this has been the convention for some years now.

In the stack overflow example, I showed an inclusion rule - probably simpler than exclusion in this case..

On Thursday, November 21, 2013, Heiko Seeberger wrote:

I think putting .scala files into the project root directory is bad style. Could you please explain why you consider this "standard conventions"?

Anyway, Eclipse doesn't like nested source directories. There are ways to work around it (exclusion rules), but this feature would definitely add some complexity.

— Reply to this email directly or view it on GitHubhttps://github.com/typesafehub/sbteclipse/issues/186#issuecomment-28965940 .

hseeberger commented 10 years ago

Thanks for the clarification.

Scala files under project/ are part of the sbt build definition. Therefore they (might) depend on sbt libraries, hence a general solution requires more than just adding a src entry. See issue #26.

jsuereth commented 10 years ago

@hseeberger If you do "reload plugins" "eclipse", then you everything seems to work.

What you actually need to be able to add the root directory is the appropriate mechanisms of "excluded" directories. If that issue was fixed, I'd say we should be able to enable this, so we can eclipsify our build.scala files.

mighdoll commented 10 years ago

@jsuereth - not quite everything works. I see in #26, someone noticed the same issue and also proposed adding:

        <classpathentry including="*.scala" kind="src" path=""/>

Perhaps the plugin could check whether there are .scala files in root path by examining the 'sources' key and if so, then add the above entry to the classpath. I think that would solve the common case at least.

@hseeberger this issue is is just about adding the above classpath entry when you do "reload plugins" "eclipse". (I suppose it would also fix this stack overflow request too.)

26 would trigger all this without requiring "reload plugins" which would be nice (but #26 is separate, and would benefit from this logic).

godenji commented 10 years ago

@jsuereth blows up here in a Play sub project enabled build

reload plugins // fine eclipse // boom

[debug] Project dependencies for configuration 'compile': Success(List())
[debug] Project dependencies for configuration 'test': Success(List())
java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:313)
at scala.None$.get(Option.scala:311)
at com.typesafe.sbteclipse.core.Eclipse$.relativize(Eclipse.scala:576)

Have periodically tried since forever to get project/*.scala files recognized by Eclipse -- the inner workings of SBT would be far more accessible with live type inference vs. blindly groping in the dark ;-)

hrj commented 10 years ago

Could this plugin generate a separate Eclipse project for the .scala files relevant to the sbt project? That way there won't be a namespace collision across different concerns.

jsuereth commented 10 years ago

@hrj I think I just found the piece that would allow us to do it. THere'sa pluginData key that has the right classpath.

teldosas commented 7 years ago

Any progress on this? I too have a project that has sources in the root folder but nested. That is com/company/lib. So the contents of this folder should have package com.compay.lib

The plugin currently adds

<classpathentry output="C:-Users-User-Projects-Project1" kind="src" path="C:-Users-User-Projects-Project1"/>

that's the path to my project dash separated and it doesn't work

I fix it manually from eclipse ui by adding the project root as a source folder and an inclusion rule and I get the following classpathentry

<classpathentry including="com/**" kind="src" path=""/>

which works

Can this be done automatically? I would gladly create a PR if someone points me to the right direction. :)