Skip to content

Instantly share code, notes, and snippets.

@gkossakowski
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkossakowski/eb1eb5ce5abc22b7e7b6 to your computer and use it in GitHub Desktop.
Save gkossakowski/eb1eb5ce5abc22b7e7b6 to your computer and use it in GitHub Desktop.
Patch needed to generate proper Eclipse files for sbt project itself
diff --git a/project/Sbt.scala b/project/Sbt.scala
index 4e660f4..8007c3b 100644
--- a/project/Sbt.scala
+++ b/project/Sbt.scala
@@ -8,6 +8,8 @@ import Common._
import Licensed._
import Scope.ThisScope
import LaunchProguard.{ proguard, Proguard }
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseCreateSrc
object Sbt extends Build {
override lazy val settings = super.settings ++ buildSettings ++ Status.settings ++ nightlySettings
@@ -23,7 +25,12 @@ object Sbt extends Build {
concurrentRestrictions in Global += Util.testExclusiveRestriction,
testOptions += Tests.Argument(TestFrameworks.ScalaCheck, "-w", "1"),
javacOptions in compile ++= Seq("-target", "6", "-source", "6", "-Xlint", "-Xlint:-serial"),
- incOptions := incOptions.value.withNameHashing(true)
+ incOptions := incOptions.value.withNameHashing(true),
+ // do not add test source files to generated `.classpath` file
+ // we have to exclude test files because Eclipse has only one classpath per project
+ // which makes it fail to resolve class definitions correctly because classes defined
+ // in tests overshadow classes defined in dependent projects
+ EclipseKeys.createSrc in Test := EclipseCreateSrc.ValueSet.empty
)
lazy val myProvided = config("provided") intransitive;
@@ -279,7 +286,8 @@ object Sbt extends Build {
watchSources <++= apiDefinitions,
resourceGenerators in Compile <+= (version, resourceManaged, streams, compile in Compile) map generateVersionFile,
apiDefinitions <<= baseDirectory map { base => (base / "definition") :: (base / "other") :: (base / "type") :: Nil },
- sourceGenerators in Compile <+= (cacheDirectory, apiDefinitions, fullClasspath in Compile in datatypeSub, sourceManaged in Compile, mainClass in datatypeSub in Compile, runner, streams) map generateAPICached
+ sourceGenerators in Compile <+= (cacheDirectory, apiDefinitions, fullClasspath in Compile in datatypeSub, sourceManaged in Compile, mainClass in datatypeSub in Compile, runner, streams) map generateAPICached,
+ EclipseKeys.createSrc in Compile := EclipseCreateSrc.Default + EclipseCreateSrc.Managed
)
def precompiledSettings = Seq(
diff --git a/project/Transform.scala b/project/Transform.scala
index b45d47d..91a0c54 100644
--- a/project/Transform.scala
+++ b/project/Transform.scala
@@ -1,5 +1,7 @@
import sbt._
import Keys._
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseCreateSrc
object Transform {
lazy val transformSources = TaskKey[Seq[File]]("transform-sources")
@@ -53,7 +55,8 @@ object Transform {
transformSources <<= (fileMappings in transformSources, sourceProperties) map { (rs, props) =>
rs map { case (in, out) => transform(in, out, props) }
},
- sourceGenerators <+= transformSources
+ sourceGenerators <+= transformSources,
+ EclipseKeys.createSrc in Compile := EclipseCreateSrc.Default + EclipseCreateSrc.Managed
)
def transformSourceMappings = (inputSources, inputSourceDirectories, sourceManaged) map { (ss, sdirs, sm) =>
(ss --- sdirs) x (rebase(sdirs, sm) | flat(sm)) toSeq
diff --git a/project/Util.scala b/project/Util.scala
index 4228c3e..8e79551 100644
--- a/project/Util.scala
+++ b/project/Util.scala
@@ -1,6 +1,8 @@
import sbt._
import Keys._
import StringUtilities.normalize
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys
+import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseCreateSrc
object Util {
val ExclusiveTest = Tags.Tag("exclusive-test")
@@ -159,7 +161,8 @@ object %s {
def keywordsSettings: Seq[Setting[_]] = inConfig(Compile)(Seq(
scalaKeywords := getScalaKeywords,
generateKeywords <<= (sourceManaged, scalaKeywords) map writeScalaKeywords,
- sourceGenerators <+= generateKeywords map (x => Seq(x))
+ sourceGenerators <+= generateKeywords map (x => Seq(x)),
+ EclipseKeys.createSrc in Compile := EclipseCreateSrc.Default + EclipseCreateSrc.Managed
))
}
object Common {
@rkrzewski
Copy link

Hmm, I can't apply this patch:

patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

It does look wonky, see import Common. following @@@ at line 5.

@gkossakowski
Copy link
Author

Fixed. I was using git show and I thought it produces a proper patch.

@rkrzewski
Copy link

It was easy enough to apply by hand :) Also, it would not apply cleanly to the tip of 0.13 branch as of today. I'll fork sbt repo and push the change shortly.

@rkrzewski
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment