Re: [sbt] How to prevent generation of src/main/java and src/test/java when no Java files are in project?

429 views
Skip to first unread message

Heiko Seeberger

unread,
Mar 25, 2013, 7:12:08 AM3/25/13
to simple-b...@googlegroups.com
sbteclipse uses the sbt setting unmanagedSourceDirectories (by default in Compile and Test configuration) to determine which Eclipse source entries should be created.

By default unmanagedSourceDirectories contains Scala and Java sources:
> inspect unmanaged-source-directories
[info] Setting: scala.collection.Seq[java.io.File] = List(/Users/heiko/projects/sbteclipse/src/main/scala, /Users/heiko/projects/sbteclipse/src/main/java)
[info] Description:
[info]  Unmanaged source directories, which contain manually created sources.
[info] Provided by:
[info]  {file:/Users/heiko/projects/sbteclipse/}sbteclipse/compile:unmanaged-source-directories
[info] Dependencies:
[info]  sbteclipse/compile:scala-source
[info]  sbteclipse/compile:java-source

In order to avoid the Java source directories to be created, simply redefine unmanagedSourceDirectories by adding these two settings:
unmanagedSourceDirectories in Compile <<= (scalaSource in Compile)(Seq(_))
unmanagedSourceDirectories in Test <<= (scalaSource in Test)(Seq(_))

Cheers
Heiko

--

Heiko Seeberger
Twitter: @hseeberger
Company: Typesafe - The software stack for applications that scale
Author of "Durchstarten mit Scala, a tutorial-style Scala book"

On Mar 24, 2013, at 6:21 PM, Andrew D Bate <andre...@outlook.com> wrote:

Hello,

I also have multiple modules that each have their own eclipse projects generated.

I did try adding those two lines to my project/build.scala (now attached), but the src/main/java and src/test/java directories were still generated.

For some reason, I cannot upload my project/build.scala, so I have just copied the text below:

_______________________________________________

import sbt._
import Keys._

object ConsequenceReasonerMultiModuleBuild extends Build {

  lazy val buildSettings = Seq(
    name         := "Consequence Reasoner",
    version      := "0.1-SNAPSHOT",
    organization := "uk.ac.ox.cs.cr",
    scalaVersion := "2.10.1",
    scalacOptions += "-optimise",
    scalacOptions += "-target:jvm-1.7",
    libraryDependencies += "com.typesafe" % "config" % "1.0.0",
    libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test",
    // Dependency at compilation-time only (not at runtime)
    libraryDependencies += "com.nativelibs4java" %% "scalaxy-loops" % "0.3-SNAPSHOT" % "provided" excludeAll(ExclusionRule(organization = "org.scala-lang")),
    // Scalaxy/Loops snapshots are published on the Sonatype repository
    resolvers += Resolver.sonatypeRepo("snapshots"),
    compileOrder in Compile := CompileOrder.Mixed,
    compileOrder in Test := CompileOrder.JavaThenScala
  )

  override lazy val settings = super.settings ++ buildSettings

  // SBT chooses default project based on lexicographical ordering
  lazy val akernel       = Project(id = "cr-kernel",
                                   base = file("reasoner-kernel"))

  lazy val owlapi        = Project(id = "cr-owlapi",
                                   base = file("reasoner-owlapi")) dependsOn(akernel)

  lazy val protegeplugin = Project(id = "cr-protege-plugin",
                                   base = file("reasoner-protege-plugin")) dependsOn(akernel)

  lazy val fssparser     = Project(id = "cr-fss-parser",
                                   base = file("reasoner-fss-parser")) dependsOn(akernel)

  lazy val cli           = Project(id = "cr-cli",
                                   base = file("reasoner-cli")) dependsOn(fssparser)

  lazy val benchmark     = Project(id = "cr-benchmark",
                                   base = file("reasoner-benchmark")) dependsOn(akernel)

}

_______________________________________________

Any ideas?

Many thanks,

Andrew


On Friday, 22 March 2013 10:13:19 UTC, rinma lavi wrote:
Can't tell for sure (since you didn't post project/build.scala)  so here is a blind guess:

There is something like:

unmanagedSourceDirectories in Compile <<= (javaSource in Compile)(_ :: Nil) 
unmanagedSourceDirectories in Test    <<= (javaSource in Compile)(_ :: Nil) 

in there somewhere.

Br,

On Thursday, 21 March 2013 14:45:48 UTC+1, Andrew D Bate wrote:
Hello,

When I run "sbt eclipse" then both src/main/java and src/test/java are regenerated.

Since this is an existing project and there are no Java files (i.e. Scala only), then what can I add to project/build.scala to prevent these directories from being generated?

Any ideas?

Best wishes,

Andrew

--
You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
To post to this group, send email to simple-b...@googlegroups.com.
Visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Andrew D Bate

unread,
Mar 25, 2013, 8:01:46 AM3/25/13
to simple-b...@googlegroups.com
I have added those two lines to my project/build.scala, but the java directories are still generated.

Is this because I have multiple modules in my project?

When I type "inspect unmanaged-source-directories" (with those two lines added to my project/build.scala) I get the following output:

[info] Description:
[info]  Unmanaged source directories, which contain manually created sources.
[info] Provided by:
[info]  {file:/E:/GitHub/ConsequenceReasoner/}cr-kernel/compile:unmanaged-source-directories
[info] Dependencies:
[info]  cr-kernel/compile:scala-source
[info]  cr-kernel/compile:java-source
[info] Reverse dependencies:
[info]  cr-kernel/compile:source-directories
[info]  cr-kernel/compile:unmanaged-sources
[info] Delegates:
[info]  cr-kernel/compile:unmanaged-source-directories
[info]  cr-kernel/*:unmanaged-source-directories
[info]  {.}/compile:unmanaged-source-directories
[info]  {.}/*:unmanaged-source-directories
[info]  */compile:unmanaged-source-directories
[info]  */*:unmanaged-source-directories
[info] Related:
[info]  cr-owlapi/compile:unmanaged-source-directories
[info]  cr-fss-parser/test:unmanaged-source-directories
[info]  cr-fss-parser/compile:unmanaged-source-directories
[info]  cr-cli/test:unmanaged-source-directories
[info]  cr-benchmark/compile:unmanaged-source-directories
[info]  cr-protege-plugin/test:unmanaged-source-directories
[info]  cr-benchmark/test:unmanaged-source-directories
[info]  cr-owlapi/test:unmanaged-source-directories
[info]  cr-kernel/test:unmanaged-source-directories
[info]  cr-cli/compile:unmanaged-source-directories
[info]  cr-protege-plugin/compile:unmanaged-source-directories


Many thanks for your help,

Andrew

Heiko Seeberger

unread,
Mar 25, 2013, 10:03:14 AM3/25/13
to simple-b...@googlegroups.com
On Mar 25, 2013, at 1:01 PM, Andrew D Bate <andre...@outlook.com> wrote:

I have added those two lines to my project/build.scala, but the java directories are still generated.

Is this because I have multiple modules in my project?

Yeah, I think so. Instead of defining build settings, please assign the settings to each project. Here is an example:

Heiko

Andrew D Bate

unread,
Mar 25, 2013, 10:58:29 AM3/25/13
to simple-b...@googlegroups.com
In case this thread is useful to others in the future, my working script (i.e. an SBT script which does not generate src/main/java nor src/test/java in any of my sub-projects) is as follows:


import sbt._
import Keys._

object ConsequenceReasonerMultiModuleBuild extends Build {

  lazy val buildSettings = Defaults.defaultSettings ++ Seq(
    //name         := "Consequence Reasoner",
    //version      := "0.1-SNAPSHOT",
    organization := "uk.ac.ox.cs.cr",
    scalaVersion := "2.10.1",
    scalacOptions += "-optimise",
    scalacOptions += "-target:jvm-1.7",
    libraryDependencies += "com.typesafe" % "config" % "1.0.0",
    libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test",
    // Dependency at compilation-time only (not at runtime)
    libraryDependencies += "com.nativelibs4java" %% "scalaxy-loops" % "0.3-SNAPSHOT" % "provided" excludeAll(ExclusionRule(organization = "org.scala-lang")),
    // Scalaxy/Loops snapshots are published on the Sonatype repository
    resolvers += Resolver.sonatypeRepo("snapshots")
  )

  lazy val eclipseSettings = Seq(
    // Avoid the creation of Java source directories in Eclipse projects when using the sbteclipse plugin with the following two lines:
    unmanagedSourceDirectories in Compile <<= (scalaSource in Compile)(Seq(_)),
    unmanagedSourceDirectories in Test <<= (scalaSource in Test)(Seq(_))
  )

  // SBT chooses default project based on lexicographical ordering
  lazy val akernel              = Project(id = "cr-kernel",
                                          base = file("reasoner-kernel"),
                                          settings = buildSettings ++ Seq(name := "CR Kernel") ++ eclipseSettings) dependsOn(optimisedCollections)

  lazy val optimisedCollections = Project(id = "cr-optimised-collections",
                                          base = file("reasoner-optimised-collections"),
                                          settings = buildSettings ++ Seq(name := "CR Optimised Collections") ++ eclipseSettings)

  lazy val owlapi               = Project(id = "cr-owlapi",
                                          base = file("reasoner-owlapi"),
                                          settings = buildSettings ++ Seq(name := "CR OWLAPI Bindings") ++ eclipseSettings) dependsOn(akernel)

  lazy val protegeplugin        = Project(id = "cr-protege-plugin",
                                          base = file("reasoner-protege-plugin"),
                                          settings = buildSettings ++ Seq(name := "CR Protege Plugin") ++ eclipseSettings) dependsOn(akernel)

  lazy val fssparser            = Project(id = "cr-fss-parser",
                                          base = file("reasoner-fss-parser"),
                                          settings = buildSettings ++ Seq(name := "CR FSS Parser") ++ eclipseSettings) dependsOn(akernel)

  lazy val cli                  = Project(id = "cr-cli",
                                          base = file("reasoner-cli"),
                                          settings = buildSettings ++ Seq(name := "CR CLI") ++ eclipseSettings) dependsOn(fssparser)

  lazy val benchmark            = Project(id = "cr-benchmark",
                                          base = file("reasoner-benchmark"),
                                          settings = buildSettings ++ Seq(name := "CR Benchmark Suite") ++ eclipseSettings) dependsOn(akernel)
}


Thanks go to @Heiko Seeberger

Heiko Seeberger

unread,
Mar 25, 2013, 11:07:54 AM3/25/13
to simple-b...@googlegroups.com
Glad it works now!

Cheers
Heiko

--

Heiko Seeberger
Twitter: @hseeberger
Company: Typesafe - The software stack for applications that scale
Author of "Durchstarten mit Scala, a tutorial-style Scala book"

nafg

unread,
Apr 5, 2013, 2:17:47 AM4/5/13
to simple-b...@googlegroups.com
I do the following globally:

cat ~/.sbt/srcnonexist.sbt
unmanagedSourceDirectories in Compile ~= { _.filter(_.exists) }
Reply all
Reply to author
Forward
0 new messages