-
Notifications
You must be signed in to change notification settings - Fork 949
Fix bug of unmanagedResourceDirectories #7178
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Thanks for the report and sending a PR. Are you saying that sbt currently does not support adding overlapping unmanagedResourceDirectories like |
@eed3si9n Thanks for the comment. |
I think so. In general having static typing in the build definition allows sbt, builds, and plugin ecosystem to evolve at different pace. I am particularly concerned about making implementation-level changes that would make semantic difference in exactly the opposite of what the type promises in an observable way. It might work for some time, but it could break again later. I would recommend creating a different directory with your conf files. |
If I move the unmanaged resources directories out of For example, the codes below might cause same problem. Compile / unmanagedResourceDirectories += baseDirectory.value / "src/main/unmanaged_resources"
Compile / unmanagedResourceDirectories += baseDirectory.value / "src/main/unmanaged_resources/hadoop_conf" However, I also agree with you that having static typing at build time can cause problems. After some thought I've thought that the underlying problem is not that the def rebase(oldBases: Iterable[File], newBase: File, zero: FileMap = transparent): FileMap =
fold(zero, oldBases.toList.sorted)(old => rebase(old, newBase)) |
@eed3si9n Hi, there! def copyResourcesTask =
Def.task {
val t = classDirectory.value
val dirs = resourceDirectories.value.toSet
val sortedDirs = resourceDirectories.value.sorted
val s = streams.value
val syncDir = crossTarget.value / (prefix(configuration.value.name) + "sync")
val factory = CacheStoreFactory(syncDir)
val cacheStore = factory.make("copy-resource")
val converter = fileConverter.value
val flt: File => Option[File] = flat(t)
val transform: File => Option[File] = (f: File) => rebase(sortedDirs, t)(f).orElse(flt(f))
val mappings: Seq[(File, File)] = resources.value.flatMap {
case r if !dirs(r) => transform(r).map(r -> _)
case _ => None
}
s.log.debug("Copy resource mappings: " + mappings.mkString("\n\t", "\n\t", ""))
Sync.sync(cacheStore, fileConverter = converter)(mappings)
mappings
} I just added a variable, |
@minkyu97 Sorry about the delayed response. I'd be fine with going forward with the idea. |
@eed3si9n I'm really sorry too.. I missed your comment for a long time because of my work. |
ead92f9
to
d02bc01
Compare
I found that sometimes files in directories added to
unmanagedResourceDirectories
are ignored.This was because the
resourcesDirectories
are managed as aSet
like belowBut, you know, the default
Set
inscala
is implemented as aHashSet
, which does not guarantee ordering of elements.For example, When I added my config directory
src/main/resources/conf
tounmanagedResourceDirectories
in order to include a file calledsrc/main/resources/conf/my-conf.json
as a resource, but my config file was compiled astarget/scala/classes/conf/my-conf.json
, nottarget/scala/classes/my-conf.json
.When I printed out the variable
dirs
mentioned above, I got the following result. (For convenience, represent the project path as~
)When I improved it using
SortedSet
and printed out the variabledirs
, It looks fine!