Reputation: 12670
If I want to package a subproject's jar inside the main jar, I can do this sort of thing:
define 'library' do
project.version = '0.1'
define 'subproject' do
package :jar
end
package(:jar).include(project('subproject').package(:jar),
as: 'org/acme/library/subproject.jar')
end
This will lazily build the jar in the subproject, right before it is needed for packaging into the main jar, and everything works.
Problem is, my tests want to use the jar file as well, so the logical place for it is in the resources. So I wonder how I'm supposed to copy something build by another project into the resources for this project. The docs are notably lacking any examples of this and mostly focus on how to copy one directory of files to another.
This is what I tried:
resources.from(project('subproject').package(:jar),
as: 'org/acme/library/subproject.jar')
It fails:
RuntimeError : Source directory $HOME/Documents/library/subproject/target/library-subproject-0.1.jar doesn't exist
$HOME/Documents/library/buildfile:38:in `block in <top (required)>'
To my surprise, this seems to be the one place in buildr which eagerly evaluates the existence of a build product instead of setting it up as a lazy dependency...
I can work around this as follows:
# Crappy workaround to eagerly create target dir in subproject.
mkdir_p project("lucene#{ver}").path_to(:target)
resources.from(project("lucene#{ver}").path_to(:target)).
include(project("lucene#{ver}").package(:jar))
I don't like this because it still eagerly evaluates the directory, which forces me to create that directory long before any of the build is being run. Meaning that even when I run buildr clean
, it's creating this directory. Yuck.
So what's the proper way to do this?
Upvotes: 1
Views: 30
Reputation: 461
The way we typically do this is to not create any packages with the top level project and instead use a subproject to define the two packages. i.e
define 'myproject'
...
define 'model' do
...
package(:jar)
end
define 'server' do
...
package(:war) do |war|
war.libs.clear
war.libs << project('model').package(:jar)
end
end
end
This allows much easier management of dependencies and ordering of builds. Hope that helps!
Upvotes: 1