You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Ander Juaristi <aj...@gmx.es> on 2015/04/10 12:42:53 UTC

How to package multi-project project into single JAR

Hi,

I have a Java project in Eclipse for whom I generated a buildfile automatically using Buildr itself.

The project is formed by sub-projects, and the layout is the following:

MyProject
|- main
    |- src
|- utils
    |- src
|- config
    |- src
|- logging
    |- src

When I run "buildr package" it correctly packages every subproject in the corresponding "target" directory, and it finally generates a file MyProject-1.0.0.jar in the root, but that JAR is empty: it only contains a manifest.

MyProject
|- main
    |- src
    |- target
       |- main-1.0.0.jar
|- utils
    |- src
    |- target
       |- utils-1.0.0.jar
|- config
    |- src
    |- target
       |- config-1.0.0.jar
|- logging
    |- src
    |- target
       |- logging-1.0.0.jar
|- MyProject-1.0.0.jar          <-- Only the manifest, no classes

What I'd like to know is how to merge all of the subprojects into the root JAR. As a last resort I could of course extend the "package" task and extract-repackage all the subprojects using Ruby language, but I feel this should be possible using Buildr's mechanisms.

My buildfile looks like this (relevant parts only):

require 'buildr/ide/eclipse'

define "MyProject" do

   # This wasn't in the beginning, I added it in the end
   # and it then generated the empty root package.
   package :jar

   define "utils" do
     package :jar
     compile.with dependencies
   end

   # All the other sub-projects look similar
end

-- 
Regards,
- AJ

Re: How to package multi-project project into single JAR

Posted by Alex Boisvert <al...@gmail.com>.
Use the merge() method on package.

e.g.,

define "example" do
  define "a" do
    package(:jar)
  end

  define "b" do
    package(:jar)
  end


  package(:jar).merge project(:a), project(:b)
end


On Fri, Apr 10, 2015 at 3:42 AM, Ander Juaristi <aj...@gmx.es> wrote:

> Hi,
>
> I have a Java project in Eclipse for whom I generated a buildfile
> automatically using Buildr itself.
>
> The project is formed by sub-projects, and the layout is the following:
>
> MyProject
> |- main
>    |- src
> |- utils
>    |- src
> |- config
>    |- src
> |- logging
>    |- src
>
> When I run "buildr package" it correctly packages every subproject in the
> corresponding "target" directory, and it finally generates a file
> MyProject-1.0.0.jar in the root, but that JAR is empty: it only contains a
> manifest.
>
> MyProject
> |- main
>    |- src
>    |- target
>       |- main-1.0.0.jar
> |- utils
>    |- src
>    |- target
>       |- utils-1.0.0.jar
> |- config
>    |- src
>    |- target
>       |- config-1.0.0.jar
> |- logging
>    |- src
>    |- target
>       |- logging-1.0.0.jar
> |- MyProject-1.0.0.jar          <-- Only the manifest, no classes
>
> What I'd like to know is how to merge all of the subprojects into the root
> JAR. As a last resort I could of course extend the "package" task and
> extract-repackage all the subprojects using Ruby language, but I feel this
> should be possible using Buildr's mechanisms.
>
> My buildfile looks like this (relevant parts only):
>
> require 'buildr/ide/eclipse'
>
> define "MyProject" do
>
>   # This wasn't in the beginning, I added it in the end
>   # and it then generated the empty root package.
>   package :jar
>
>   define "utils" do
>     package :jar
>     compile.with dependencies
>   end
>
>   # All the other sub-projects look similar
> end
>
> --
> Regards,
> - AJ
>