How to exclude .scala source file in project folder?

4,101 views
Skip to first unread message

Hendy Irawan

unread,
Oct 11, 2011, 11:51:16 PM10/11/11
to simple-build-tool
Hi,

I'm using sbt 0.11.0.
I'd like to exclude a .scala file because when I run "sbt console" it
complains:

> compile
[info] Compiling 1 Scala source to /home/ceefour/git/bippoadmin/butler/
target/scala-2.9.1/classes...
[error] /home/ceefour/git/bippoadmin/butler/butler.scala:1: expected
class or object definition
[error] val butler = id.co.bippo.devops.Butler.load
[error] ^
[error] /home/ceefour/git/bippoadmin/butler/butler.scala:2: expected
class or object definition
[error] id.co.bippo.devops.Butler.main(Array[String]())
[error] ^
[error] two errors found
[error] {file:/home/ceefour/git/bippoadmin/butler/}default-9b1882/
compile:compile: Compilation failed
[error] Total time: 0 s, completed 12 Okt 11 10:50:04

The strange thing is butler.scala is not even in the source
directories (which are src/main/scala), but still compiled by sbt? Is
this a bug?

How to do this? Thank you.

Regards,
Hendy

Mark Harrah

unread,
Oct 12, 2011, 7:49:59 PM10/12/11
to simple-b...@googlegroups.com
Hi Hendy,

The project base directory is by default a source directory in addition to src/main/scala. You can exclude source files by name like:

excludeFilter in unmanagedSources := "butler.scala"

-Mark

>
> Regards,
> Hendy
>

Hendy Irawan

unread,
Oct 12, 2011, 9:33:47 PM10/12/11
to simple-b...@googlegroups.com

Thank you Mark!

Much thanks!

Hendy




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


Hendy Irawan

unread,
Oct 12, 2011, 9:41:13 PM10/12/11
to simple-build-tool

paulbutcher

unread,
Oct 23, 2011, 6:57:53 PM10/23/11
to simple-build-tool
On Oct 13, 12:49 am, Mark Harrah <dmhar...@gmail.com> wrote:
> The project base directory is by default a source directory in addition to src/main/scala.  You can exclude source files by name like:
>
> excludeFilter in unmanagedSources := "butler.scala"

I've just stumbled across this, and am slightly confused.
excludeFilter is normally defined (if I'm reading Defaults.scala
correctly) as:

> excludeFilter :== (".*" - ".") || HiddenFileFilter

Does setting it to be "butler.scala" not result in hidden files no
longer being excluded? And what (if any) are the bad effects of this?

Not a big thing, but I just want to make sure that I'm understanding
things correctly :-)

Thanks!

--
paul.butcher->msgCount++

Snetterton, Castle Combe, Cadwell Park...
Who says I have a one track mind?

http://www.paulbutcher.com/
LinkedIn: http://www.linkedin.com/in/paulbutcher
MSN: pa...@paulbutcher.com
AIM: paulrabutcher
Skype: paulrabutcher

Jan Berkel

unread,
Oct 24, 2011, 9:44:21 AM10/24/11
to simple-b...@googlegroups.com

> excludeFilter :== (".*"  - ".") || HiddenFileFilter

Does setting it to be "butler.scala" not result in hidden files no
longer being excluded? And what (if any) are the bad effects of this?

Not a big thing, but I just want to make sure that I'm understanding
things correctly :-)


a related question to filtering - i want to filter out test resources (the resources are located in the source directory), however the following does not work:

Seq(...
  resourceDirectory in Test <<= (javaSource in Test) (js => js),
  excludeFilter in resources in Test := "*.java"
)

   jan

Havoc Pennington

unread,
Oct 24, 2011, 10:04:39 AM10/24/11
to simple-b...@googlegroups.com
Hi,

On Sun, Oct 23, 2011 at 6:57 PM, paulbutcher
<paulra...@googlemail.com> wrote:
>
>> excludeFilter :== (".*"  - ".") || HiddenFileFilter
>
> Does setting it to be "butler.scala" not result in hidden files no
> longer being excluded? And what (if any) are the bad effects of this?
>
> Not a big thing, but I just want to make sure that I'm understanding
> things correctly :-)

Keep in mind scopes: https://github.com/harrah/xsbt/wiki/Getting-Started-Scopes

It's a little hard to unpack this from the sbt command line because
the filters' values just show up as "sbt.SimpleFileFilter@8bfdea" when
you "inspect exclude-filter"

But if you look where the excludeFilter :== definition you mention is
defined in Defaults.scala, it's "inScope(GlobalScope)" so that is
defining */*:exclude-filter

Mark's suggestion is to define

excludeFilter in unmanagedSources := "butler.scala"

which is specifically for the unmanagedSources task only rather than global.

That already has a whitelist:

includeFilter in unmanagedSources :== "*.java" | "*.scala"

I think you may be right that hidden files would no longer be
excluded, but unless your hidden files end in .scala or .java then
perhaps it won't really matter since they won't be in the
includeFilter.

If you messed with excludeFilter globally rather than in
unmanaged-sources, there could maybe be more side effects, I don't
know.

Havoc

Mark Harrah

unread,
Oct 26, 2011, 10:52:06 PM10/26/11
to simple-b...@googlegroups.com
On Mon, 24 Oct 2011 10:04:39 -0400
Havoc Pennington <h...@pobox.com> wrote:

> Hi,
>
> On Sun, Oct 23, 2011 at 6:57 PM, paulbutcher
> <paulra...@googlemail.com> wrote:
> >
> >> excludeFilter :== (".*"  - ".") || HiddenFileFilter
> >
> > Does setting it to be "butler.scala" not result in hidden files no
> > longer being excluded? And what (if any) are the bad effects of this?

Yes, you're right, perhaps I simplified the answer too much.

> > Not a big thing, but I just want to make sure that I'm understanding
> > things correctly :-)
>
> Keep in mind scopes: https://github.com/harrah/xsbt/wiki/Getting-Started-Scopes
>
> It's a little hard to unpack this from the sbt command line because
> the filters' values just show up as "sbt.SimpleFileFilter@8bfdea" when
> you "inspect exclude-filter"
>
> But if you look where the excludeFilter :== definition you mention is
> defined in Defaults.scala, it's "inScope(GlobalScope)" so that is
> defining */*:exclude-filter
>
> Mark's suggestion is to define
>
> excludeFilter in unmanagedSources := "butler.scala"
>
> which is specifically for the unmanagedSources task only rather than global.
>
> That already has a whitelist:
>
> includeFilter in unmanagedSources :== "*.java" | "*.scala"
>
> I think you may be right that hidden files would no longer be
> excluded, but unless your hidden files end in .scala or .java then
> perhaps it won't really matter since they won't be in the
> includeFilter.

The main reason you'd probably want to keep the hidden file exclusion is to exclude source files in .svn directories, for example. You can augment the current filter instead of completely replacing it with something like:

excludeFilter in unmanagedSources ~= { _ || "butler.scala" }

which is equivalent to:

excludeFilter in unmanagedSources <<=
(excludeFilter in unmanagedSources) { (currentFilter: FileFilter) =>
currentFilter || "butler.scala"
}

-Mark

Mark Harrah

unread,
Oct 26, 2011, 10:52:19 PM10/26/11
to simple-b...@googlegroups.com
Hi Jan,

That should be unmanagedResources instead of resources (for sources, it is unmanagedSources). The reason is that sbt only automatically traverses unmanaged resource directories looking for resources. 'resources' contains both 'unmanagedResources' and 'managedResources' and no filtering is done on 'resources'.

-Mark

> jan
>

Reply all
Reply to author
Forward
0 new messages